From 56ccc14bcc9088ef6a88403c9ccdfcdbfcdfe94a Mon Sep 17 00:00:00 2001 From: Ryan Ayers Date: Wed, 22 Jul 2026 19:56:33 -0500 Subject: [PATCH] fix(code-def): surface method/constructor/field/struct definitions (#1628) DEF_TYPES listed only canonical symbol-type names (function, class, interface, ...). But normalizeSymbolType in the code chunker canonicalizes only some tree-sitter node types and lets the rest fall through type.replace(/_/g, ' '). So method_declaration is stored as 'method declaration', struct_specifier as 'struct specifier', protocol_declaration as 'protocol declaration'. None were in DEF_TYPES, so code-def returned 0 hits for every method, constructor, field, C struct, and Swift protocol. The plain 'struct' entry never matched either. Add the fallthrough definition forms. Read-path only; no reindex needed (0 -> N on existing indexes). Co-authored-by: Claude Opus 4.8 (1M context) Co-authored-by: Time Attakc <89218912+time-attack@users.noreply.github.com> --- src/commands/code-def.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/commands/code-def.ts b/src/commands/code-def.ts index 7cb3690a2..26573cae8 100644 --- a/src/commands/code-def.ts +++ b/src/commands/code-def.ts @@ -37,9 +37,19 @@ export async function findCodeDef( // trigger) are first-class definitions in the SQL sense. The chunker's // normalizeSymbolType maps create_table → 'table' etc, so adding the SQL // kinds here is what makes `gbrain code-def users` work against SQL. + // Method-level + member definitions. normalizeSymbolType only canonicalizes + // some node types; the rest fall through `type.replace(/_/g, ' ')`, so + // tree-sitter's method_declaration → 'method declaration', struct_specifier → + // 'struct specifier', protocol_declaration → 'protocol declaration', etc. + // Without these, code-def is blind to every method, constructor, field, C + // struct, and Swift protocol — which is most of an OO codebase. The plain + // 'struct' entry above never matched for the same reason (C emits the + // 'struct specifier' fallback form). const DEF_TYPES = [ 'function', 'class', 'interface', 'type', 'enum', 'struct', 'trait', 'module', 'contract', 'table', 'view', 'index', 'procedure', 'schema', 'database', 'trigger', + 'method declaration', 'method definition', 'constructor declaration', + 'field declaration', 'field definition', 'struct specifier', 'protocol declaration', ]; const params: unknown[] = [symbol, limit]; let whereLang = '';