Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Description

Moves diagnostic generation from the LibraryImportGenerator source generator to a new LibraryImportDiagnosticsAnalyzer, per Roslyn team recommendation.

Changes:

  • Added LibraryImportDiagnosticsAnalyzer.cs with infrastructure to run diagnostic logic
    • Uses SymbolEqualityComparer to compare attribute types instead of string matching
    • Returns early when ProcessLibraryImportAttribute returns null (invalid compilation)
    • GetDiagnosticIfInvalidMethodForGeneration is internal static so the generator can call it directly
    • LibraryImportGeneratorOptions is created once per compilation in RegisterCompilationStartAction
  • Updated CSharpSourceGeneratorVerifier to accept a TAnalyzer type parameter for specifying which analyzer to run alongside a generator
    • Uses collection expression syntax for GetDiagnosticAnalyzers()
  • Removed diagnostic reporting from LibraryImportGenerator:
    • Removed all DiagnosticOr usage from the pipeline
    • Generator calls LibraryImportDiagnosticsAnalyzer.GetDiagnosticIfInvalidMethodForGeneration directly
    • Methods are filtered in a single Where clause that combines null check and validity check
  • Updated diagnostic tests to use CSharpAnalyzerVerifier instead of CSharpSourceGeneratorVerifier:
    • Tests now run only the analyzer without the generator
    • CSharpAnalyzerVerifier.Test ignores compiler diagnostics since partial methods won't have implementations without the generator
  • Updated other test files to use two type parameters:
    • LibraryImportGenerator tests use LibraryImportDiagnosticsAnalyzer
    • Other generators use EmptyDiagnosticAnalyzer from Microsoft.CodeAnalysis.Testing as a placeholder

Current 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., InvalidStringMarshallingConfiguration validation, some MarshalAs field validations).

Next steps (future PRs):

  • Complete analyzer to handle all diagnostic edge cases
  • Apply pattern to ComInterfaceGenerator, JSImportGenerator, JSExportGenerator, DownlevelLibraryImportGenerator

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 29, 2026 23:28
… 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
Copilot AI requested a review from jkoritzinsky January 29, 2026 23:53
jkoritzinsky

This comment was marked as outdated.

@jkoritzinsky jkoritzinsky dismissed their stale review January 30, 2026 00:15

Mis-clicked approve

@jkoritzinsky

This comment was marked as resolved.

Copy link
Member

@jkoritzinsky jkoritzinsky left a 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.

…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
Copilot AI requested a review from jkoritzinsky January 30, 2026 00:47
…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>
Copy link
Member

@jkoritzinsky jkoritzinsky left a 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.

…ion, simplify verifier, move options

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants