diff --git a/CHANGELOG.md b/CHANGELOG.md index fd79e62..2bcf186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Code Editor Package for Visual Studio +## [2.0.18] - 2023-03-17 + +Integration: + +- Performance improvements with `EditorApplication.update` callbacks. + +Project generation: + +- Add extra compiler options for analyzers and source generators. + + ## [2.0.17] - 2022-12-06 Integration: diff --git a/Editor/COMIntegration/Release/COMIntegration.exe b/Editor/COMIntegration/Release/COMIntegration.exe index 70080ff..d67f42c 100644 Binary files a/Editor/COMIntegration/Release/COMIntegration.exe and b/Editor/COMIntegration/Release/COMIntegration.exe differ diff --git a/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration b/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration index d37b4ad..5972034 100644 Binary files a/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration and b/Editor/Plugins/AppleEventIntegration.bundle/Contents/MacOS/AppleEventIntegration differ diff --git a/Editor/ProjectGeneration/ProjectGeneration.cs b/Editor/ProjectGeneration/ProjectGeneration.cs index b94a90e..35d77b0 100644 --- a/Editor/ProjectGeneration/ProjectGeneration.cs +++ b/Editor/ProjectGeneration/ProjectGeneration.cs @@ -664,33 +664,50 @@ private static IEnumerable GetOtherArguments(ResponseFileData[] response } } - private string[] GetAnalyzers(Assembly assembly, ResponseFileData[] responseFilesData, out string rulesetPath) + private void SetAnalyzerAndSourceGeneratorProperties(Assembly assembly, ResponseFileData[] responseFilesData, ProjectProperties properties) { - rulesetPath = null; - if (m_CurrentInstallation == null || !m_CurrentInstallation.SupportsAnalyzers) - return Array.Empty(); - + return; + // Analyzers provided by VisualStudio - List analyzers = new List(m_CurrentInstallation.GetAnalyzers()); + var analyzers = new List(m_CurrentInstallation.GetAnalyzers()); + var additionalFilePaths = new List(); + var rulesetPath = string.Empty; + var analyzerConfigPath = string.Empty; #if UNITY_2020_2_OR_NEWER // Analyzers + ruleset provided by Unity analyzers.AddRange(assembly.compilerOptions.RoslynAnalyzerDllPaths); + rulesetPath = assembly.compilerOptions.RoslynAnalyzerRulesetPath; +#endif - rulesetPath = assembly - .compilerOptions - .RoslynAnalyzerRulesetPath - .MakeAbsolutePath() - .NormalizePathSeparators(); +#if UNITY_2021_3_OR_NEWER && !UNITY_2022_1 // we have support in 2021.3, 2022.2 but without a backport in 2022.1 + additionalFilePaths.AddRange(assembly.compilerOptions.RoslynAdditionalFilePaths); + analyzerConfigPath = assembly.compilerOptions.AnalyzerConfigPath; #endif - // Analyzers provided by csc.rsp + // Analyzers and additional files provided by csc.rsp analyzers.AddRange(GetOtherArguments(responseFilesData, new HashSet(new[] { "analyzer", "a" }))); + additionalFilePaths.AddRange(GetOtherArguments(responseFilesData, new HashSet(new[] { "additionalfile" }))); - return analyzers + properties.RulesetPath = ToNormalizedPath(rulesetPath); + properties.Analyzers = ToNormalizedPaths(analyzers); + properties.AnalyzerConfigPath = ToNormalizedPath(analyzerConfigPath); + properties.AdditionalFilePaths = ToNormalizedPaths(additionalFilePaths); + } + + private string ToNormalizedPath(string path) + { + return path + .MakeAbsolutePath() + .NormalizePathSeparators(); + } + + private string[] ToNormalizedPaths(IEnumerable values) + { + return values .Where(a => !string.IsNullOrEmpty(a)) - .Select(a => a.MakeAbsolutePath().NormalizePathSeparators()) + .Select(a => ToNormalizedPath(a)) .Distinct() .ToArray(); } @@ -702,7 +719,6 @@ out StringBuilder headerBuilder ) { var projectType = ProjectTypeOf(assembly.name); - var analyzers = GetAnalyzers(assembly, responseFilesData, out var rulesetPath); var projectProperties = new ProjectProperties { @@ -711,10 +727,7 @@ out StringBuilder headerBuilder AssemblyName = assembly.name, RootNamespace = GetRootNamespace(assembly), OutputPath = assembly.outputPath, - // Analyzers - RulesetPath = rulesetPath, // RSP alterable - Analyzers = analyzers, Defines = assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray(), Unsafe = assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe), // VSTU Flavoring @@ -724,6 +737,8 @@ out StringBuilder headerBuilder FlavoringPackageVersion = VisualStudioIntegration.PackageVersion(), }; + SetAnalyzerAndSourceGeneratorProperties(assembly, responseFilesData, projectProperties); + GetProjectHeader(projectProperties, out headerBuilder); } @@ -830,6 +845,23 @@ private void GetProjectHeader(ProjectProperties properties, out StringBuilder he } headerBuilder.Append(@" ").Append(k_WindowsNewline); } + + if (!string.IsNullOrEmpty(properties.AnalyzerConfigPath)) + { + headerBuilder.Append(@" ").Append(k_WindowsNewline); + headerBuilder.Append(@" ").Append(k_WindowsNewline); + headerBuilder.Append(@" ").Append(k_WindowsNewline); + } + + if (properties.AdditionalFilePaths.Any()) + { + headerBuilder.Append(@" ").Append(k_WindowsNewline); + foreach (var additionalFile in properties.AdditionalFilePaths) + { + headerBuilder.Append(@" ").Append(k_WindowsNewline); + } + headerBuilder.Append(@" ").Append(k_WindowsNewline); + } } private static string GetProjectFooter() diff --git a/Editor/ProjectGeneration/ProjectProperties.cs b/Editor/ProjectGeneration/ProjectProperties.cs index 6438f24..c8963e0 100644 --- a/Editor/ProjectGeneration/ProjectProperties.cs +++ b/Editor/ProjectGeneration/ProjectProperties.cs @@ -13,6 +13,9 @@ internal class ProjectProperties // Analyzers public string[] Analyzers { get; set; } = Array.Empty(); public string RulesetPath { get; set; } = string.Empty; + public string AnalyzerConfigPath { get; set; } = string.Empty; + // Source generators + public string[] AdditionalFilePaths { get; set; } = Array.Empty(); // RSP alterable public string[] Defines { get; set; } = Array.Empty(); diff --git a/Editor/VisualStudioIntegration.cs b/Editor/VisualStudioIntegration.cs index 570203e..8ddc22a 100644 --- a/Editor/VisualStudioIntegration.cs +++ b/Editor/VisualStudioIntegration.cs @@ -22,7 +22,7 @@ internal class VisualStudioIntegration class Client { public IPEndPoint EndPoint { get; set; } - public DateTime LastMessage { get; set; } + public double LastMessage { get; set; } } private static Messager _messager; @@ -141,7 +141,8 @@ private static void OnUpdate() { foreach (var client in _clients.Values.ToArray()) { - if (DateTime.Now.Subtract(client.LastMessage) > TimeSpan.FromMilliseconds(4000)) + // EditorApplication.timeSinceStartup: The time since the editor was started, in seconds, not reset when starting play mode. + if (EditorApplication.timeSinceStartup - client.LastMessage > 4) _clients.Remove(client.EndPoint); } } @@ -216,14 +217,14 @@ private static void CheckClient(Message message) client = new Client { EndPoint = endPoint, - LastMessage = DateTime.Now + LastMessage = EditorApplication.timeSinceStartup }; _clients.Add(endPoint, client); } else { - client.LastMessage = DateTime.Now; + client.LastMessage = EditorApplication.timeSinceStartup; } } diff --git a/package.json b/package.json index 4e03b5e..d460d81 100644 --- a/package.json +++ b/package.json @@ -2,22 +2,25 @@ "name": "com.unity.ide.visualstudio", "displayName": "Visual Studio Editor", "description": "Code editor integration for supporting Visual Studio as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.", - "version": "2.0.17", + "version": "2.0.18", "unity": "2019.4", "unityRelease": "25f1", "dependencies": { "com.unity.test-framework": "1.1.9" }, "relatedPackages": { - "com.unity.ide.visualstudio.tests": "2.0.17" + "com.unity.ide.visualstudio.tests": "2.0.18" + }, + "_upm": { + "changelog": "Integration:\n\n- Performance improvements with `EditorApplication.update` callbacks.\n \nProject generation:\n\n- Add extra compiler options for analyzers and source generators." }, "upmCi": { - "footprint": "95a297ed65f40d1df2fe8239f87deab3217a10b0" + "footprint": "1d7ac8985c088423201e27b93ccdc6292ff941c9" }, "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.ide.visualstudio@2.0/manual/index.html", "repository": { "url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git", "type": "git", - "revision": "1f126893bfb18ea9661fb15771613e841467073c" + "revision": "9d3c07127cbe1916b8abbfd18f71fb8d9df8008c" } }