-
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
XAML: Provide better support for AdditionalFiles analyzers #44131
Comments
cc @mavasani |
This comment has been minimized.
This comment has been minimized.
@sharwell I believe the request here is to support first class analysis callbacks for additional files, similar to source files. This will allow analyzers that analyze additional files to report diagnostics on opened additional files with the default analysis scope (Open documents). Additionally, it would be easier for third parties to write their own suggested actions (code fixes) for diagnostics in additional files. @mgoertz-msft Can you confirm if this correctly represents your feature request? |
@mavasani That makes sense, thanks! |
@mavasani Yes, that's exactly the purpose of this request so we can represent XAML documents in additional files and run analyzers on XAML documents. |
@mavasani Can you create an API proposal for review derived from the current syntax tree analysis APIs? |
@sharwell Sure, I will create and post an API proposal. We would need to have a design review with the compiler team before working on the implementation. |
ProposalDesignDesign API surface for additional file actions analogous to SyntaxTree actions:
public struct AdditionalFileAnalysisContext
{
public AdditionalText File { get; }
public AnalyzerOptions Options { get; }
public CancellationToken CancellationToken { get; }
public Compilation Compilation { get; }
public void ReportDiagnostic(Diagnostic diagnostic);
}
public void RegisterAdditionalFileAction(Action<AdditionalFileAnalysisContext> action); ImplementationIdentical analyzer action semantics to syntax tree action callbacks. From https://github.com/dotnet/roslyn/blob/master/docs/analyzers/Analyzer%20Actions%20Semantics.md:
Open questionShould we expose a similar API for analyzer config files? This will allow us to write analyzers for mistakes in editorconfig files, which show up on opening these files. For example, we can finally address #19055 if |
@sharwell @vatsalyaagrawal We can bring the above design proposal for discussion at the next IDE design meeting if we can have a member from compiler team present at the discussion. |
@mgoertz-msft can you confirm the above API would meet your request? |
@mavasani Looks like that should work. I wonder if instead of |
|
Addresses dotnet#44131 The added analyzer APIs are similar to the existing APIs for syntax tree callback. This commit adds the compiler APIs + tests Future enhancement: Add analyzer action for reporting diagnostics in analyzer config files
The API proposal was approved at the design meeting. |
Addresses dotnet#44131 The added analyzer APIs are similar to the existing APIs for syntax tree callback. This commit adds the compiler APIs + tests Future enhancement: Add analyzer action for reporting diagnostics in analyzer config files
@mgoertz-msft FYI that your original feature request has now been implemented for 16.8 P1 with #45076. I will keep this issue open to track exposing a similar API for analyzer config files. |
Closes dotnet#44131 dotnet#45076 added support for reporting analyzer diagnostics in additional files. This PR addresses pending work from dotnet#44131 (comment) by adding similar support for editorconfig/globalconfig files in the project. There are two primary public API additions
Closes dotnet#44131 Primary public API additions: 1. Expose `AnalyzerConfigFiles` as text files from `AnayzerOptions`. Currently, we only expose `AdditionalFiles` from `AnalyzerOptions`. 2. Add `RegisterAnalyzerConfigFileAction` to `AnalysisContext` and `CompilationStartAnalysisContext` to report diagnostics in editorconfig files. `AnalyzerConfigFileAnalysisContext` is the new context type for this callback. 3. Expose `AnalyzerConfigFileDiagnostics` from `AnalysisResult` for analyzer hosts to fetch analyzer diagnostics reported in editorconfig files
Now tracked with #64213 |
Problem
Currently the only way to create analyzers for additional files is via RegisterCompilationStartAction for example and accessing them via AnalyzerOptions.AdditionalFiles. Unfortunately this means that there is no way for analyzer optimizations, such as running only for a currently open additional document for example. This places the burden of any potential optimizations on each analyzer implementation and could result in performance problems.
Justification
With the internal DocumentDiagnosticAnalyzers being frowned upon and eventually going away an official replacement solution for additional files is needed to support analyzers for non-core Roslyn languages such as XAML.
Ask
Provide support for something like an AdditionalDocumentDiagnosticAnalyzer for example that can be optimized for additional files scenarios.
The text was updated successfully, but these errors were encountered: