Skip to content

smart-explore: Add C/C++ language support and fix Windows tree-sitter CLI resolution #2617

@4ImL3sSb0T

Description

@4ImL3sSb0T

Problem

smart_outline, smart_search, and smart_unfold fail for C (.c, .h) and C++ (.cpp, .cc, .cxx, .hpp) files with:

Could not parse . File may use an unsupported language or be empty.

Root Causes

Three issues were identified and fixed locally:

1. Missing C/C++ query patterns in Fu object

The Fu object in mcp-server.cjs has no c or cpp entries. C files fall back to the generic query, which uses function_declaration — a node type that doesn't exist in the C tree-sitter grammar. The query compilation fails silently, returning 0 symbols.

Fix: Add c and cpp query entries to Fu:

// C query
c: `
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @func
(struct_specifier name: (type_identifier) @name) @struct_def
(type_definition declarator: (type_identifier) @name) @tdef
(enum_specifier name: (type_identifier) @name) @enm
(preproc_include path: (_) @name) @imp
`

// C++ query (adds qualified_identifier and namespace_definition)
cpp: `
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @func
(function_definition declarator: (function_declarator declarator: (qualified_identifier name: (identifier) @name))) @func
(class_specifier name: (type_identifier) @name) @cls
(struct_specifier name: (type_identifier) @name) @struct_def
(namespace_definition name: (identifier) @name) @cls
(type_definition declarator: (type_identifier) @name) @tdef
(enum_specifier name: (type_identifier) @name) @enm
(preproc_include path: (_) @name) @imp
`

And update AS() to map "c""c" and "cpp""cpp" instead of falling through to "generic".

2. OS() function can't find tree-sitter.exe on Windows

The OS() function checks for the tree-sitter binary with existsSync(path), but on Windows the binary is tree-sitter.exe. Since existsSync("tree-sitter") returns false, it falls back to "tree-sitter" which isn't on PATH, causing execFileSync to fail silently.

Fix: Add Windows .exe check:

function OS() {
  if (zr) return zr;
  try {
    let t = Hi.resolve("tree-sitter-cli/package.json");
    let e = B.join(B.dirname(t), "tree-sitter");
    if (ee.existsSync(e)) return zr = e, e;
    // Fix: check for .exe on Windows
    if (process.platform === "win32") {
      let n = e + ".exe";
      if (ee.existsSync(n)) return zr = n, n;
    }
  } catch {}
  return zr = "tree-sitter", zr;
}

3. tree-sitter native binding missing for Windows + Node 22

The tree-sitter npm package has no prebuilt binary for win32-x64 with Node.js ABI 127. Requires manual npm rebuild tree-sitter after installing VS Build Tools.

Environment

  • OS: Windows 11
  • Node.js: v22.20.0
  • claude-mem: 12.4.9
  • Claude Code plugin system

Workaround

Applied all three fixes locally to both ~/.claude/plugins/cache/thedotmack/claude-mem/12.4.9/scripts/mcp-server.cjs and ~/.claude/plugins/marketplaces/thedotmack/plugin/scripts/mcp-server.cjs. All three smart-explore tools now work correctly for C and C++ files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions