Conversation
…leMethodWithParameter test (#82) * Initial plan * Add MSGH007 validation for simple generators with parameters Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds a clearer diagnostic for the “simple pattern” [GeneratesMethod] generator case when the generator method has parameters (which can’t be provided at compile time), and validates the diagnostic location via a new unit test.
Changes:
- Introduce new error diagnostic
MSGH007for parameterized simple generator methods. - Report
MSGH007from the generation pipeline and highlight only the generator method signature. - Add
AnalyzerReleases.Unshipped.mdentry and a new generator test covering the scenario.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| EasySourceGenerators.Generators/GeneratesMethodGenerator.Diagnostics.cs | Adds MSGH007 diagnostic descriptor for parameterized simple generators. |
| EasySourceGenerators.Generators/GeneratesMethodGenerationPipeline.cs | Detects generator methods with parameters (in the simple pattern path) and reports MSGH007 with signature-only location. |
| EasySourceGenerators.Generators/AnalyzerReleases.Unshipped.md | Documents the new analyzer rule MSGH007. |
| EasySourceGenerators.GeneratorTests/SimpleMethodWithParameter.cs | Adds a test ensuring MSGH007 is emitted and highlights only the signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| internal static readonly DiagnosticDescriptor CannotUseRuntimeParameterForCompileTimeGeneratorError = new( | ||
| id: "MSGH007", | ||
| title: "Cannot use runtime parameter for compile-time generator", | ||
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use MethodTemplate if you want to emit method body instead of single value.", |
There was a problem hiding this comment.
Diagnostic MSGH007 message suggests using MethodTemplate, but there’s no MethodTemplate type/API in this repo (search only finds this string). This will mislead users; update the message to reference an existing alternative (e.g., the fluent pattern returning IMethodImplementationGenerator / Generate.Method() / MethodBuilder).
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use MethodTemplate if you want to emit method body instead of single value.", | |
| messageFormat: "Method generators cannot have any parameters, as they will be run at compile time to generate the method output value. Use the fluent method-generation API (e.g., Generate.Method() / MethodBuilder) if you want to emit a method body instead of a single value.", |
| MSGH005 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||
| MSGH006 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator No newline at end of file | ||
| MSGH006 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator | ||
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGeneratorDiagnostics No newline at end of file |
There was a problem hiding this comment.
AnalyzerReleases.Unshipped.md “Notes” column is inconsistent for MSGH007: other MSGH00x entries use GeneratesMethodGenerator, but MSGH007 uses GeneratesMethodGeneratorDiagnostics. If the convention is to list the analyzer/generator name, align MSGH007 with the existing entries for consistency.
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGeneratorDiagnostics | |
| MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator |
| public class SimpleMethodWithParameterTests | ||
| { | ||
| [Test] | ||
| public void SimpleMethodWithParameterTests_Test() |
There was a problem hiding this comment.
Test naming is inconsistent with the rest of the test suite (which uses descriptive names like GeneratesMethod_WithNonStaticMethod_EmitsMSGH002). Consider renaming SimpleMethodWithParameterTests_Test to describe the behavior under test (e.g., that a parameterized simple generator emits MSGH007 and highlights only the signature).
| public void SimpleMethodWithParameterTests_Test() | |
| public void GeneratesMethod_WithParameter_EmitsMSGH007AndHighlightsOnlySignature() |
No description provided.