Skip to content
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

Only provide fallback options for host analyzers #75317

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Oct 1, 2024

  • Separate analysis passes into "project" analyzers (aka NuGet-installed analyzers) and "solution" analyzers (aka host- or VSIX-installed analyzers)
  • Only provide fallback options from the host for host-installed analyzers

Items not covered by this pull request

  • Redirect Code Style analyzers to Features analyzers when loaded in Visual Studio. This is addressed separately by Do not load CodeStyle analyzers added by the SDK #75250.
  • Treat Features analyzers as project analyzers when they are being used in place of Code Style analyzers.
  • NuGet-installed code fixes and refactorings should not use host options, but currently they do. Only source generators and analyzers are corrected by this pull request.

Known issues introduced by this change

@sharwell sharwell requested review from a team as code owners October 1, 2024 13:38
@sharwell sharwell marked this pull request as draft October 1, 2024 13:38
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 1, 2024
Copy link
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

foreach (var reference in _project.Solution.AnalyzerReferences.Concat(_project.AnalyzerReferences))
using var _1 = ArrayBuilder<DiagnosticAnalyzer>.GetInstance(out var projectAnalyzerBuilder);
using var _2 = ArrayBuilder<DiagnosticAnalyzer>.GetInstance(out var hostAnalyzerBuilder);
foreach (var reference in _project.Solution.AnalyzerReferences)
{
Copy link
Member

@tmat tmat Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the loop can be factored to a local function and AppendAnalyzerMap can be inlined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ This is small enough that I'll leave it for now.

@arunchndr
Copy link
Member

What do we need before this can be published?

@sharwell sharwell marked this pull request as ready for review October 9, 2024 14:42
@@ -333,14 +360,84 @@ public AnalyzerConfigData GetAnalyzerOptionsForPath(string path, CancellationTok
}

internal sealed class ProjectAnalyzerConfigOptionsProvider(ProjectState projectState) : AnalyzerConfigOptionsProvider
{
private AnalyzerConfigOptionsCache.Value GetCache()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduplicate code in a follow up. E.g. use a common base class

Copy link
Member

@tmat tmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved assuming a clean-up will be done in a follow up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Needs API Review Needs to be reviewed by the API review council untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants