Further work on Golang RPC, import manipulation, and formatting#7557
Merged
jkschneider merged 1 commit intomainfrom May 3, 2026
Merged
Further work on Golang RPC, import manipulation, and formatting#7557jkschneider merged 1 commit intomainfrom
jkschneider merged 1 commit intomainfrom
Conversation
Full RPC handler surface, recipe-author primitives, type attribution,
test harness, and recipe library brought to parity with the JavaScript,
Python, and C# language ports.
RPC handler surface
- Parse / ParseProject (project-aware: module + goModContent; per-file
closest-ancestor go.mod ownership; sibling go.sum populates
ResolvedDependencies).
- BatchVisit returns {modified, deleted, hasNewMessages, searchResultIds};
searchResultIds walker registered, hasNewMessages snapshot tracked.
- Generate drives ScanningRecipe.Generate.
- GetMarketplace emits full descriptor (recipeList, dataTables,
preconditions, maintainers, contributors, examples, option types).
- PrepareRecipe returns per-instance UUID.
- TraceGetObject for RPC tracing.
- Server CLI flags: --log-file, --trace-rpc-messages, --metrics-csv,
--recipe-install-dir, --data-tables-csv-dir.
Recipe-author surface
- recipe.Recipe + recipe.Base, ScanningRecipe end-to-end.
- recipe.DataTable[Row] generic + InMemoryDataTableStore +
CsvDataTableStore.
- visitor.GoVisitor.Cursor() / SetCursor() for RPC seeding;
visitor.BuildChain reconstructs cursors from RPC IDs.
- Cursor message map: PutMessage, GetNearestMessage,
PollNearestMessage, etc.
- recipe.Service[T](sourceFile) registry + GoVisitor.DoAfterVisit
composition.
- Five services: ImportService, AutoFormatService, AnnotationService,
WhitespaceValidationService, NamingService.
- Five foundational recipes: AddImport, RemoveImport,
RemoveUnusedImports, OrderImports, RenamePackage.
Type attribution
- Same-package multi-file resolution via parser.ParsePackage.
- Third-party module resolution via go.mod requires + vendor walker
(parses <projectRoot>/vendor/<modulePath>/*.go for real
JavaTypeMethod attribution; honors `replace` directives).
- tree.GoResolutionResult marker (Module, Requires, Replaces,
Excludes, Retracts, ResolvedDependencies); both Go-side and
Java-side RPC codecs.
- parser.ProjectImporter 3-tier lazy resolver
(sources -> requires -> stdlib).
- Build-tag file inclusion: parser.MatchBuildContext recognizes
//go:build, // +build, and filename suffixes; default
build.Default with recipe-author override.
- Cross-package generics across the corpus.
RPC sender / receiver visitor-pattern refactor
- Senders / receivers on both sides extend the language visitor
(visitor.GoVisitor on Go, JavaVisitor<RpcSendQueue/ReceiveQueue>
on Java) and override VisitX, mirroring rewrite-java.
- Eliminated ~600 LOC of switch boilerplate.
- tree.J got polymorphic GetID / GetPrefix / GetMarkers; mutators
intentionally NOT on the interface (would break RecipeScheduler
identity-based change detection).
Annotations
- tree.Annotation (J-shaped) + LeadingAnnotations on
VariableDeclarations, MethodDeclaration, TypeDecl on both Go and
Java sides.
- Struct field tags AND //go:/lint: directives uniformly modeled as
J.Annotation; printer reassembles backticks for tags and //<name>
lines for directives.
- AnnotationService surface mirrors rewrite-java
(AllAnnotations, IsAnnotatedWith, FindAnnotations,
AddAnnotationVisitor, RemoveAnnotationVisitor).
Test harness
- Java: Assertions.go(...), goMod(...), goProject(name, ...) sibling
pattern matching mavenProject(...).
- Go: test.RewriteRun + test.Golang(...), test.GoMod(...),
test.GoSum(...), test.GoProject(name, ...).
- propagateModuleResolution copies the parsed go.mod marker onto
every sibling .go CU at project expansion so cross-file recipes
read module context per file.
- ExpectType / ExpectPrimitiveType / ExpectMethodType helpers on
both sides.
- GoMod conformance corpus (10 cases) shared across Go + Java tests.
- Printer parity corpus (13 fixtures across gofmt/ + generics/),
opt-in via `make parity`, never in CI.
Recipe-author guide at doc/recipe-authoring.md.
PLAN.md removed: contents are now reflected in the codebase, doc, and
shipped tests.
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.
Summary
Brings
rewrite-goto parity with the JavaScript / Python / C# language ports across the RPC handler surface, recipe-author primitives, type attribution, test harness, and recipe library.RPC handler surface
Parse/ParseProject(project-aware:module+goModContent; per-file closest-ancestorgo.modownership; siblinggo.sumpopulatesResolvedDependencies).BatchVisitreturns{modified, deleted, hasNewMessages, searchResultIds};searchResultIdswalker registered,hasNewMessagessnapshot tracked.GeneratedrivesScanningRecipe.Generate.GetMarketplaceemits the full descriptor (recipeList,dataTables,preconditions,maintainers,contributors,examples, option types).PrepareRecipereturns per-instance UUID.TraceGetObjectfor RPC tracing.--log-file,--trace-rpc-messages,--metrics-csv,--recipe-install-dir,--data-tables-csv-dir.Recipe-author surface
recipe.Recipe+recipe.Base;ScanningRecipeend-to-end.recipe.DataTable[Row]generic +InMemoryDataTableStore+CsvDataTableStore.visitor.GoVisitor.Cursor()/SetCursor();visitor.BuildChainreconstructs cursors from RPC IDs.PutMessage,GetNearestMessage,PollNearestMessage, etc.recipe.Service[T](sourceFile)registry +GoVisitor.DoAfterVisitcomposition.ImportService,AutoFormatService,AnnotationService,WhitespaceValidationService,NamingService.AddImport,RemoveImport,RemoveUnusedImports,OrderImports,RenamePackage.Type attribution
parser.ParsePackage.go.modrequires + vendor walker (realJavaTypeMethodattribution; honorsreplacedirectives).tree.GoResolutionResultmarker (Module, Requires, Replaces, Excludes, Retracts, ResolvedDependencies); both Go-side and Java-side RPC codecs.parser.ProjectImporter3-tier lazy resolver (sources → requires → stdlib).parser.MatchBuildContextrecognizes//go:build,// +build, and filename suffixes.RPC sender / receiver visitor-pattern refactor
visitor.GoVisitoron Go,JavaVisitor<RpcSendQueue/ReceiveQueue>on Java) and overrideVisitX, mirroring rewrite-java.tree.Jgot polymorphicGetID/GetPrefix/GetMarkers; mutators intentionally NOT on the interface (would breakRecipeScheduleridentity-based change detection).Annotations
tree.Annotation(J-shaped) +LeadingAnnotationsonVariableDeclarations,MethodDeclaration,TypeDeclon both sides.//go:///lint:directives uniformly modeled asJ.Annotation.AnnotationServicesurface mirrors rewrite-java.Test harness
Assertions.go(...),goMod(...),goProject(name, ...)matchingmavenProject(...).test.RewriteRun+test.Golang(...),test.GoMod(...),test.GoSum(...),test.GoProject(name, ...).propagateModuleResolutioncopies the parsed go.mod marker onto every sibling.goCU at project expansion.ExpectType/ExpectPrimitiveType/ExpectMethodTypehelpers on both sides.gofmt/+generics/), opt-in viamake parity, never in CI.Documentation
doc/recipe-authoring.md.PLAN.mdremoved; contents now reflected in the codebase, doc, and shipped tests.Test plan
cd rewrite-go && go test ./...— full Go suite green../gradlew :rewrite-go:check :rewrite-go:integTest— Java unit + integ.cd rewrite-go && make parity— printer corpus byte-equality.recipes-gotest suite against the worktree replace path.