Refactor: extract generateModules helper to eliminate duplicate Generate pipeline in DUCasesGenerator and FieldsGenerator#257
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor duplicate code in FieldsGenerator and DUCasesGenerator
Refactor: extract Mar 11, 2026
generateModules helper to eliminate duplicate Generate pipeline in DUCasesGenerator and FieldsGenerator
23 tasks
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DUCasesGeneratorandFieldsGeneratorshared a structurally identical ~12-line pattern for parsing the AST, filtering types by attribute, and collecting generated modules — differing only in the extractor function and attribute type.Changes
GeneratorHelpers.fs— two new internal helpers:filterByAttribute<'A>: filters(LongIdent * SynTypeDefn list) listto namespaces containing at least one type with the given attributegenerateModules<'Attr>: full pipeline — parse AST → extract → filter → map toSynModuleOrNamespace→Output.AstDUCasesGenerator.fs/FieldsGenerator.fs—Generateimplementations collapsed to a single call:LensesGenerator.fs— intentionally unchanged; it processes both records and DUs in one pass and requires theSynAttributeinstance for wrapper name extraction, making it incompatible with the generic helper.Original prompt
This section details on the original issue you should resolve
<issue_title>Duplicate Code: Namespace-filtered Type Extraction Pattern in FieldsGenerator and DUCasesGenerator</issue_title>
<issue_description>Analysis of commit d8842b9
Assignee:
@copilotSummary
FieldsGenerator.fsandDUCasesGenerator.fsshare a structurally identical ~12-line pattern for extracting, filtering, and collecting type definitions from the parsed AST. The only differences are the attribute type and the extraction function used. This makes the pattern a strong candidate for a shared helper.Duplication Details
Pattern: Namespace-filtered type extraction + module collection
src/Myriad.Plugins/DUCasesGenerator.fs(lines 150–163)src/Myriad.Plugins/FieldsGenerator.fs(lines 166–181)DUCasesGenerator.fs:
FieldsGenerator.fs (structurally identical):
Impact Analysis
Refactoring Recommendations
Extract a shared helper in
Myriad.PluginsorMyriad.CoreextractAndFilter Ast.extractDU (Ast.hasAttribute(Generator.DuCasesAttribute)) astAlternative: Inline the collection step too
namespaceAndrecordsvariable +modulespipeline could be collapsed into one expression using the shared helper, reducing 12 lines to ~5 in each generator.Implementation Checklist
Analysis Metadata
Comments on the Issue (you are @copilot in this section)
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.