Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(core): retain receiver ownership in structural extraction
Lum11049270014b6244
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/cpp-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/cpp-extractor.test.tsindex 19d8242f..f8165a7b 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/cpp-extractor.test.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/cpp-extractor.test.ts@@ -31,6 +31,19 @@ function parse(code: string) {describe("CppExtractor", () => {const extractor = new CppExtractor();+ it("distinguishes free functions from inline and out-of-class methods", () => {+ const { tree, parser, root } = parse(`struct A { void run() {} };+void B::run() {}+void run() {}+`);+ expect(root.hasError).toBe(false);+ expect(extractor.extractStructure(root).functions.map(fn => [fn.name, fn.owner])).toEqual([+ ["run", "A"], ["run", "B"], ["run", ""],+ ]);+ tree.delete();+ parser.delete();+ });+it("has correct languageIds", () => {expect(extractor.languageIds).toEqual(["cpp", "c"]);});diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/go-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/go-extractor.test.tsindex 2cf1b772..2f518645 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/go-extractor.test.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/go-extractor.test.ts@@ -31,6 +31,23 @@ function parse(code: string) {describe("GoExtractor", () => {const extractor = new GoExtractor();+ it("preserves receiver ownership outside type declarations, including generic receivers", () => {+ const { tree, parser, root } = parse(`package p+type A[T any] struct{}+func (a *A[T]) Run() {}+func (b B) Run() {}+func Run() {}+`);+ expect(root.hasError).toBe(false);+ const result = extractor.extractStructure(root);+ expect(result.functions.map(fn => [fn.name, fn.owner])).toEqual([+ ["Run", "A"], ["Run", "B"], ["Run", ""],+ ]);+ expect(result.classes[0].methods).toEqual(["Run"]);+ tree.delete();+ parser.delete();+ });+it("has correct languageIds", () => {expect(extractor.languageIds).toEqual(["go"]);});diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/rust-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/rust-extractor.test.tsindex 06879602..707a72b4 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/rust-extractor.test.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/rust-extractor.test.ts@@ -31,6 +31,22 @@ function parse(code: string) {describe("RustExtractor", () => {const extractor = new RustExtractor();+ it("preserves impl ownership and leaves trait identity unresolved", () => {+ const { tree, parser, root } = parse(`struct A;+impl A { fn run(&self) {} }+impl B<u32> { fn run(&self) {} }+impl Trait for A { fn run(&self) {} }+fn run() {}+`);+ expect(root.hasError).toBe(false);+ const result = extractor.extractStructure(root);+ expect(result.functions.map(fn => [fn.name, fn.owner])).toEqual([+ ["run", "A"], ["run", "B<u32>"], ["run", null], ["run", ""],+ ]);+ tree.delete();+ parser.delete();+ });+it("has correct languageIds", () => {expect(extractor.languageIds).toEqual(["rust"]);});diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/cpp-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/cpp-extractor.tsindex 8523d6f2..bd41aefd 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/cpp-extractor.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/cpp-extractor.ts@@ -381,6 +381,7 @@ export class CppExtractor implements LanguageExtractor {const paramsNode = funcDecl.childForFieldName("parameters");functions.push({name: info.name,+ owner: className,lineRange: [member.startPosition.row + 1,member.endPosition.row + 1,@@ -446,6 +447,7 @@ export class CppExtractor implements LanguageExtractor {functions.push({name: info.name,+ owner: info.qualifier ?? "",lineRange: [node.startPosition.row + 1,node.endPosition.row + 1,diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/go-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/go-extractor.tsindex 53e3e95a..656621ee 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/go-extractor.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/go-extractor.ts@@ -50,17 +50,12 @@ function extractReceiverType(receiverNode: TreeSitterNode): string | undefined {const decl = findChild(receiverNode, "parameter_declaration");if (!decl) return undefined;- // Look for type_identifier directly or inside pointer_type- for (let i = 0; i < decl.childCount; i++) {- const child = decl.child(i);- if (!child) continue;- if (child.type === "type_identifier") {- return child.text;- }- if (child.type === "pointer_type") {- const typeId = findChild(child, "type_identifier");- if (typeId) return typeId.text;- }+ // Follow only the receiver's base type, never its generic type arguments.+ let type = decl.childForFieldName("type");+ if (type?.type === "pointer_type") type = type.namedChildren[0] ?? null;+ if (type?.type === "generic_type") type = type.childForFieldName("type");+ if (type?.type === "type_identifier") {+ return type.text;}return undefined;}@@ -197,6 +192,7 @@ export class GoExtractor implements LanguageExtractor {functions.push({name: nameNode.text,+ owner: "",lineRange: [node.startPosition.row + 1,node.endPosition.row + 1,@@ -225,9 +221,12 @@ export class GoExtractor implements LanguageExtractor {const paramsNode = node.childForFieldName("parameters");const params = extractParams(paramsNode ?? null);const returnType = extractResultType(node);+ const receiverNode = node.childForFieldName("receiver");+ const receiverType = receiverNode ? extractReceiverType(receiverNode) : undefined;functions.push({name: nameNode.text,+ owner: receiverType ?? null,lineRange: [node.startPosition.row + 1,node.endPosition.row + 1,@@ -237,15 +236,11 @@ export class GoExtractor implements LanguageExtractor {});// Track receiver type for struct association- const receiverNode = node.childForFieldName("receiver");- if (receiverNode) {- const receiverType = extractReceiverType(receiverNode);- if (receiverType) {- if (!methodsByReceiver.has(receiverType)) {- methodsByReceiver.set(receiverType, []);- }- methodsByReceiver.get(receiverType)!.push(nameNode.text);+ if (receiverType) {+ if (!methodsByReceiver.has(receiverType)) {+ methodsByReceiver.set(receiverType, []);}+ methodsByReceiver.get(receiverType)!.push(nameNode.text);}if (isExported(nameNode.text)) {diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/rust-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/rust-extractor.tsindex 98ab38ff..128f1a56 100644--- a/understand-anything-plugin/packages/core/src/plugins/extractors/rust-extractor.ts+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/rust-extractor.ts@@ -238,6 +238,7 @@ export class RustExtractor implements LanguageExtractor {functions.push({name: nameNode.text,+ owner: "",lineRange: [node.startPosition.row + 1,node.endPosition.row + 1,@@ -400,6 +401,9 @@ export class RustExtractor implements LanguageExtractor {functions.push({name: nameNode.text,+ // A trait impl needs trait identity as well as receiver identity.+ // Until that is modeled, do not equate it with an inherent method.+ owner: node.childForFieldName("trait") ? null : typeName,lineRange: [fn.startPosition.row + 1,fn.endPosition.row + 1,diff --git a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.tsindex c9986bab..07bcc80a 100644--- a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts+++ b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts@@ -278,6 +278,7 @@ export class TreeSitterPlugin implements AnalyzerPlugin {structure: StructuralAnalysis | null;leafTexts: string[];hasUnresolvedNames: boolean;+ language?: string;} {let tree: ReturnType<TreeSitterParser["parse"]> = null;try {@@ -318,6 +319,7 @@ export class TreeSitterPlugin implements AnalyzerPlugin {}return {status: "succeeded",+ language: langKey!,structure,leafTexts: [...leafTexts],hasUnresolvedNames,diff --git a/understand-anything-plugin/packages/core/src/types.ts b/understand-anything-plugin/packages/core/src/types.tsindex 28cadca0..e65aa2a1 100644--- a/understand-anything-plugin/packages/core/src/types.ts+++ b/understand-anything-plugin/packages/core/src/types.ts@@ -183,7 +183,15 @@ export interface ReferenceResolution {// Plugin interfacesexport interface StructuralAnalysis {- functions: Array<{ name: string; lineRange: [number, number]; params: string[]; returnType?: string }>;+ functions: Array<{+ name: string;+ lineRange: [number, number];+ params: string[];+ returnType?: string;+ /** Declaring type/scope; empty means free function, null means unresolved.+ * Omitted by extractors that only represent methods in classes[].methods. */+ owner?: string | null;+ }>;classes: Array<{ name: string; lineRange: [number, number]; methods: string[]; properties: string[] }>;imports: Array<{ source: string; specifiers: string[]; lineNumber: number }>;exports: Array<{ name: string; lineNumber: number; isDefault?: boolean }>;