-
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
Add FixAll in containing type/member support for code fixes #59989
Conversation
Currently, one can apply FixAll operations to Document, Project and Solution scopes. Now, we also support fixing all diagnostics in containing member and type scopes, wherever applicable.
d65e480
to
a774ffc
Compare
src/Features/Core/Portable/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core/Shared/Extensions/TelemetryExtensions.cs
Outdated
Show resolved
Hide resolved
} | ||
else | ||
{ | ||
var diagnostics = ImmutableArray<Diagnostic>.Empty; |
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.
Use a builder?
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.
So, for 99% cases we expect a single FixAll span entry here. We get multiple FixAll spans within a document only for the case where a single named type has multiple partial definitions defined in the same file, which is almost never the case in real code bases. I don't think we need to optimize for this corner case.
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.
my general concern is simply that the builder approach is just as easy to write, and works well for the 1 to many case. I agree it's unlikely, but really rthe ImmutableArray.AddRange approach really stands out like a sort thumb as "this is just waiting for an unfortunate case. Note: sam's TemporaryArray is great here. just do:
using var diagnostics = TemporaryArray<Diagnostic>Empty;
As fast for the normal case (<4 items), and no pathlogical dropoff.
...paces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.SpanBasedDiagnosticProvider.cs
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAll/FixAllState.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAllContextHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAllContextHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAllContextHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAllContextHelper.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/FixAllContextHelper.cs
Outdated
Show resolved
Hide resolved
...es/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs
Outdated
Show resolved
Hide resolved
…e so TS/F# can also opt into ContainingType/Member scope for fix all.
...Workspace/Core/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs
Outdated
Show resolved
Hide resolved
...Workspace/Core/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs
Outdated
Show resolved
Hide resolved
...Workspace/Core/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs
Show resolved
Hide resolved
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.
done iwth pass. almost all nits. did see a concern with global statements.
…d using the internal overload instead
Thanks @CyrusNajmabadi - feedback addressed |
Currently, one can apply FixAll operations to Document, Project and Solution scopes. Now, we also support fixing all diagnostics in containing member and type scopes, wherever applicable.
Closes #60029
Screenshot
Note
ContainingType
scope fixes all diagnostics in all the partial definitions across files, not just the type declaration in current file from which the fix is triggered.ContainingMember
fix all option (for examplemake class static
code fix for CA1822).ContainingType
fix all option (for exampleremove unnecessary usings
code fix for IDE0005).Added Tests
FixAllScope.ContainingMember
andFixAllScope.ContainingType
in following buckets:FixAllScope.ContainingMember
andFixAllScope.ContainingType
.