Skip to content

fix: attach Go receiver methods to owner types#588

Open
msnandhis wants to merge 3 commits into
colbymchenry:mainfrom
msnandhis:fix/583-go-receiver-method-contains
Open

fix: attach Go receiver methods to owner types#588
msnandhis wants to merge 3 commits into
colbymchenry:mainfrom
msnandhis:fix/583-go-receiver-method-contains

Conversation

@msnandhis
Copy link
Copy Markdown
Contributor

Summary

Fixes #583.

This fixes two Go extraction/resolution gaps that left receiver methods orphaned from their owner type:

  • parses generic receiver declarations such as func (s *Stack[T]) Push(...), so the receiver type is recorded as Stack instead of being dropped
  • adds a post-extraction Go receiver owner pass that links Type::Method nodes to the matching type declared in the same package directory, even when the method is declared in a different file

The resolver also avoids cross-directory same-name matches, so a Widget type in another package directory does not accidentally receive methods from the current package.

Tests

  • npx -y -p node@22 -p npm@10 npm run test -- __tests__/extraction.test.ts -t 'Go Extraction'
  • npx -y -p node@22 -p npm@10 npm run test -- __tests__/resolution.test.ts -t 'links Go receiver methods'
  • npx -y -p node@22 -p npm@10 npm run test -- __tests__/extraction.test.ts __tests__/resolution.test.ts
  • npx -y -p node@22 -p npm@10 npm run build
  • npx -y -p node@22 -p npm@10 npx vitest run --maxWorkers=1 --minWorkers=1
  • git diff --check

Note: one initial fully parallel npm test run hit a timeout in the existing shared-daemon test. The same daemon test passed when rerun directly, and the full suite passed when run serially with Vitest worker limits.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90f1a56fe9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resolution/index.ts Outdated
if (methods.length === 0) return 0;

const ownersByName = new Map<string, Node[]>();
for (const kind of ['struct', 'class', 'enum', 'trait'] as const) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include Go type_alias owners when linking receiver methods

For valid Go defined types whose underlying type is not a struct/interface, e.g. type Status string with func (s Status) String() string in another file, the extractor creates the owner as a type_alias node, but this owner scan only considers struct/class/enum/trait. Those receiver methods therefore remain orphaned even though they are declared on a matching type in the same package; include Go type_alias nodes in the owner map so named non-struct types get the same contains edge.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff577f3fe5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/resolution/index.ts
});
}
}
updated += this.linkGoReceiverMethodOwners();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Run Go owner linking for indexFiles

When callers use CodeGraph.indexFiles() to index a selected set of Go files, this new owner-linking pass never runs because it is only wired through runPostExtract() (called by indexAll/sync, while src/index.ts:392-400 returns directly from orchestrator.indexFiles). In that context, receiver methods declared in a different indexed file from their type remain without the synthesized contains edge, so the fix behaves differently depending on which public indexing API was used.

Useful? React with 👍 / 👎.

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.

Go: receiver methods dropped from their type — generic receivers (*T[P]) and cross-file declarations lose the struct→method contains edge

1 participant