-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Move the SyntaxTree and SemanticModel action based analyzers to respect context.FilterSpan #68014
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
Conversation
…ct context.FilterSpan Closes dotnet#67888 Follow-up to dotnet#67818
| { | ||
| var semanticModel = _compilation.GetSemanticModel(context.Tree); | ||
| var diagnostics = semanticModel.GetSyntaxDiagnostics(cancellationToken: context.CancellationToken); | ||
| var diagnostics = semanticModel.GetSyntaxDiagnostics(context.FilterSpan, context.CancellationToken); |
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.
This is the only compiler change in this PR
...arp/Analyzers/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
.../NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
.../NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
.../NewLines/ArrowExpressionClausePlacement/ArrowExpressionClausePlacementDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
.../NewLines/ConditionalExpressionPlacement/ConditionalExpressionPlacementDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
.../Analyzers/NewLines/ConsecutiveBracePlacement/ConsecutiveBracePlacementDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
...nalyzers/NewLines/EmbeddedStatementPlacement/EmbeddedStatementPlacementDiagnosticAnalyzer.cs
Show resolved
Hide resolved
...moveUnnecessaryNullableDirective/CSharpRemoveRedundantNullableDirectiveDiagnosticAnalyzer.cs
Outdated
Show resolved
Hide resolved
|
So conceptually, i'm 100% behind this. But hte pattern is so common, and so clunky, it would def benefit from some helpers/extensions. I also think it's worth discussing making the value non-nullable, and just having the span be the full file for the non-lightbulb case. Then the consumption side simplifies a ton. |
...orkspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/AnalysisContextExtensions.cs
Show resolved
Hide resolved
...orkspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/AnalysisContextExtensions.cs
Outdated
Show resolved
Hide resolved
...ensions/Compiler/Core/Helpers/RemoveUnnecessaryImports/AbstractUnnecessaryImportsProvider.cs
Outdated
Show resolved
Hide resolved
CyrusNajmabadi
left a comment
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.
LGTM. I'd like @sharwell's thoughts on if FilterSpan should be nullable or not. However, that's def not blocking, and this PR does implement the approved design, so that convo can happen in parallel.
I'm on the fence. I hear the point about the analyzer doing something different if the span is null or not. But that seems equiv to the analyzer doing something different if the span if the full-span of the compilation unit or not.
GIven that everyone who uses the span effectively does so to see what's in it, or do an intersection test, then null doesn't seem useful. But i'm ok either way :)
Closes #67888
Follow-up to #67818
Performance measurements
Summary
SyntaxTree analyzers: Decent performance improvements seen in this PR for the syntax analyzers. Note that majority of performance benefit was already fetched from Add FilterSpan API to analyzer contexts #67818, which moved our slowest syntax analyzer (IDE0055 - formatting analyzer) to respect
context.FilterSpanSemanticModel analyzers: Pretty significant performance improvements seen in this PR for the semantic model action analyzers. See screenshots below
Performance screenshots info:
SyntaxTree action analyzers
SemanticModel action analyzers
All analyzers (excluding SymbolStart analyzers)