Skip to content

Enforce MSGH007 for simple generators with parameters and finish SimpleMethodWithParameter test#82

Merged
dex3r merged 2 commits intobugfix/simple_method_with_parameterfrom
copilot/continue-simple-method-test
Mar 9, 2026
Merged

Enforce MSGH007 for simple generators with parameters and finish SimpleMethodWithParameter test#82
dex3r merged 2 commits intobugfix/simple_method_with_parameterfrom
copilot/continue-simple-method-test

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

Simple [GeneratesMethod] generators are compile-time executors and must not accept runtime parameters, but this path was not validated and the existing test was unfinished. This PR completes the test and adds a dedicated validation path that emits MSGH007 on the generator method signature (not method body).

  • Completed coverage for the unfinished scenario

    • Finalized SimpleMethodWithParameterTests_Test to assert:
      • MSGH007 is emitted.
      • Diagnostic location is in source.
      • Highlighted span includes method signature and excludes method body.
  • Added simple-pattern parameter validation in generation pipeline

    • In GeneratesMethodGenerationPipeline, for non-switch and non-fluent groups:
      • detect generator methods with one or more parameters,
      • emit CannotUseRuntimeParameterForCompileTimeGeneratorError (MSGH007),
      • stop generation for that invalid group.
  • Diagnostic location is now signature-scoped

    • Added signature span computation (method start -> end of parameter list) so errors target declaration signature rather than body content.
if (methodsWithParameters.Count > 0)
{
    foreach (GeneratesMethodGenerationTarget methodWithParameters in methodsWithParameters)
    {
        context.ReportDiagnostic(Diagnostic.Create(
            GeneratesMethodGeneratorDiagnostics.CannotUseRuntimeParameterForCompileTimeGeneratorError,
            GetMethodSignatureLocation(methodWithParameters.Syntax)));
    }

    return string.Empty;
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Continue working on SimpleMethodWithParameterTests_Test</issue_title>
<issue_description>1. Finish the test
2. Modify the generators so the test passes - generators should highlight the generator method signature (not body) and report analyzer error MSGH007</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot AI changed the title [WIP] Finish SimpleMethodWithParameterTests_Test and modify generators Enforce MSGH007 for simple generators with parameters and finish SimpleMethodWithParameter test Mar 7, 2026
Copilot finished work on behalf of dex3r March 7, 2026 13:39
@dex3r dex3r marked this pull request as ready for review March 9, 2026 19:06
Copilot AI review requested due to automatic review settings March 9, 2026 19:06
@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!

@dex3r dex3r merged commit 980470c into bugfix/simple_method_with_parameter Mar 9, 2026
4 checks passed
@dex3r dex3r deleted the copilot/continue-simple-method-test branch March 9, 2026 19:07
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

This PR enforces that “simple pattern” [GeneratesMethod] generators (compile-time executors) cannot declare runtime parameters, and completes the previously unfinished test case to validate both the diagnostic (MSGH007) and its source location span.

Changes:

  • Added a validation step in the simple-pattern generation path to emit MSGH007 when a generator method declares one or more parameters, and to skip generation for that invalid group.
  • Implemented signature-scoped diagnostic location computation (start of method declaration through the end of the parameter list).
  • Finished SimpleMethodWithParameterTests_Test to assert MSGH007 is emitted and that the highlighted span includes the signature but not the method body.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
EasySourceGenerators.Generators/GeneratesMethodGenerationPipeline.cs Adds simple-pattern parameter validation and signature-scoped diagnostic locations for MSGH007.
EasySourceGenerators.GeneratorTests/SimpleMethodWithParameter.cs Completes the test to verify MSGH007 emission and correct diagnostic span targeting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

dex3r added a commit that referenced this pull request Mar 9, 2026
* Added SimpleMethodWithParameterTest

* WIP

* Enforce MSGH007 for simple generators with parameters and finish SimpleMethodWithParameter 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>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dex3r <3155725+dex3r@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

None yet

Development

Successfully merging this pull request may close these issues.

3 participants