Skip to content

Commit ebe8973

Browse files
author
Unity Technologies
committed
## [2.0.18] - 2023-03-17 Integration: - Performance improvements with `EditorApplication.update` callbacks. Project generation: - Add extra compiler options for analyzers and source generators.
1 parent 4893e3b commit ebe8973

File tree

7 files changed

+76
-26
lines changed

7 files changed

+76
-26
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Code Editor Package for Visual Studio
22

3+
## [2.0.18] - 2023-03-17
4+
5+
Integration:
6+
7+
- Performance improvements with `EditorApplication.update` callbacks.
8+
9+
Project generation:
10+
11+
- Add extra compiler options for analyzers and source generators.
12+
13+
314
## [2.0.17] - 2022-12-06
415

516
Integration:
0 Bytes
Binary file not shown.
Binary file not shown.

Editor/ProjectGeneration/ProjectGeneration.cs

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -664,33 +664,50 @@ private static IEnumerable<string> GetOtherArguments(ResponseFileData[] response
664664
}
665665
}
666666

667-
private string[] GetAnalyzers(Assembly assembly, ResponseFileData[] responseFilesData, out string rulesetPath)
667+
private void SetAnalyzerAndSourceGeneratorProperties(Assembly assembly, ResponseFileData[] responseFilesData, ProjectProperties properties)
668668
{
669-
rulesetPath = null;
670-
671669
if (m_CurrentInstallation == null || !m_CurrentInstallation.SupportsAnalyzers)
672-
return Array.Empty<string>();
673-
670+
return;
671+
674672
// Analyzers provided by VisualStudio
675-
List<string> analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
673+
var analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
674+
var additionalFilePaths = new List<string>();
675+
var rulesetPath = string.Empty;
676+
var analyzerConfigPath = string.Empty;
676677

677678
#if UNITY_2020_2_OR_NEWER
678679
// Analyzers + ruleset provided by Unity
679680
analyzers.AddRange(assembly.compilerOptions.RoslynAnalyzerDllPaths);
681+
rulesetPath = assembly.compilerOptions.RoslynAnalyzerRulesetPath;
682+
#endif
680683

681-
rulesetPath = assembly
682-
.compilerOptions
683-
.RoslynAnalyzerRulesetPath
684-
.MakeAbsolutePath()
685-
.NormalizePathSeparators();
684+
#if UNITY_2021_3_OR_NEWER && !UNITY_2022_1 // we have support in 2021.3, 2022.2 but without a backport in 2022.1
685+
additionalFilePaths.AddRange(assembly.compilerOptions.RoslynAdditionalFilePaths);
686+
analyzerConfigPath = assembly.compilerOptions.AnalyzerConfigPath;
686687
#endif
687688

688-
// Analyzers provided by csc.rsp
689+
// Analyzers and additional files provided by csc.rsp
689690
analyzers.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(new[] { "analyzer", "a" })));
691+
additionalFilePaths.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(new[] { "additionalfile" })));
690692

691-
return analyzers
693+
properties.RulesetPath = ToNormalizedPath(rulesetPath);
694+
properties.Analyzers = ToNormalizedPaths(analyzers);
695+
properties.AnalyzerConfigPath = ToNormalizedPath(analyzerConfigPath);
696+
properties.AdditionalFilePaths = ToNormalizedPaths(additionalFilePaths);
697+
}
698+
699+
private string ToNormalizedPath(string path)
700+
{
701+
return path
702+
.MakeAbsolutePath()
703+
.NormalizePathSeparators();
704+
}
705+
706+
private string[] ToNormalizedPaths(IEnumerable<string> values)
707+
{
708+
return values
692709
.Where(a => !string.IsNullOrEmpty(a))
693-
.Select(a => a.MakeAbsolutePath().NormalizePathSeparators())
710+
.Select(a => ToNormalizedPath(a))
694711
.Distinct()
695712
.ToArray();
696713
}
@@ -702,7 +719,6 @@ out StringBuilder headerBuilder
702719
)
703720
{
704721
var projectType = ProjectTypeOf(assembly.name);
705-
var analyzers = GetAnalyzers(assembly, responseFilesData, out var rulesetPath);
706722

707723
var projectProperties = new ProjectProperties
708724
{
@@ -711,10 +727,7 @@ out StringBuilder headerBuilder
711727
AssemblyName = assembly.name,
712728
RootNamespace = GetRootNamespace(assembly),
713729
OutputPath = assembly.outputPath,
714-
// Analyzers
715-
RulesetPath = rulesetPath,
716730
// RSP alterable
717-
Analyzers = analyzers,
718731
Defines = assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray(),
719732
Unsafe = assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
720733
// VSTU Flavoring
@@ -724,6 +737,8 @@ out StringBuilder headerBuilder
724737
FlavoringPackageVersion = VisualStudioIntegration.PackageVersion(),
725738
};
726739

740+
SetAnalyzerAndSourceGeneratorProperties(assembly, responseFilesData, projectProperties);
741+
727742
GetProjectHeader(projectProperties, out headerBuilder);
728743
}
729744

