Skip to content

Bugfix/simple method with parameter#83

Merged
dex3r merged 3 commits intomainfrom
bugfix/simple_method_with_parameter
Mar 9, 2026
Merged

Bugfix/simple method with parameter#83
dex3r merged 3 commits intomainfrom
bugfix/simple_method_with_parameter

Conversation

@dex3r
Copy link
Owner

@dex3r dex3r commented Mar 9, 2026

No description provided.

dex3r and others added 3 commits March 7, 2026 14:13
…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>
Copilot AI review requested due to automatic review settings March 9, 2026 19:08
@dex3r dex3r merged commit b3ae50d into main Mar 9, 2026
3 checks passed
@dex3r dex3r deleted the bugfix/simple_method_with_parameter branch March 9, 2026 19:09
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 MSGH007 for parameterized simple generator methods.
  • Report MSGH007 from the generation pipeline and highlight only the generator method signature.
  • Add AnalyzerReleases.Unshipped.md entry 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.",
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
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.",

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGeneratorDiagnostics
MSGH007 | GeneratesMethodGenerator | Error | GeneratesMethodGenerator

Copilot uses AI. Check for mistakes.
public class SimpleMethodWithParameterTests
{
[Test]
public void SimpleMethodWithParameterTests_Test()
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
public void SimpleMethodWithParameterTests_Test()
public void GeneratesMethod_WithParameter_EmitsMSGH007AndHighlightsOnlySignature()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants