Skip to content

Commit

Permalink
Merge pull request #87 from Chizaruu/80-add-launchjson-config-generat…
Browse files Browse the repository at this point in the history
…ion-and-customization

80 add launchjson config generation and customization
  • Loading branch information
Chizaruu authored Feb 21, 2024
2 parents 542eae9 + d1403f8 commit 0675a18
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Projects/2021.3 LTS/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.14f1
m_EditorVersionWithRevision: 2021.3.14f1 (eee1884e7226)
m_EditorVersion: 2021.3.35f1
m_EditorVersionWithRevision: 2021.3.35f1 (157b46ce122a)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In addition to its core features, this package includes seamless integration wit

### Streamlined Configuration Setup and Customization

The com.tsk.ide.vscode package presents a proficient solution designed for streamlined integration of Visual Studio Code with Unity. This package significantly simplifies the setup process by generating essential configuration files, namely `.editorconfig`. This conserves valuable time and boosts your efficiency by minimizing the potential for setup errors.
The com.tsk.ide.vscode package presents a proficient solution designed for streamlined integration of Visual Studio Code with Unity. This package significantly simplifies the setup process by generating essential configuration files, namely `settings.json`, `.editorconfig`, `.code-workspace`, and `launch.json`. This conserves valuable time and boosts your efficiency by minimizing the potential for setup errors.

To utilize this feature, navigate to `Preferences > External Tools > Generate config files for:` and select the appropriate options to create the configuration files. After this, merely click on the `Regenerate` button.

Expand Down
4 changes: 4 additions & 0 deletions com.tsk.ide.vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Code Editor Package for Visual Studio Code

## [1.4.8] - 2024-02-22

- Added Launch.json section to Externals Tools

## [1.4.7] - 2023-08-06

- Remove omnisharp config generation from package
Expand Down
45 changes: 45 additions & 0 deletions com.tsk.ide.vscode/Editor/ConfigGeneration/ConfigGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IConfigGenerator
string VSCodeSettings { get; set; }
string WorkspaceSettings { get; set; }
string EditorConfigSettings { get; set; }
string LaunchConfigSettings { get; set; }
string ProjectDirectory { get; }
IFlagHandler FlagHandler { get; }
void Sync();
Expand Down Expand Up @@ -100,13 +101,24 @@ public class ConfigGeneration : IConfigGenerator
dotnet_diagnostic.IDE0051.severity = none
";

const string k_DefaultLaunchConfig = @"{
""version"": ""0.2.0"",
""configurations"": [
{
""name"": ""Attach to Unity"",
""type"": ""vstuc"",
""request"": ""attach""
}
]
}";
public string ProjectDirectory { get; }
readonly string m_ProjectName;
IFlagHandler IConfigGenerator.FlagHandler => m_FlagHandler;

string m_VSCodeSettings;
string m_WorkspaceSettings;
string m_EditorConfigSettings;
string m_LaunchConfigSettings;

public string VSCodeSettings
{
Expand Down Expand Up @@ -159,6 +171,23 @@ public string EditorConfigSettings
}
}

public string LaunchConfigSettings
{
get =>
m_LaunchConfigSettings ??= EditorPrefs.GetString(
"vscode_launchConfigSettings",
k_DefaultLaunchConfig
);
set
{
if (value == "")
value = k_DefaultLaunchConfig;

m_LaunchConfigSettings = value;
EditorPrefs.SetString("vscode_launchConfigSettings", value);
}
}

readonly IFlagHandler m_FlagHandler;
readonly IFileIO m_FileIOProvider;

Expand All @@ -182,6 +211,7 @@ public void Sync()
WriteVSCodeSettingsFiles();
WriteWorkspaceFile();
WriteEditorConfigFile();
WriteLaunchConfigFile();
}

void WriteVSCodeSettingsFiles()
Expand Down Expand Up @@ -221,5 +251,20 @@ void WriteEditorConfigFile()
m_FileIOProvider.WriteAllText(editorConfig, EditorConfigSettings);
}
}

