Skip to content

Refactor GeneratesMethodGenerator into a tiny orchestrator with focused helper components#14

Merged
dex3r merged 6 commits into
mainfrom
copilot/refactor-generates-method-generator
Feb 28, 2026
Merged

Refactor GeneratesMethodGenerator into a tiny orchestrator with focused helper components#14
dex3r merged 6 commits into
mainfrom
copilot/refactor-generates-method-generator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

  • Review new PR comments and identify actionable requests
  • Investigate latest CI/workflow status and failing logs
  • Apply null-safe PortableExecutableReference.FilePath handling in runtime resolver/lookups
  • Run targeted tests for generator changes
  • Run final code review and CodeQL scan
  • Report progress with commit and reply to addressed PR comments
Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor GeneratesMethodGenerator</issue_title>
<issue_description>Refactor GeneratesMethodGenerator:

  • split it nicely into small, testable classes
  • move diagnostic descriptions to a separate file (if that is ok, maybe they NEED to be there??)
  • replace var with actuall types
  • do other common refactoring task as you see fit
  • make code as self-documenting as possible, with good naming, avoid comments
  • make sure all tests still pass</issue_description>

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


✨ 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 2 commits February 27, 2026 19:05
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor GeneratesMethodGenerator for better structure and readability Refactor GeneratesMethodGenerator into focused components and centralize diagnostics Feb 27, 2026
@dex3r dex3r marked this pull request as ready for review February 27, 2026 19:39
Copilot AI review requested due to automatic review settings February 27, 2026 19:39
Copy link
Copy Markdown
Owner

@dex3r dex3r left a comment

Choose a reason for hiding this comment

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

That is a good start. Now, extract even more code out of GeneratesMethodGenerator, so it's very tiny. The helper classes and methods should be small and unit-testable.

Copy link
Copy Markdown
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

Refactors GeneratesMethodGenerator to improve structure by separating target collection/validation and centralizing diagnostic descriptors, while keeping the generation logic and outputs the same.

Changes:

  • Extracted [GeneratesMethod] discovery/validation into GeneratesMethodGenerationTargetCollector and introduced GeneratesMethodGenerationTarget as a typed transfer model.
  • Centralized diagnostic descriptors into GeneratesMethodGenerator.Diagnostics.cs and updated generator code to reference them.
  • Replaced var with explicit types in touched generator paths.

Reviewed changes

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

File Description
MattSourceGenHelpers.Generators/GeneratesMethodGenerator.cs Updated generator to consume collected targets, reference centralized diagnostics, and use explicit typing.
MattSourceGenHelpers.Generators/GeneratesMethodGenerator.Diagnostics.cs New centralized diagnostic descriptor definitions (MSGH001–MSGH004).
MattSourceGenHelpers.Generators/GeneratesMethodGenerationTargetCollector.cs New collector that discovers/validates generator methods and emits validation diagnostics.

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

Comment thread MattSourceGenHelpers.Generators/GeneratesMethodGenerator.cs Outdated
Comment thread MattSourceGenHelpers.Generators/GeneratesMethodGenerator.cs Outdated
Copilot AI and others added 2 commits February 27, 2026 19:44
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 27, 2026

That is a good start. Now, extract even more code out of GeneratesMethodGenerator, so it's very tiny. The helper classes and methods should be small and unit-testable.

Done in 681caa0 (with follow-up polish in e89e0c4). GeneratesMethodGenerator is now kept very small, with orchestration moved to GeneratesMethodGenerationPipeline and the remaining logic split into focused helper classes: GeneratesMethodPatternSourceBuilder and GeneratesMethodExecutionRuntime.

Copilot AI changed the title Refactor GeneratesMethodGenerator into focused components and centralize diagnostics Refactor GeneratesMethodGenerator into a tiny orchestrator with focused helper components Feb 27, 2026
@dex3r dex3r requested a review from Copilot February 28, 2026 08:47
Copy link
Copy Markdown
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


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

Comment on lines +52 to +58
PortableExecutableReference? match = compilation.References
.OfType<PortableExecutableReference>()
.FirstOrDefault(reference => string.Equals(
Path.GetFileNameWithoutExtension(reference.FilePath),
assemblyName.Name,
StringComparison.OrdinalIgnoreCase));
return match?.FilePath != null ? context.LoadFromAssemblyPath(match.FilePath) : null;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

PortableExecutableReference.FilePath is nullable, but the predicate calls Path.GetFileNameWithoutExtension(reference.FilePath) without a null check. This can throw (and also triggers nullable warnings) when the compilation contains in-memory references with FilePath == null. Consider filtering to reference.FilePath is not null before calling Path.* (and/or using a safe fallback).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 095d0c1 by guarding reference.FilePath is not null before calling Path.GetFileNameWithoutExtension in the resolver lookup.

Comment on lines +63 to +68
PortableExecutableReference? abstractionsReference = compilation.References
.OfType<PortableExecutableReference>()
.FirstOrDefault(reference => string.Equals(
Path.GetFileNameWithoutExtension(reference.FilePath),
"MattSourceGenHelpers.Abstractions",
StringComparison.OrdinalIgnoreCase));
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The lookup for the Abstractions reference assumes reference.FilePath is non-null (Path.GetFileNameWithoutExtension(reference.FilePath)). FilePath can be null for some metadata references, which would crash the generator. Add a null check in the predicate (or otherwise handle null paths) before calling Path.*.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 095d0c1 by adding a null-safe predicate for reference.FilePath in the Abstractions-reference lookup.

Comment on lines +150 to +153
.FirstOrDefault(reference => string.Equals(
Path.GetFileNameWithoutExtension(reference.FilePath),
assemblyName.Name,
StringComparison.OrdinalIgnoreCase));
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

Same nullable FilePath issue in the AssemblyLoadContext resolver: Path.GetFileNameWithoutExtension(reference.FilePath) can throw if FilePath is null. Guard with reference.FilePath is not null before using it.

Suggested change
.FirstOrDefault(reference => string.Equals(
Path.GetFileNameWithoutExtension(reference.FilePath),
assemblyName.Name,
StringComparison.OrdinalIgnoreCase));
.FirstOrDefault(reference =>
reference.FilePath is not null &&
string.Equals(
Path.GetFileNameWithoutExtension(reference.FilePath),
assemblyName.Name,
StringComparison.OrdinalIgnoreCase));

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 095d0c1 with the suggested null guard in the second AssemblyLoadContext resolver lookup.

@dex3r
Copy link
Copy Markdown
Owner

dex3r commented Feb 28, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: dex3r <3155725+dex3r@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 28, 2026

@copilot apply changes based on the comments in this thread

Applied in 095d0c1. I implemented the thread feedback by adding null guards for PortableExecutableReference.FilePath in all three metadata-reference lookups in GeneratesMethodExecutionRuntime to avoid null-path crashes with in-memory references.

@dex3r dex3r merged commit 1aa7794 into main Feb 28, 2026
1 check passed
@dex3r dex3r deleted the copilot/refactor-generates-method-generator branch February 28, 2026 12:20
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.

Refactor GeneratesMethodGenerator

3 participants