From 7e0d9b9ec0d1b839ae1f7861d973274964556330 Mon Sep 17 00:00:00 2001 From: TheSunn <49146439+TheKenS@users.noreply.github.com> Date: Wed, 27 May 2026 06:01:45 +0800 Subject: [PATCH] fix(extraction): extract type refs from TS interface property and method signatures (#432) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Types that appeared only in TypeScript interface members — property signatures like `value?: Partial` and method signatures like `fetchPage(arg: IPage): IOrderField` — were not being captured at extraction time, so the resolver never built `references` edges for them. `codegraph_impact`/`codegraph_callers` on the named type missed every consumer that imported it solely to use it in an interface shape. Add a `property_signature` / `method_signature` branch in `visitNode`: when inside a class-like node (which covers interfaces) and the language supports type annotations, call `extractTypeAnnotations` with the parent (interface) node ID as the edge source. No property/method node is created — only unresolved references that the resolver wires the same way it wires field and parameter type references elsewhere. --- CHANGELOG.md | 10 ++++++++++ __tests__/extraction.test.ts | 32 ++++++++++++++++++++++++++++++++ src/extraction/tree-sitter.ts | 16 ++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3f09c..50b4a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,6 +196,16 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). `docs/design/mixed-ios-and-react-native-bridging.md`. ### Fixed +- **TypeScript interface members now produce `references` edges to their + annotated types (#432).** Types that appeared only in an interface's + property or method signatures — e.g. `value?: Partial` or + `fetchPage(arg: IPage): IOrderField` — were being silently dropped at + extraction time, so `codegraph_impact`/`codegraph_callers` on the named + type missed every consumer that imported it just to use it in an + interface shape. The walker now extracts type annotations from both + `property_signature` and `method_signature` nodes inside class-like + parents (interfaces, classes), and the resolver wires the resulting + references the same way it wires field and parameter types elsewhere. - **Git worktrees no longer silently borrow another tree's index (#155).** When a worktree is nested inside the main checkout — exactly what agent tools that place worktrees under gitignored paths like diff --git a/__tests__/extraction.test.ts b/__tests__/extraction.test.ts index 92512e2..96b2686 100644 --- a/__tests__/extraction.test.ts +++ b/__tests__/extraction.test.ts @@ -205,6 +205,38 @@ export interface User { }); }); + it('should extract type references from interface property signatures', () => { + const code = ` +import type { IPage } from '../PromoterList'; +import type { IOrderField } from '../types'; + +interface Hprops { + value?: Partial & Partial; +} +`; + const result = extractFromSource('HeaderFilter.ts', code); + + const refs = result.unresolvedReferences.filter((r) => r.referenceKind === 'references'); + expect(refs.some((r) => r.referenceName === 'IPage')).toBe(true); + expect(refs.some((r) => r.referenceName === 'IOrderField')).toBe(true); + }); + + it('should extract type references from interface method signatures', () => { + const code = ` +import type { IPage } from '../PromoterList'; +import type { IOrderField } from '../types'; + +interface MethodForm { + fetchPage(arg: IPage): IOrderField; +} +`; + const result = extractFromSource('MethodForm.ts', code); + + const refs = result.unresolvedReferences.filter((r) => r.referenceKind === 'references'); + expect(refs.some((r) => r.referenceName === 'IPage')).toBe(true); + expect(refs.some((r) => r.referenceName === 'IOrderField')).toBe(true); + }); + it('should track function calls', () => { const code = ` function main() { diff --git a/src/extraction/tree-sitter.ts b/src/extraction/tree-sitter.ts index b8a149b..4e0a126 100644 --- a/src/extraction/tree-sitter.ts +++ b/src/extraction/tree-sitter.ts @@ -387,6 +387,22 @@ export class TreeSitterExtractor { else if (nodeType === 'impl_item') { this.extractRustImplItem(node); } + // TypeScript interface members: property_signature (`foo: T`, `foo?: T`) + // and method_signature (`foo(arg: A): R`) both carry type annotations the + // interface walker would otherwise drop. Extract them as `references` + // edges from the interface so resolvers can wire callers/impact for + // types that only appear in interface members. + else if ( + (nodeType === 'property_signature' || nodeType === 'method_signature') && + this.isInsideClassLikeNode() && + this.TYPE_ANNOTATION_LANGUAGES.has(this.language) + ) { + const parentId = this.nodeStack[this.nodeStack.length - 1]; + if (parentId) { + this.extractTypeAnnotations(node, parentId); + } + // don't skipChildren — nested signatures still need traversal + } // Visit children (unless the extract method already visited them) if (!skipChildren) {