Skip to content

Add api to allow customizing options per DiagnosticAnalyzer#80200

Merged
CyrusNajmabadi merged 90 commits intodotnet:mainfrom
CyrusNajmabadi:compilationOptionsApi
Sep 12, 2025
Merged

Add api to allow customizing options per DiagnosticAnalyzer#80200
CyrusNajmabadi merged 90 commits intodotnet:mainfrom
CyrusNajmabadi:compilationOptionsApi

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Sep 9, 2025

API approved in #80143

@@ -31,9 +31,9 @@ internal partial class AnalyzerExecutor
internal const string AnalyzerExceptionDiagnosticId = "AD0001";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The meat of hte change is in this file.

// can use the same instance across all actions.
var context = new SemanticModelAnalysisContext(
semanticModel, AnalyzerOptions, diagReporter.AddDiagnosticAction,
semanticModel, options, diagReporter.AddDiagnosticAction,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
semanticModel, options, diagReporter.AddDiagnosticAction,
semanticModel, analyzerOptions, diagReporter.AddDiagnosticAction,

@CyrusNajmabadi
Copy link
Contributor Author

Ok. Performance seems unchanged:

| Method                      | Job        | InvocationCount | UnrollFactor | Mean    | Error    | StdDev   | Median  | Min     | Max     | Gen0        | Gen1       | Gen2      | Allocated  |
| GetDiagnosticsWithAnalyzers | Job-YBTWXS | 1               | 1            | 5.634 s | 0.0562 s | 0.0751 s | 5.649 s | 5.484 s | 5.756 s | 181000.0000 | 61000.0000 | 1000.0000 | 1440.27 MB |
| GetDiagnosticsWithAnalyzers | Job-IGTETM | 1               | 1            | 5.640 s | 0.0537 s | 0.0527 s | 5.642 s | 5.556 s | 5.760 s | 183000.0000 | 64000.0000 | 2000.0000 | 1446.7 MB |

@CyrusNajmabadi
Copy link
Contributor Author

@dotnet/roslyn-compiler for eyes. Tnx :)

@CyrusNajmabadi
Copy link
Contributor Author

@dotnet/roslyn-compiler for reviews :)

@CyrusNajmabadi
Copy link
Contributor Author

@dotnet/roslyn-compiler @jjonescz @jcouv ptal :)


// Deduping map for the distinct AnalyzerConfigOptionsProvider we get back from getAnalyzerConfigOptionsProvider.
// The common case in VS host is that there is generally only 1-2 of these providers. For example, a provider
// that looks in editorconfig+vsoptions, and a provider that only looks in editorconfig. We only want to make
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR: I'm planning to enable analyzer redirecting in dev18 which would redirect built-in SDK analyzers to ones inserted in VS (to avoid compiler version mismatch). I'm not sure if that is going to break the logic of analyzer option loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pinging you offline :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked offline. We're good. The redirection tthat is done doesn't affect the status of these references as 'project references'. It just impacts the location they are loaded from. So we will still see these as project-level references, and will appropriately hookup the right non-fallback options.

@CyrusNajmabadi
Copy link
Contributor Author

@dotnet/roslyn-compiler for final set of eyes.

@CyrusNajmabadi CyrusNajmabadi merged commit 906c266 into dotnet:main Sep 12, 2025
28 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the compilationOptionsApi branch September 12, 2025 21:28
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 12, 2025
@akhera99 akhera99 modified the milestones: Next, 18.0 P1, 18.0 P2 Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs API Review Needs to be reviewed by the API review council

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants