-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Move diagnostic generation from LibraryImportGenerator to LibraryImportDiagnosticsAnalyzer #123780
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
Draft
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/move-diagnostic-generation-to-analyzers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+369
−119
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… diagnostics Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
…itional analyzer loading Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
…till reports diagnostics) Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Move diagnostic generation to analyzers alongside generators
Add LibraryImportDiagnosticsAnalyzer foundation for diagnostic migration
Jan 29, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Member
jkoritzinsky
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.
@copilot address this review.
...ime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
Show resolved
Hide resolved
...ime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
Outdated
Show resolved
Hide resolved
...raries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticOr.cs
Outdated
Show resolved
Hide resolved
...aries/System.Runtime.InteropServices/tests/Common/Verifiers/CSharpSourceGeneratorVerifier.cs
Show resolved
Hide resolved
…per review feedback Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot
AI
changed the title
Add LibraryImportDiagnosticsAnalyzer foundation for diagnostic migration
Move diagnostic generation from LibraryImportGenerator to LibraryImportDiagnosticsAnalyzer
Jan 30, 2026
...ibraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs
Outdated
Show resolved
Hide resolved
...braries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Diagnostics.cs
Show resolved
Hide resolved
…null, remove helper method Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
…analyzer only Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
This was referenced Jan 30, 2026
Open
Member
jkoritzinsky
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.
@copilot please address the feedback in this review.
...ime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/Common/Verifiers/CSharpAnalyzerVerifier.cs
Outdated
Show resolved
Hide resolved
...aries/System.Runtime.InteropServices/tests/Common/Verifiers/CSharpSourceGeneratorVerifier.cs
Outdated
Show resolved
Hide resolved
...ibraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs
Outdated
Show resolved
Hide resolved
...ime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
Outdated
Show resolved
Hide resolved
…ion, simplify verifier, move options Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
This was referenced Jan 30, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Moves diagnostic generation from the
LibraryImportGeneratorsource generator to a newLibraryImportDiagnosticsAnalyzer, per Roslyn team recommendation.Changes:
LibraryImportDiagnosticsAnalyzer.cswith infrastructure to run diagnostic logicSymbolEqualityComparerto compare attribute types instead of string matchingProcessLibraryImportAttributereturns null (invalid compilation)GetDiagnosticIfInvalidMethodForGenerationisinternal staticso the generator can call it directlyLibraryImportGeneratorOptionsis created once per compilation inRegisterCompilationStartActionCSharpSourceGeneratorVerifierto accept aTAnalyzertype parameter for specifying which analyzer to run alongside a generatorGetDiagnosticAnalyzers()LibraryImportGenerator:DiagnosticOrusage from the pipelineLibraryImportDiagnosticsAnalyzer.GetDiagnosticIfInvalidMethodForGenerationdirectlyWhereclause that combines null check and validity checkCSharpAnalyzerVerifierinstead ofCSharpSourceGeneratorVerifier:CSharpAnalyzerVerifier.Testignores compiler diagnostics since partial methods won't have implementations without the generatorLibraryImportDiagnosticsAnalyzerEmptyDiagnosticAnalyzerfrom Microsoft.CodeAnalysis.Testing as a placeholderCurrent state: 672/703 tests pass (95%). The analyzer reports most diagnostics but doesn't yet handle all edge cases that the generator previously handled (e.g.,
InvalidStringMarshallingConfigurationvalidation, some MarshalAs field validations).Next steps (future PRs):
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.