dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

Remove special handling for DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis #37056

Open sharwell opened 5 years ago

sharwell commented 5 years ago

Related to #31758

This flag is used by analyzers to support a fast syntax-only analysis prior to full semantic analysis. It should be possible to replace this analyzer-specified behavior with automatic behavior in the driver:

We can extend this behavior to also support syntax node actions in no-semantics mode, a behavior not allowed by the current analyzer driver.

mavasani commented 5 years ago

I think this can be very easily achieved by the IDE diagnostic service invoking CompilationWithAnalyzers.GetAnalyzerSyntaxDiagnosticsAsync. I believe the current implementation takes the approach of filtering down the analyzers to those that specify DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis and invoking CompilationWithAnalyzers.GetAnalysisResult, which does not restrict the force completed actions. New implementation should not attempt to filter analyzers, but just invoke the above syntax-only API, so the core analyzer driver only force completes syntax tree actions.

Attempts to get or use the SemanticModel automatically cancel the execution of this analyzer's syntax tree actions for the syntax-only operations.

I don't think we need to do this. Analyzers registering syntax tree actions should not attempt to get semantic model, driver doesn't need to safeguard this.