From 7c668200ba782a16d532381c464fcb24ffdcb06e Mon Sep 17 00:00:00 2001 From: Abdul-Kadir Coskun Date: Sat, 1 Apr 2023 20:02:19 +1100 Subject: [PATCH] ProjectGeneration handles .omnisharp, .editiorconfig, and analyzers No booleans. --- CHANGELOG.md | 12 +- Editor/ProjectGeneration/FileIO.cs | 7 + Editor/ProjectGeneration/ProjectGeneration.cs | 512 +++++------------- Editor/VSCodeScriptEditor.cs | 195 +------ package.json | 4 +- 5 files changed, 141 insertions(+), 589 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1931ff..d380ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Code Editor Package for Visual Studio Code -<<<<<<< HEAD +## [1.3.1] - 2023-04-01 + +- Moved .omnisharp, .editorconfig, and analyzer generation to ProjectGeneration.cs to be in line with the rest of the project +- Simplified XElement creation in ProjectGeneration.cs to be more readable + ## [1.3.0] - 2023-04-01 - Added complete SDK support, this allows you to use Omnisharp's useModernNet in your project (Special thanks to Andrew Spiering @wackoisgod) @@ -9,8 +13,6 @@ - Added support for .Net 4.8 API compatibility level for 2022.1 and above - Fixed failure while loading the analyzer reference 'Unity.SourceGenerators' -======= ->>>>>>> 8298f45 (Better Support & Formatting) ## [1.2.7] - 2023-03-19 - Added Unity Roslyn analyzers support (See ) @@ -98,6 +100,6 @@ Add %LOCALAPPDATA%/Programs to the path of install paths. ## [1.0.3] - 2019-01-01 -### This is the first release of *Unity Package vscode_editor* +### This is the first release of _Unity Package vscode_editor_ -Using the newly created api to integrate Visual Studio Code with Unity. +Using the newly created api to integrate Visual Studio Code with Unity. \ No newline at end of file diff --git a/Editor/ProjectGeneration/FileIO.cs b/Editor/ProjectGeneration/FileIO.cs index 2c2c95a..fd6120d 100644 --- a/Editor/ProjectGeneration/FileIO.cs +++ b/Editor/ProjectGeneration/FileIO.cs @@ -12,6 +12,8 @@ public interface IFileIO string ReadAllText(string fileName); void WriteAllText(string fileName, string content); + void Copy(string sourceFileName, string destFileName, bool overwrite); + void CreateDirectory(string pathName); string EscapedRelativePathFor(string file, string projectDirectory); } @@ -33,6 +35,11 @@ public void WriteAllText(string fileName, string content) File.WriteAllText(fileName, content, Encoding.UTF8); } + public void Copy(string sourceFileName, string destFileName, bool overwrite) + { + File.Copy(sourceFileName, destFileName, overwrite); + } + public void CreateDirectory(string pathName) { Directory.CreateDirectory(pathName); diff --git a/Editor/ProjectGeneration/ProjectGeneration.cs b/Editor/ProjectGeneration/ProjectGeneration.cs index bc01877..14b132c 100644 --- a/Editor/ProjectGeneration/ProjectGeneration.cs +++ b/Editor/ProjectGeneration/ProjectGeneration.cs @@ -33,16 +33,11 @@ enum ScriptingLanguage CSharp } -<<<<<<< HEAD -======= - public static readonly string MSBuildNamespaceUri = - "http://schemas.microsoft.com/developer/msbuild/2003"; - ->>>>>>> 8298f45 (Better Support & Formatting) const string k_WindowsNewline = "\r\n"; const string k_SettingsJson = - @"{ + /*lang=json,strict*/ + @"{ ""files.exclude"": { ""**/.DS_Store"":true, @@ -107,6 +102,34 @@ enum ScriptingLanguage ] }"; + const string k_OmniSharpJson = + @"{ + ""RoslynExtensionsOptions"": { + ""enableRoslynAnalyzers"": true, + ""enableEditorConfigSupport"": true, + ""sdkIncludePrereleases"": false, + ""organizeImportsOnFormat"": true, + ""threadsToUseForAnalyzers"": true, + ""useModernNet"": true, + ""documentAnalysisTimeoutMs"": 600000, + ""LocationPaths"": [""./NuGet""] + } +}"; + + const string k_EditorConfig = + @"# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# 4 space indentation +[*.cs] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +"; + + /// /// Map source extensions to ScriptingLanguages /// @@ -171,7 +194,6 @@ public void GenerateAll(bool generateAll) const string k_ToolsVersion = "4.0"; const string k_ProductVersion = "10.0.20506"; const string k_BaseDirectory = "."; -<<<<<<< HEAD #if UNITY_2022_1_OR_NEWER const string k_TargetFrameworkVersion = "net48"; @@ -179,17 +201,14 @@ public void GenerateAll(bool generateAll) const string k_TargetFrameworkVersion = "net471"; #endif -======= - const string k_TargetFrameworkVersion = "v4.7.1"; - ->>>>>>> 8298f45 (Better Support & Formatting) public ProjectGeneration(string tempDirectory) : this( tempDirectory, new AssemblyNameProvider(), new FileIOProvider(), new GUIDProvider() - ) { } + ) + { } public ProjectGeneration( string tempDirectory, @@ -433,6 +452,9 @@ public void GenerateAndWriteSolutionAndProjects() WriteVSCodeSettingsFiles(); WriteWorkspaceFile(); + WriteOmniSharpConfigFile(); + WriteEditorConfigFile(); + WriteUnityAnalyzersFile(); } List ParseResponseFileData(Assembly assembly) @@ -470,13 +492,8 @@ List ParseResponseFileData(Assembly assembly) Dictionary> GenerateAllAssetProjectParts() { -<<<<<<< HEAD Dictionary> stringBuilders = - new Dictionary>(); -======= - Dictionary stringBuilders = new(); - ->>>>>>> 8298f45 (Better Support & Formatting) + new(); foreach (string asset in m_AssemblyNameProvider.GetAllAssetPaths()) { // Exclude files coming from packages except if they are internalized. @@ -508,20 +525,12 @@ Dictionary> GenerateAllAssetProjectParts() stringBuilders[assemblyName] = projectBuilder; } -<<<<<<< HEAD var noneElement = new XElement("None"); noneElement.SetAttributeValue( "Include", m_FileIOProvider.EscapedRelativePathFor(asset, ProjectDirectory) ); projectBuilder.Add(noneElement); -======= - projectBuilder - .Append(" ") - .Append(k_WindowsNewline); ->>>>>>> 8298f45 (Better Support & Formatting) } } @@ -537,11 +546,7 @@ Dictionary> GenerateAllAssetProjectParts() void SyncProject( Assembly assembly, -<<<<<<< HEAD Dictionary> allAssetsProjectParts, -======= - Dictionary allAssetsProjectParts, ->>>>>>> 8298f45 (Better Support & Formatting) List responseFilesData ) { @@ -604,11 +609,7 @@ void SyncFileIfNotChanged(string filename, string newContents) string ProjectText( Assembly assembly, -<<<<<<< HEAD Dictionary> allAssetsProjectParts, -======= - Dictionary allAssetsProjectParts, ->>>>>>> 8298f45 (Better Support & Formatting) List responseFilesData ) { @@ -629,7 +630,6 @@ List responseFilesData // we have source files if (assembly.sourceFiles.Length != 0) { -<<<<<<< HEAD var itemGroup = new XElement("ItemGroup"); foreach (var file in assembly.sourceFiles) @@ -652,21 +652,6 @@ List responseFilesData itemGroup.Add(additionalAssetsForProject); project.Add(itemGroup); } -======= - var fullFile = m_FileIOProvider.EscapedRelativePathFor(file, ProjectDirectory); - projectBuilder - .Append(" ") - .Append(k_WindowsNewline); - } - - // Append additional non-script files that should be included in project generation. - if ( - allAssetsProjectParts.TryGetValue(assembly.name, out var additionalAssetsForProject) - ) - projectBuilder.Append(additionalAssetsForProject); ->>>>>>> 8298f45 (Better Support & Formatting) var responseRefs = responseFilesData.SelectMany( x => x.FullPathReferences.Select(r => r) @@ -680,7 +665,6 @@ List responseFilesData if (allReferences.Any()) { -<<<<<<< HEAD var refItemGroup = new XElement("ItemGroup"); foreach (var reference in allReferences) { @@ -688,41 +672,6 @@ List responseFilesData ? reference : Path.Combine(ProjectDirectory, reference); AppendReference(fullReference, refItemGroup); -======= - string fullReference = Path.IsPathRooted(reference) - ? reference - : Path.Combine(ProjectDirectory, reference); - AppendReference(fullReference, projectBuilder); - } - - if (0 < assembly.assemblyReferences.Length) - { - projectBuilder.Append(" ").Append(k_WindowsNewline); - projectBuilder.Append(" ").Append(k_WindowsNewline); - foreach ( - Assembly reference in assembly.assemblyReferences.Where( - i => i.sourceFiles.Any(ShouldFileBePartOfSolution) - ) - ) - { - projectBuilder - .Append(" ") - .Append(k_WindowsNewline); - projectBuilder - .Append(" {") - .Append(ProjectGuid(reference.name)) - .Append("}") - .Append(k_WindowsNewline); - projectBuilder - .Append(" ") - .Append(reference.name) - .Append("") - .Append(k_WindowsNewline); - projectBuilder.Append(" ").Append(k_WindowsNewline); ->>>>>>> 8298f45 (Better Support & Formatting) } project.Add(refItemGroup); @@ -755,15 +704,16 @@ static void AppendReference(string fullReference, XElement projectBuilder) { var escapedFullPath = SecurityElement.Escape(fullReference); escapedFullPath = escapedFullPath.NormalizePath(); -<<<<<<< HEAD var reference = new XElement( "Reference", new XAttribute("Include", Path.GetFileNameWithoutExtension(escapedFullPath)) ); - var hintPath = new XElement("HintPath"); - hintPath.Value = escapedFullPath; + var hintPath = new XElement("HintPath") + { + Value = escapedFullPath + }; reference.Add(hintPath); projectBuilder.Add(reference); } @@ -780,16 +730,20 @@ XElement builder var langVersion = GenerateLangVersion(otherArguments["langversion"], assembly); var commonPropertyGroup = new XElement("PropertyGroup"); - var langElement = new XElement("LangVersion"); - langElement.Value = langVersion; + var langElement = new XElement("LangVersion") + { + Value = langVersion + }; commonPropertyGroup.Add(langElement); // Allow unsafe code bool allowUnsafeCode = assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe); - var unsafeElement = new XElement("AllowUnsafeBlocks"); - unsafeElement.Value = allowUnsafeCode.ToString(); + var unsafeElement = new XElement("AllowUnsafeBlocks") + { + Value = allowUnsafeCode.ToString() + }; commonPropertyGroup.Add(unsafeElement); var warningLevel = new XElement("WarningLevel", "4"); @@ -812,8 +766,10 @@ XElement builder .ToArray() ); var definePropertyGroup = new XElement("PropertyGroup"); - var definesElement = new XElement("DefineConstants"); - definesElement.Value = defines; + var definesElement = new XElement("DefineConstants") + { + Value = defines + }; definePropertyGroup.Add(definesElement); builder.Add(definePropertyGroup); @@ -825,27 +781,16 @@ XElement builder { foreach (var item in ruleSets) { - var ruleElement = new XElement("CodeAnalysisRuleSet"); - ruleElement.Value = item; + var ruleElement = new XElement("CodeAnalysisRuleSet") + { + Value = item + }; commonPropertyGroup.Add(ruleElement); } } } builder.Add(commonPropertyGroup); -======= - projectBuilder - .Append(" ") - .Append(k_WindowsNewline); - projectBuilder - .Append(" ") - .Append(escapedFullPath) - .Append("") - .Append(k_WindowsNewline); - projectBuilder.Append(" ").Append(k_WindowsNewline); ->>>>>>> 8298f45 (Better Support & Formatting) } public string ProjectFile(Assembly assembly) @@ -865,35 +810,6 @@ private static string GenerateLangVersion( Assembly assembly ) { -<<<<<<< HEAD -======= - var otherArguments = GetOtherArgumentsFromResponseFilesData(responseFilesData); - GetProjectHeaderTemplate( - builder, - ProjectGuid(assembly.name), - assembly.name, - string.Join( - ";", - new[] { "DEBUG", "TRACE" } - .Concat(assembly.defines) - .Concat(responseFilesData.SelectMany(x => x.Defines)) - .Concat(EditorUserBuildSettings.activeScriptCompilationDefines) - .Distinct() - .ToArray() - ), - GenerateLangVersion(otherArguments["langversion"], assembly), - assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe), - GenerateAnalyserItemGroup(RetrieveRoslynAnalyzers(assembly, otherArguments)), - GenerateRoslynAnalyzerRulesetPath(assembly, otherArguments) - ); - } - - private static string GenerateLangVersion( - IEnumerable langVersionList, - Assembly assembly - ) - { ->>>>>>> 8298f45 (Better Support & Formatting) var langVersion = langVersionList.FirstOrDefault(); if (!string.IsNullOrWhiteSpace(langVersion)) return langVersion; @@ -904,17 +820,12 @@ Assembly assembly #endif } -<<<<<<< HEAD private static string[] GenerateRoslynAnalyzerRulesetPath( -======= - private static string GenerateRoslynAnalyzerRulesetPath( ->>>>>>> 8298f45 (Better Support & Formatting) Assembly assembly, ILookup otherResponseFilesData ) { #if UNITY_2020_2_OR_NEWER -<<<<<<< HEAD return otherResponseFilesData["ruleset"] .Append(assembly.compilerOptions.RoslynAnalyzerRulesetPath) .Where(a => !string.IsNullOrEmpty(a)) @@ -926,27 +837,10 @@ ILookup otherResponseFilesData .Distinct() .Select(x => MakeAbsolutePath(x).NormalizePath()) .ToArray(); -======= - return GenerateAnalyserRuleSet( - otherResponseFilesData["ruleset"] - .Append(assembly.compilerOptions.RoslynAnalyzerRulesetPath) - .Where(a => !string.IsNullOrEmpty(a)) - .Distinct() - .Select(x => MakeAbsolutePath(x).NormalizePath()) - .ToArray() - ); -#else - return GenerateAnalyserRuleSet( - otherResponseFilesData["ruleset"] - .Distinct() - .Select(x => MakeAbsolutePath(x).NormalizePath()) - .ToArray() - ); ->>>>>>> 8298f45 (Better Support & Formatting) #endif } - private static string GenerateAnalyserRuleSet(string[] paths) + private static string GenerateAnalyzerRuleSet(string[] paths) { return paths.Length == 0 ? string.Empty @@ -976,72 +870,18 @@ List responseFilesData return new KeyValuePair(key, b[(index + 1)..]); } - const string warnaserror = "warnaserror"; - return b[1..].StartsWith(warnaserror) + const string warnAsError = "warnaserror"; + return b[1..].StartsWith(warnAsError) ? new KeyValuePair( - warnaserror, - b[(warnaserror.Length + 1)..] + warnAsError, + b[(warnAsError.Length + 1)..] ) : default; }); }) -<<<<<<< HEAD .Distinct() .ToLookup(o => o.Key, pair => pair.Value); return paths; -======= - .Distinct() - .ToLookup(o => o.Key, pair => pair.Value); - return paths; - } - - string[] RetrieveRoslynAnalyzers(Assembly assembly, ILookup otherArguments) - { -#if UNITY_2020_2_OR_NEWER - return otherArguments["analyzer"] - .Concat(otherArguments["a"]) - .SelectMany(x => x.Split(';')) -#if !ROSLYN_ANALYZER_FIX - .Concat(m_AssemblyNameProvider.GetRoslynAnalyzerPaths()) -#else - .Concat(assembly.compilerOptions.RoslynAnalyzerDllPaths) -#endif - .Select(MakeAbsolutePath) - .Distinct() - .ToArray(); -#else - return otherArguments["analyzer"] - .Concat(otherArguments["a"]) - .SelectMany(x => x.Split(';')) - .Distinct() - .Select(MakeAbsolutePath) - .ToArray(); -#endif - } - - static string GenerateAnalyserItemGroup(string[] paths) - { - // - // - // - // - if (paths.Length == 0) - { - return string.Empty; - } - - var analyserBuilder = new StringBuilder(); - analyserBuilder.Append(" ").Append(k_WindowsNewline); - foreach (var path in paths) - { - analyserBuilder - .Append($" ") - .Append(k_WindowsNewline); - } - - analyserBuilder.Append(" ").Append(k_WindowsNewline); - return analyserBuilder.ToString(); ->>>>>>> 8298f45 (Better Support & Formatting) } static string GetSolutionText() @@ -1070,168 +910,22 @@ static string GetSolutionText() private static string GetTargetFrameworkVersion(ApiCompatibilityLevel netSettings) { -<<<<<<< HEAD - switch (netSettings) + return netSettings switch { - case ApiCompatibilityLevel.NET_2_0: - case ApiCompatibilityLevel.NET_2_0_Subset: + ApiCompatibilityLevel.NET_2_0 or ApiCompatibilityLevel.NET_2_0_Subset or #if !UNITY_2021_1_OR_NEWER - case ApiCompatibilityLevel.NET_4_6: + ApiCompatibilityLevel.NET_4_6 or #endif - case ApiCompatibilityLevel.NET_Web: - case ApiCompatibilityLevel.NET_Micro: - return k_TargetFrameworkVersion; + ApiCompatibilityLevel.NET_Web or ApiCompatibilityLevel.NET_Micro => k_TargetFrameworkVersion, #if !UNITY_2021_1_OR_NEWER - case ApiCompatibilityLevel.NET_Standard_2_0: - return "netstandard2.0"; + ApiCompatibilityLevel.NET_Standard_2_0 => "netstandard2.0", #endif #if UNITY_2021_1_OR_NEWER - case ApiCompatibilityLevel.NET_Standard: - return "netstandard2.1"; - case ApiCompatibilityLevel.NET_Unity_4_8: - return k_TargetFrameworkVersion; -#else + ApiCompatibilityLevel.NET_Standard => "netstandard2.1", + ApiCompatibilityLevel.NET_Unity_4_8 => k_TargetFrameworkVersion, #endif - default: - throw new ArgumentOutOfRangeException(); - } -======= - return string.Join( - "\r\n", - @" ", - @" ", - @" ", - @"", - @"" - ); - } - - static void GetProjectHeaderTemplate( - StringBuilder builder, - string assemblyGUID, - string assemblyName, - string defines, - string langVersion, - bool allowUnsafe, - string analyzerBlock, - string rulesetBlock - ) - { - builder.Append(@"").Append(k_WindowsNewline); - builder - .Append(@"") - .Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(langVersion) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder - .Append( - @" Debug" - ) - .Append(k_WindowsNewline); - builder - .Append(@" AnyCPU") - .Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(k_ProductVersion) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" 2.0").Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(EditorSettings.projectGenerationRootNamespace) - .Append("") - .Append(k_WindowsNewline); - builder - .Append(@" {") - .Append(assemblyGUID) - .Append("}") - .Append(k_WindowsNewline); - builder.Append(@" Library").Append(k_WindowsNewline); - builder - .Append(@" Properties") - .Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(assemblyName) - .Append("") - .Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(k_TargetFrameworkVersion) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" 512").Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(k_BaseDirectory) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder - .Append( - @" " - ) - .Append(k_WindowsNewline); - builder.Append(@" true").Append(k_WindowsNewline); - builder.Append(@" full").Append(k_WindowsNewline); - builder.Append(@" false").Append(k_WindowsNewline); - builder - .Append(@" Temp\bin\Debug\") - .Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(defines) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" prompt").Append(k_WindowsNewline); - builder.Append(@" 4").Append(k_WindowsNewline); - builder.Append(@" 0169").Append(k_WindowsNewline); - builder - .Append(@" ") - .Append(allowUnsafe) - .Append("") - .Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder.Append(@" ").Append(k_WindowsNewline); - builder.Append(@" true").Append(k_WindowsNewline); - builder.Append(@" true").Append(k_WindowsNewline); - builder - .Append( - @" false" - ) - .Append(k_WindowsNewline); - builder - .Append( - @" false" - ) - .Append(k_WindowsNewline); - builder - .Append( - @" false" - ) - .Append(k_WindowsNewline); - builder.Append(rulesetBlock); - builder.Append(@" ").Append(k_WindowsNewline); - builder.Append(analyzerBlock); - builder.Append(@" ").Append(k_WindowsNewline); ->>>>>>> 8298f45 (Better Support & Formatting) + _ => throw new ArgumentOutOfRangeException() + }; } void SyncSolution(IEnumerable assemblies) @@ -1241,8 +935,8 @@ void SyncSolution(IEnumerable assemblies) string SolutionText(IEnumerable assemblies) { - var fileversion = "11.00"; - var vsversion = "2010"; + var fileVersion = "11.00"; + var vsVersion = "2010"; var relevantAssemblies = RelevantAssembliesForMode(assemblies); string projectEntries = GetProjectEntries(relevantAssemblies); @@ -1254,8 +948,8 @@ string SolutionText(IEnumerable assemblies) ); return string.Format( GetSolutionText(), - fileversion, - vsversion, + fileVersion, + vsVersion, projectEntries, projectConfigurations ); @@ -1267,7 +961,7 @@ static IEnumerable RelevantAssembliesForMode(IEnumerable ass } /// - /// Get a Project("{guid}") = "MyProject", "MyProject.csproj", "{projectguid}" + /// Get a Project("{guid}") = "MyProject", "MyProject.csproj", "{projectGuid}" /// entry for each relevant language /// string GetProjectEntries(IEnumerable assemblies) @@ -1312,14 +1006,6 @@ string SolutionGuid(Assembly assembly) m_ProjectName, GetExtensionOfSourceFiles(assembly.sourceFiles) ); -<<<<<<< HEAD -======= - } - - static string ProjectFooter() - { - return GetProjectFooterTemplate(); ->>>>>>> 8298f45 (Better Support & Formatting) } static string GetProjectExtension() @@ -1347,6 +1033,52 @@ void WriteWorkspaceFile() if (!m_FileIOProvider.Exists(workspaceFile)) m_FileIOProvider.WriteAllText(workspaceFile, k_WorkspaceJson); } + + void WriteOmniSharpConfigFile() + { + var omniSharpConfig = Path.Combine(ProjectDirectory, "omnisharp.json"); + + if (!m_FileIOProvider.Exists(omniSharpConfig)) + m_FileIOProvider.WriteAllText(omniSharpConfig, k_OmniSharpJson); + } + + void WriteEditorConfigFile() + { + var editorConfig = Path.Combine(ProjectDirectory, ".editorconfig"); + + if (!m_FileIOProvider.Exists(editorConfig)) + m_FileIOProvider.WriteAllText(editorConfig, k_EditorConfig); + } + + void WriteUnityAnalyzersFile() + { + var nugetDirectory = Path.Combine(ProjectDirectory, "NuGet"); + + if (!m_FileIOProvider.Exists(nugetDirectory)) + m_FileIOProvider.CreateDirectory(nugetDirectory); + + var unityAnalyzers = Path.Combine(nugetDirectory, "Microsoft.Unity.Analyzers.dll"); + + /* + This is the path to the roslyn analyzers dll in the Unity package, and is the only way + I could find to get the analyzers dll into the project without extra user setup + */ + var unityRoslynKoalafiedDLL = Path.Combine( + ProjectDirectory, + "Packages", + "com.tsk.ide.vscode", + "Editor", + "NuGet", + "Microsoft.Unity.Analyzers.dll.koala" + ); + + /* + This file will be overwritten if it already exists in case the version of the analyzers changes + I could use a txt file to store the version of the analyzers, and only overwrite if the version changes + but I don't think it's worth the effort + */ + m_FileIOProvider.Copy(unityRoslynKoalafiedDLL, unityAnalyzers, true); + } } public static class SolutionGuidGenerator @@ -1369,4 +1101,4 @@ static string ComputeGuidHashFor(string input) return new Guid(hash).ToString(); } } -} +} \ No newline at end of file diff --git a/Editor/VSCodeScriptEditor.cs b/Editor/VSCodeScriptEditor.cs index 67b33fc..51ded77 100644 --- a/Editor/VSCodeScriptEditor.cs +++ b/Editor/VSCodeScriptEditor.cs @@ -1,10 +1,10 @@ using System; +using System.Diagnostics; using System.IO; using System.Linq; -using System.Diagnostics; +using Unity.CodeEditor; using UnityEditor; using UnityEngine; -using Unity.CodeEditor; namespace VSCodeEditor { @@ -179,26 +179,6 @@ public void CreateIfDoesntExist() { m_ProjectGeneration.Sync(); } - - if (!HasNuGetFolder()) - { - CreateNuGetFolder(); - } - - if (!HasRoslynDLL()) - { - CreateRoslynDLL(); - } - - if (!HasOmniSharpConfig()) - { - CreateOmniSharpConfig(); - } - - if (!HasEditorConfig()) - { - CreateEditorConfig(); - } } public void SyncIfNeeded( @@ -299,174 +279,6 @@ static bool OpenOSX(string arguments) return true; } - private void CreateNuGetFolder() - { - var nugetFolder = Path.Combine(m_ProjectGeneration.ProjectDirectory, "NuGet"); -<<<<<<< HEAD - -======= - ->>>>>>> 8298f45 (Better Support & Formatting) - Directory.CreateDirectory(nugetFolder); - } - - private bool HasNuGetFolder() - { - var nugetFolder = Path.Combine(m_ProjectGeneration.ProjectDirectory, "NuGet"); - return Directory.Exists(nugetFolder); - } - - private void CreateRoslynDLL() - { - string unityRoslynDLL = Path.Combine( - m_ProjectGeneration.ProjectDirectory, - "Packages", - "com.tsk.ide.vscode", - "Editor", - "NuGet", - "Microsoft.Unity.Analyzers.dll.koala" - ); - - string nugetFolder = Path.Combine(m_ProjectGeneration.ProjectDirectory, "NuGet"); - string nugetRoslynDLL = Path.Combine(nugetFolder, "Microsoft.Unity.Analyzers.dll"); - - File.Copy(unityRoslynDLL, nugetRoslynDLL); - } - - private bool HasRoslynDLL() - { - string nugetFolder = Path.Combine(m_ProjectGeneration.ProjectDirectory, "NuGet"); - string nugetRoslynDLL = Path.Combine(nugetFolder, "Microsoft.Unity.Analyzers.dll"); - - return File.Exists(nugetRoslynDLL); - } - - private void CreateOmniSharpConfig() - { - string configFilePath = Path.Combine( - m_ProjectGeneration.ProjectDirectory, - "omnisharp.json" - ); - -<<<<<<< HEAD - const string Contents = - @"{ - ""FormattingOptions"": { - ""newLine"": ""\n"", - ""useTabs"": false, - ""tabSize"": 2, - ""indentationSize"": 2, - - ""NewLinesForBracesInTypes"": false, - ""NewLinesForBracesInMethods"": false, - ""NewLinesForBracesInProperties"": false, - ""NewLinesForBracesInAccessors"": false, - ""NewLinesForBracesInAnonymousMethods"": false, - ""NewLinesForBracesInControlBlocks"": false, - ""NewLinesForBracesInAnonymousTypes"": false, - ""NewLinesForBracesInObjectCollectionArrayInitializers"": false, - ""NewLinesForBracesInLambdaExpressionBody"": false, - - ""NewLineForElse"": false, - ""NewLineForCatch"": false, - ""NewLineForFinally"": false, - ""NewLineForMembersInObjectInit"": false, - ""NewLineForMembersInAnonymousTypes"": false, - ""NewLineForClausesInQuery"": false - },"; - - File.WriteAllText( - configFilePath, - /*lang=json,strict*/ - Contents - ); - - string roslynExtensionsOptions = - @" - ""RoslynExtensionsOptions"": { - ""enableRoslynAnalyzers"": true, - ""enableEditorConfigSupport"": true, - ""sdkIncludePrereleases"": false, - ""organizeImportsOnFormat"": true, - ""threadsToUseForAnalyzers"": true, - ""useModernNet"": true, - ""documentAnalysisTimeoutMs"": 600000, - ""LocationPaths"": [""./NuGet""] - } -}"; - File.AppendAllText(configFilePath, roslynExtensionsOptions); -======= - File.WriteAllText( - configFilePath, - @"{ - ""RoslynExtensionsOptions"": { - ""EnableAnalyzersSupport"": true, - ""LocationPaths"": [""./NuGet""] - }, - ""FormattingOptions"": { - ""newLine"": ""\n"", - ""useTabs"": false, - ""tabSize"": 2, - ""indentationSize"": 2, - - ""NewLinesForBracesInTypes"": false, - ""NewLinesForBracesInMethods"": false, - ""NewLinesForBracesInProperties"": false, - ""NewLinesForBracesInAccessors"": false, - ""NewLinesForBracesInAnonymousMethods"": false, - ""NewLinesForBracesInControlBlocks"": false, - ""NewLinesForBracesInAnonymousTypes"": false, - ""NewLinesForBracesInObjectCollectionArrayInitializers"": false, - ""NewLinesForBracesInLambdaExpressionBody"": false, - - ""NewLineForElse"": false, - ""NewLineForCatch"": false, - ""NewLineForFinally"": false, - ""NewLineForMembersInObjectInit"": false, - ""NewLineForMembersInAnonymousTypes"": false, - ""NewLineForClausesInQuery"": false - } -}" - ); ->>>>>>> 8298f45 (Better Support & Formatting) - } - - private bool HasOmniSharpConfig() - { - string configFilePath = Path.Combine( - m_ProjectGeneration.ProjectDirectory, - "omnisharp.json" - ); - - return File.Exists(configFilePath); - } - - private void CreateEditorConfig() - { - string configFilePath = Path.Combine( - m_ProjectGeneration.ProjectDirectory, - ".editorconfig" - ); - - File.WriteAllText( - configFilePath, - @"root=true - -[*.cs] -dotnet_diagnostic.IDE0051.severity = none" - ); - } - - private bool HasEditorConfig() - { - string configFilePath = Path.Combine( - m_ProjectGeneration.ProjectDirectory, - ".editorconfig" - ); - - return File.Exists(configFilePath); - } - static bool SupportsExtension(string path) { var extension = Path.GetExtension(path); @@ -494,7 +306,6 @@ static VSCodeScriptEditor() if (IsVSCodeInstallation(CodeEditor.CurrentEditorInstallation)) { editor.CreateIfDoesntExist(); - } } @@ -517,4 +328,4 @@ static bool IsVSCodeInstallation(string path) public void Initialize(string editorInstallationPath) { } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index fa0f5ce..b58a958 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "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.3.0", - "unity": "2021.3", + "version": "1.3.1", + "unity": "2022.2", "dependencies": {}, "author": { "name": "Chizaruu",