-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When replacing CodeStyle analyzers do not provide Features analyzers fallback options #75534
Changes from 1 commit
0a838b9
180455c
03eccdd
e9f7c04
1198405
7344695
dff04fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,11 @@ internal sealed partial class ProjectSystemProject | |
/// </summary> | ||
private readonly HashSet<string> _projectAnalyzerPaths = []; | ||
|
||
/// <summary> | ||
/// The set of unmapped analyzer reference paths that the project knows about. | ||
/// </summary> | ||
private readonly HashSet<string> _unmappedProjectAnalyzerPaths = []; | ||
|
||
/// <summary> | ||
/// Paths to analyzers we want to add when the current batch completes. | ||
/// </summary> | ||
|
@@ -81,6 +86,7 @@ internal sealed partial class ProjectSystemProject | |
private string? _outputFilePath; | ||
private string? _outputRefFilePath; | ||
private string? _defaultNamespace; | ||
private bool _hasSdkCodeStyleAnalyzers; | ||
|
||
/// <summary> | ||
/// If this project is the 'primary' project the project system cares about for a group of Roslyn projects that | ||
|
@@ -446,14 +452,20 @@ private void UpdateRunAnalyzers() | |
ChangeProjectProperty(ref _runAnalyzers, runAnalyzers, s => s.WithRunAnalyzers(Id, runAnalyzers)); | ||
} | ||
|
||
internal bool HasSdkCodeStyleAnalyzers | ||
{ | ||
get => _hasSdkCodeStyleAnalyzers; | ||
set => ChangeProjectProperty(ref _hasSdkCodeStyleAnalyzers, value, s => s.WithHasSdkCodeStyleAnalyzers(Id, value)); | ||
} | ||
|
||
/// <summary> | ||
/// The default namespace of the project. | ||
/// </summary> | ||
/// <remarks> | ||
/// In C#, this is defined as the value of "rootnamespace" msbuild property. Right now VB doesn't | ||
/// In C#, this is defined as the value of "rootnamespace" msbuild property. Right now VB doesn't | ||
/// have the concept of "default namespace", but we conjure one in workspace by assigning the value | ||
/// of the project's root namespace to it. So various features can choose to use it for their own purpose. | ||
/// | ||
/// | ||
/// In the future, we might consider officially exposing "default namespace" for VB project | ||
/// (e.g.through a "defaultnamespace" msbuild property) | ||
/// </remarks> | ||
|
@@ -464,8 +476,8 @@ internal string? DefaultNamespace | |
} | ||
|
||
/// <summary> | ||
/// The max language version supported for this project, if applicable. Useful to help indicate what | ||
/// language version features should be suggested to a user, as well as if they can be upgraded. | ||
/// The max language version supported for this project, if applicable. Useful to help indicate what | ||
/// language version features should be suggested to a user, as well as if they can be upgraded. | ||
/// </summary> | ||
internal string? MaxLangVersion | ||
{ | ||
|
@@ -857,7 +869,7 @@ public void AddDynamicSourceFile(string dynamicFilePath, ImmutableArray<string> | |
// Don't get confused by _filePath and filePath. | ||
// VisualStudioProject._filePath points to csproj/vbproj of the project | ||
// and the parameter filePath points to dynamic file such as ASP.NET .g.cs files. | ||
// | ||
// | ||
// Also, provider is free-threaded. so fine to call Wait rather than JTF. | ||
fileInfo = provider.Value.GetDynamicFileInfoAsync( | ||
projectId: Id, projectFilePath: _filePath, filePath: dynamicFilePath, CancellationToken.None).WaitAndGetResult_CanCallOnBackground(CancellationToken.None); | ||
|
@@ -948,7 +960,7 @@ private void OnDynamicFileInfoUpdated(object? sender, string dynamicFilePath) | |
{ | ||
if (!_dynamicFilePathMaps.TryGetValue(dynamicFilePath, out fileInfoPath)) | ||
{ | ||
// given file doesn't belong to this project. | ||
// given file doesn't belong to this project. | ||
// this happen since the event this is handling is shared between all projects | ||
return; | ||
} | ||
|
@@ -970,10 +982,18 @@ public void AddAnalyzerReference(string fullPath) | |
|
||
var mappedPaths = GetMappedAnalyzerPaths(fullPath); | ||
|
||
bool containsSdkCodeStyleAnalyzers; | ||
|
||
using var _ = CreateBatchScope(); | ||
|
||
using (_gate.DisposableWait()) | ||
{ | ||
// Track the unmapped analyzer paths | ||
_unmappedProjectAnalyzerPaths.Add(fullPath); | ||
|
||
// Determine if we started using SDK CodeStyle analyzers while access to _unmappedProjectAnalyzerPaths is gated. | ||
containsSdkCodeStyleAnalyzers = _unmappedProjectAnalyzerPaths.Any(IsSdkCodeStyleAnalyzer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ What about
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree on tweaking this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this to only track the codestyle analyzer paths instead of tracking all analyzer paths. Only one call to |
||
|
||
// check all mapped paths first, so that all analyzers are either added or not | ||
foreach (var mappedFullPath in mappedPaths) | ||
{ | ||
|
@@ -998,6 +1018,8 @@ public void AddAnalyzerReference(string fullPath) | |
} | ||
} | ||
} | ||
|
||
HasSdkCodeStyleAnalyzers = containsSdkCodeStyleAnalyzers; | ||
} | ||
|
||
public void RemoveAnalyzerReference(string fullPath) | ||
|
@@ -1007,10 +1029,18 @@ public void RemoveAnalyzerReference(string fullPath) | |
|
||
var mappedPaths = GetMappedAnalyzerPaths(fullPath); | ||
|
||
bool containsSdkCodeStyleAnalyzers; | ||
|
||
using var _ = CreateBatchScope(); | ||
|
||
using (_gate.DisposableWait()) | ||
{ | ||
// Track the unmapped analyzer paths | ||
_unmappedProjectAnalyzerPaths.Remove(fullPath); | ||
|
||
// Determine if we are still using SDK CodeStyle analyzers while access to _unmappedProjectAnalyzerPaths is gated. | ||
containsSdkCodeStyleAnalyzers = _unmappedProjectAnalyzerPaths.Any(IsSdkCodeStyleAnalyzer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Can also simplify this one:
|
||
|
||
// check all mapped paths first, so that all analyzers are either removed or not | ||
foreach (var mappedFullPath in mappedPaths) | ||
{ | ||
|
@@ -1028,6 +1058,8 @@ public void RemoveAnalyzerReference(string fullPath) | |
_analyzersRemovedInBatch.Add(mappedFullPath); | ||
} | ||
} | ||
|
||
HasSdkCodeStyleAnalyzers = containsSdkCodeStyleAnalyzers; | ||
} | ||
|
||
private OneOrMany<string> GetMappedAnalyzerPaths(string fullPath) | ||
|
@@ -1061,6 +1093,14 @@ private OneOrMany<string> GetMappedAnalyzerPaths(string fullPath) | |
_ => false, | ||
}; | ||
|
||
private void UpdateHasSdkCodeStyleAnalyzers() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used? |
||
{ | ||
var containsSdkCodeStyleAnalyzers = _unmappedProjectAnalyzerPaths.Any(IsSdkCodeStyleAnalyzer); | ||
if (containsSdkCodeStyleAnalyzers == HasSdkCodeStyleAnalyzers) | ||
return; | ||
HasSdkCodeStyleAnalyzers = containsSdkCodeStyleAnalyzers; | ||
} | ||
|
||
internal const string RazorVsixExtensionId = "Microsoft.VisualStudio.RazorExtension"; | ||
private static readonly string s_razorSourceGeneratorSdkDirectory = CreateDirectoryPathFragment("Sdks", "Microsoft.NET.Sdk.Razor", "source-generators"); | ||
private static readonly ImmutableArray<string> s_razorSourceGeneratorAssemblyNames = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explanation of what mapping of analyzer references means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this field name to
_sdkCodeStyleAnalyzerPaths
which I think is self explanatory.