Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.0.18] - 2023-03-17

Integration:

- Performance improvements with `EditorApplication.update` callbacks.

Project generation:

- Add extra compiler options for analyzers and source generators.
  • Loading branch information
Unity Technologies committed Mar 17, 2023
1 parent 4893e3b commit ebe8973
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 26 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Binary file modified Editor/COMIntegration/Release/COMIntegration.exe
Binary file not shown.
Binary file not shown.
68 changes: 50 additions & 18 deletions Editor/ProjectGeneration/ProjectGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,33 +664,50 @@ private static IEnumerable<string> 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<string>();
return;

// Analyzers provided by VisualStudio
List<string> analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
var analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
var additionalFilePaths = new List<string>();
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<string>(new[] { "analyzer", "a" })));
additionalFilePaths.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(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<string> values)
{
return values
.Where(a => !string.IsNullOrEmpty(a))
.Select(a => a.MakeAbsolutePath().NormalizePathSeparators())
.Select(a => ToNormalizedPath(a))
.Distinct()
.ToArray();
}
Expand All @@ -702,7 +719,6 @@ out StringBuilder headerBuilder
)
{
var projectType = ProjectTypeOf(assembly.name);
var analyzers = GetAnalyzers(assembly, responseFilesData, out var rulesetPath);

var projectProperties = new ProjectProperties
{
Expand All @@ -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
Expand All @@ -724,6 +737,8 @@ out StringBuilder headerBuilder
FlavoringPackageVersion = VisualStudioIntegration.PackageVersion(),
};

SetAnalyzerAndSourceGeneratorProperties(assembly, responseFilesData, projectProperties);

GetProjectHeader(projectProperties, out headerBuilder);
}

Expand Down Expand Up @@ -830,6 +845,23 @@ private void GetProjectHeader(ProjectProperties properties, out StringBuilder he
}
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}

if (!string.IsNullOrEmpty(properties.AnalyzerConfigPath))
{
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
headerBuilder.Append(@" <EditorConfigFiles Include=""").Append(properties.AnalyzerConfigPath).Append(@""" />").Append(k_WindowsNewline);
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}

if (properties.AdditionalFilePaths.Any())
{
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (var additionalFile in properties.AdditionalFilePaths)
{
headerBuilder.Append(@" <AdditionalFiles Include=""").Append(additionalFile).Append(@""" />").Append(k_WindowsNewline);
}
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}
}

private static string GetProjectFooter()
Expand Down
3 changes: 3 additions & 0 deletions Editor/ProjectGeneration/ProjectProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ internal class ProjectProperties
// Analyzers
public string[] Analyzers { get; set; } = Array.Empty<string>();
public string RulesetPath { get; set; } = string.Empty;
public string AnalyzerConfigPath { get; set; } = string.Empty;
// Source generators
public string[] AdditionalFilePaths { get; set; } = Array.Empty<string>();

// RSP alterable
public string[] Defines { get; set; } = Array.Empty<string>();
Expand Down
9 changes: 5 additions & 4 deletions Editor/VisualStudioIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/manual/index.html",
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
"type": "git",
"revision": "1f126893bfb18ea9661fb15771613e841467073c"
"revision": "9d3c07127cbe1916b8abbfd18f71fb8d9df8008c"
}
}

0 comments on commit ebe8973

Please sign in to comment.