void WriteLaunchConfigFile()
{
if (m_FlagHandler.ConfigFlag.HasFlag(ConfigFlag.LaunchConfig))
{
var vsCodeDirectory = Path.Combine(ProjectDirectory, ".vscode");

if (!m_FileIOProvider.Exists(vsCodeDirectory))
m_FileIOProvider.CreateDirectory(vsCodeDirectory);

var launchConfigJson = Path.Combine(vsCodeDirectory, "launch.json");

m_FileIOProvider.WriteAllText(launchConfigJson, LaunchConfigSettings);
}
}
}
}
1 change: 1 addition & 0 deletions com.tsk.ide.vscode/Editor/Utils/FlagHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ConfigFlag
VSCode = 1,
Workspace = 2,
EditorConfig = 4,
LaunchConfig = 8,
}

[Flags]
Expand Down
39 changes: 38 additions & 1 deletion com.tsk.ide.vscode/Editor/VSCodeScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public class VSCodeScriptEditor : IExternalCodeEditor
bool m_ShowVSCodeSettingsSection = false;
bool m_ShowWorkspaceSection = false;
bool m_ShowEditorConfigSection = false;
bool m_ShowLaunchConfigSection = false;

Vector2 m_VSCodeScrollPosition;
Vector2 m_WorkspaceScrollPosition;
Vector2 m_EditorConfigScrollPosition;
Vector2 m_LaunchConfigScrollPosition;

readonly IDiscovery m_Discoverability;
readonly IGenerator m_ProjectGeneration;
Expand Down Expand Up @@ -111,6 +113,18 @@ bool ShowProjectSection
}
}

bool ShowLaunchConfigSection
{
get =>
m_ShowLaunchConfigSection
|| EditorPrefs.GetBool("vscode_showLaunchConfigSection", false);
set
{
m_ShowLaunchConfigSection = value;
EditorPrefs.SetBool("vscode_showLaunchConfigSection", value);
}
}

static string[] DefaultExtensions
{
get
Expand Down Expand Up @@ -188,6 +202,7 @@ public void OnGUI()
RenderExtensionsSection();
RenderConfigSection();
RenderProjectSection();

}

void RenderEditorSection()
Expand Down Expand Up @@ -290,7 +305,7 @@ ref m_WorkspaceScrollPosition

FlagButton(
ConfigFlag.EditorConfig,
"EditorConfig",
"Editor Config",
"",
(handler, flag) => handler.ConfigFlag.HasFlag(flag),
(handler, flag) => handler.ToggleConfig(flag)
Expand All @@ -304,6 +319,22 @@ ref m_WorkspaceScrollPosition
ref m_EditorConfigScrollPosition
);

FlagButton(
ConfigFlag.LaunchConfig,
"Launch Config",
"",
(handler, flag) => handler.ConfigFlag.HasFlag(flag),
(handler, flag) => handler.ToggleConfig(flag)
);

if (m_ConfigGeneration.FlagHandler.ConfigFlag.HasFlag(ConfigFlag.LaunchConfig))
RenderSettingsSection(
ref m_ShowLaunchConfigSection,
m_ConfigGeneration.LaunchConfigSettings,
"Launch",
ref m_LaunchConfigScrollPosition
);

RegenerateButton("Regenerate", "Regenerate config files");
EditorGUI.indentLevel--;
}
Expand Down Expand Up @@ -346,6 +377,9 @@ ref Vector2 scrollPosition
case "editorconfig":
m_ConfigGeneration.EditorConfigSettings = settings;
break;
case "Launch":
m_ConfigGeneration.LaunchConfigSettings = settings;
break;
}
}

Expand Down Expand Up @@ -491,6 +525,9 @@ void RegenerateButton(string guiMessage, string command = "")
case "Reset editorconfig settings":
m_ConfigGeneration.EditorConfigSettings = "";
break;
case "Reset Launch settings":
m_ConfigGeneration.LaunchConfigSettings = "";
break;
default:
UnityEngine.Debug.LogError("Unknown button pressed");
break;
Expand Down
2 changes: 1 addition & 1 deletion com.tsk.ide.vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.tsk.ide.vscode",
"displayName": "TSK VSCode Editor",
"description": "Unofficial code editor integration for supporting Visual Studio Code as code editor for Unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "1.4.7",
"version": "1.4.8",
"unity": "2021.3",
"dependencies": {},
"author": {
Expand Down

0 comments on commit 0675a18

Please sign in to comment.