fix(extraction): drop the extractVariables hook, which the core never called (#2809)

Root cause: LanguageExtractor in src/extraction/tree-sitter-types.ts declared
an optional extractVariables hook, documented together with the VariableInfo
type it returned, but nothing ever called it. Variables are named by the
core's own extractVariable, from its per-language branches and the
variableTypes list. A language author who wrote the hook got nothing back,
with no error and no warning; the reporter hit this while adding Nim.

Fix: remove the hook and VariableInfo. No language implemented the hook,
nothing else referred to either one, and the module is not part of the
public API. The variableTypes doc now says how the core finds the declared
names, and that a grammar which nests them deeper gets its own branch in
extractVariable, as the add-lang skill already says. Wiring the hook in was
the alternative, but nothing needs it, so it would be an API no language
exercises; the open Nim PR uses a core branch instead.

Validation:
- New __tests__/language-extractor-hooks.test.ts reads LanguageExtractor's
  members with the TypeScript parser and checks that the extraction core
  reads each one through an extractor receiver. On main it fails, listing
  extractVariables; with the fix both tests pass, and all 59 remaining
  members are read.
- The compiled JavaScript is byte-identical: of 1,164 dist files hashed, only
  tree-sitter-types.d.ts and its map changed.
- expressjs/express (0dee2c52, 214 files) indexed before and after, on the
  native-kernel and the wasm paths: the graph dumps are byte-identical
  (12,450 lines; 1,135 nodes, 2,258 edges).

Fixes #2465

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-10-22 17:23:05 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 9ed79c6cf1
commit 80c3680068
2 changed files with 103 additions and 24 deletions
+8 -24
View File
@@ -25,23 +25,6 @@ export interface ImportInfo {
handledRefs?: boolean;
}
/**
* Information about a single variable within a declaration.
* Returned by a language's extractVariables hook.
*/
export interface VariableInfo {
/** Variable name */
name: string;
/** Node kind: 'variable' or 'constant' */
kind: NodeKind;
/** Optional signature string */
signature?: string;
/** If set, this declarator is actually a function and should be extracted as such */
delegateToFunction?: SyntaxNode;
/** The AST node to use for positioning (may differ from the declaration node) */
positionNode?: SyntaxNode;
}
/**
* Context object passed to language hooks that need to call back into the core extractor.
* Provides a controlled API surface — hooks can create nodes, visit children, and add
@@ -137,7 +120,14 @@ export interface LanguageExtractor {
importTypes: string[];
/** Node types that represent function calls */
callTypes: string[];
/** Node types that represent variable declarations (const, let, var, etc.) */
/**
* Node types that represent variable declarations (const, let, var, etc.).
* By default the core names each declared variable from the node's direct
* `identifier` or `variable_declarator` children (`extractVariable` in
* tree-sitter.ts). A grammar that nests the names deeper, like Swift's
* `pattern` or Lua's `variable_list`, gets its own branch there; there is no
* per-language hook for it.
*/
variableTypes: string[];
/** Node types that represent class fields (extracted as 'field' kind inside class bodies) */
fieldTypes?: string[];
@@ -331,12 +321,6 @@ export interface LanguageExtractor {
*/
extractImport?: (node: SyntaxNode, source: string) => ImportInfo | null;
/**
* Extract variable declarations from a variable declaration node.
* Returns info about each declared variable, allowing the core to create nodes.
*/
extractVariables?: (node: SyntaxNode, source: string) => VariableInfo[];
/**
* Extract receiver/owner type name from a method declaration.
* Used by Go to get the struct receiver (e.g., "scrapeLoop" from "func (sl *scrapeLoop) run()").