Problem Statement
Currently, validation and diagnostic reporting for Lambda.Host only occurs during the build phase through the source generator in Lambda.Host.SourceGenerators. This means developers don't get real-time feedback in their IDE about issues like:
- Multiple method call violations (LH0001)
- Multiple parameters of the same type (LH0002)
This delayed feedback slows down development and makes it harder to catch errors early.
Proposed Solution
Create a dedicated Roslyn analyzer project (Lambda.Host.Analyzers) that provides real-time diagnostics directly in the IDE. This will give developers immediate visual feedback (squiggly lines, warnings, errors) as they type, before they even build the project.
Technical Approach
-
Create new project: Lambda.Host.Analyzers.csproj
- Target
netstandard2.0 (same as source generators)
- Reference
Microsoft.CodeAnalysis.CSharp (version 4.14.0 to match existing)
- Set
EnforceExtendedAnalyzerRules and IsRoslynComponent properties
-
Extract validation logic from Lambda.Host.SourceGenerators:
- Reuse existing
DiagnosticDescriptor definitions from Diagnostics.cs
- Port validation logic into analyzer-specific diagnostic analyzers
- May need slight adjustments to work in the analyzer context vs. source generator context
-
Implement Roslyn diagnostic analyzers:
- Create syntax/semantic analyzers that detect problematic patterns
- Report diagnostics using the same IDs (LH0001, LH0002, etc.)
- Follow .NET analyzer best practices
-
Package and distribute:
- Configure as analyzer in
.csproj with <IncludeBuildOutput>false</IncludeBuildOutput>
- Ensure it's included in the
Lambda.Host NuGet package
Acceptance Criteria
Technical Notes
- Most of the validation logic can be borrowed from the existing source generator
- Some adjustments may be needed since analyzers operate on syntax/semantic model differently than source generators
- Consider using incremental analyzers for better performance
- Follow Roslyn analyzer guidelines: https://github.com/dotnet/roslyn-analyzers
Related Files
src/Lambda.Host.SourceGenerators/Diagnostics.cs - Existing diagnostic definitions
src/Lambda.Host.SourceGenerators/MapHandlerSourceOutput.cs - Contains validation logic to extract
Problem Statement
Currently, validation and diagnostic reporting for Lambda.Host only occurs during the build phase through the source generator in
Lambda.Host.SourceGenerators. This means developers don't get real-time feedback in their IDE about issues like:This delayed feedback slows down development and makes it harder to catch errors early.
Proposed Solution
Create a dedicated Roslyn analyzer project (
Lambda.Host.Analyzers) that provides real-time diagnostics directly in the IDE. This will give developers immediate visual feedback (squiggly lines, warnings, errors) as they type, before they even build the project.Technical Approach
Create new project:
Lambda.Host.Analyzers.csprojnetstandard2.0(same as source generators)Microsoft.CodeAnalysis.CSharp(version 4.14.0 to match existing)EnforceExtendedAnalyzerRulesandIsRoslynComponentpropertiesExtract validation logic from
Lambda.Host.SourceGenerators:DiagnosticDescriptordefinitions fromDiagnostics.csImplement Roslyn diagnostic analyzers:
Package and distribute:
.csprojwith<IncludeBuildOutput>false</IncludeBuildOutput>Lambda.HostNuGet packageAcceptance Criteria
Lambda.Host.Analyzersproject created with proper configurationTechnical Notes
Related Files
src/Lambda.Host.SourceGenerators/Diagnostics.cs- Existing diagnostic definitionssrc/Lambda.Host.SourceGenerators/MapHandlerSourceOutput.cs- Contains validation logic to extract