@@ -830,6 +845,23 @@ private void GetProjectHeader(ProjectProperties properties, out StringBuilder he
830845
}
831846
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
832847
}
848+
849+
if (!string.IsNullOrEmpty(properties.AnalyzerConfigPath))
850+
{
851+
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
852+
headerBuilder.Append(@" <EditorConfigFiles Include=""").Append(properties.AnalyzerConfigPath).Append(@""" />").Append(k_WindowsNewline);
853+
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
854+
}
855+
856+
if (properties.AdditionalFilePaths.Any())
857+
{
858+
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
859+
foreach (var additionalFile in properties.AdditionalFilePaths)
860+
{
861+
headerBuilder.Append(@" <AdditionalFiles Include=""").Append(additionalFile).Append(@""" />").Append(k_WindowsNewline);
862+
}
863+
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
864+
}
833865
}
834866

835867
private static string GetProjectFooter()

Editor/ProjectGeneration/ProjectProperties.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ internal class ProjectProperties
1313
// Analyzers
1414
public string[] Analyzers { get; set; } = Array.Empty<string>();
1515
public string RulesetPath { get; set; } = string.Empty;
16+
public string AnalyzerConfigPath { get; set; } = string.Empty;
17+
// Source generators
18+
public string[] AdditionalFilePaths { get; set; } = Array.Empty<string>();
1619

1720
// RSP alterable
1821
public string[] Defines { get; set; } = Array.Empty<string>();

Editor/VisualStudioIntegration.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class VisualStudioIntegration
2222
class Client
2323
{
2424
public IPEndPoint EndPoint { get; set; }
25-
public DateTime LastMessage { get; set; }
25+
public double LastMessage { get; set; }
2626
}
2727

2828
private static Messager _messager;
@@ -141,7 +141,8 @@ private static void OnUpdate()
141141
{
142142
foreach (var client in _clients.Values.ToArray())
143143
{
144-
if (DateTime.Now.Subtract(client.LastMessage) > TimeSpan.FromMilliseconds(4000))
144+
// EditorApplication.timeSinceStartup: The time since the editor was started, in seconds, not reset when starting play mode.
145+
if (EditorApplication.timeSinceStartup - client.LastMessage > 4)
145146
_clients.Remove(client.EndPoint);
146147
}
147148
}
@@ -216,14 +217,14 @@ private static void CheckClient(Message message)
216217
client = new Client
217218
{
218219
EndPoint = endPoint,
219-
LastMessage = DateTime.Now
220+
LastMessage = EditorApplication.timeSinceStartup
220221
};
221222

222223
_clients.Add(endPoint, client);
223224
}
224225
else
225226
{
226-
client.LastMessage = DateTime.Now;
227+
client.LastMessage = EditorApplication.timeSinceStartup;
227228
}
228229
}
229230

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
"name": "com.unity.ide.visualstudio",
33
"displayName": "Visual Studio Editor",
44
"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.",
5-
"version": "2.0.17",
5+
"version": "2.0.18",
66
"unity": "2019.4",
77
"unityRelease": "25f1",
88
"dependencies": {
99
"com.unity.test-framework": "1.1.9"
1010
},
1111
"relatedPackages": {
12-
"com.unity.ide.visualstudio.tests": "2.0.17"
12+
"com.unity.ide.visualstudio.tests": "2.0.18"
13+
},
14+
"_upm": {
15+
"changelog": "Integration:\n\n- Performance improvements with `EditorApplication.update` callbacks.\n \nProject generation:\n\n- Add extra compiler options for analyzers and source generators."
1316
},
1417
"upmCi": {
15-
"footprint": "95a297ed65f40d1df2fe8239f87deab3217a10b0"
18+
"footprint": "1d7ac8985c088423201e27b93ccdc6292ff941c9"
1619
},
1720
"documentationUrl": "https://docs.unity3d.com/Packages/[email protected]/manual/index.html",
1821
"repository": {
1922
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
2023
"type": "git",
21-
"revision": "1f126893bfb18ea9661fb15771613e841467073c"
24+
"revision": "9d3c07127cbe1916b8abbfd18f71fb8d9df8008c"
2225
}
2326
}

0 commit comments

Comments
 (0)