Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
feat: add Nix language support (#159)
Ansh Sonkusare885c8889f6a6
diff --git a/src/graph/generic.ts b/src/graph/generic.tsindex eee0b316..e8d7cbe5 100644--- a/src/graph/generic.ts+++ b/src/graph/generic.ts@@ -58,6 +58,7 @@ export const GENERIC_LANGS: readonly GenericLang[] = [{ name: "zig", exts: [".zig"], wasm: "zig" },{ name: "dart", exts: [".dart"], wasm: "dart" }, // surfaced by PR #38 (@muneebshere){ name: "clojure", exts: [".clj", ".cljs", ".cljc", ".bb"], wasm: "clojure" },+ { name: "nix", exts: [".nix"], wasm: "nix" },{ name: "lua", exts: [".lua"], wasm: "lua" },];diff --git a/src/graph/queries/nix.scm b/src/graph/queries/nix.scmnew file mode 100644index 00000000..e5e00961--- /dev/null+++ b/src/graph/queries/nix.scm@@ -0,0 +1,32 @@+; Nix tags — standard tree-sitter tags convention (@definition.<kind> + @name + @reference.call).+; Based on upstream tree-sitter-nix queries, extended for graft's breadth tier.+;+; Note: `binding` inside `let_expression` cannot have its children matched in+; tree-sitter queries (parse error), so let-bound variables are NOT captured as+; @definition. They are still searchable via the file node's residual body.++; Function definitions: `name = args: body` or `name = body` (where body is a function)+(binding+ (attrpath (identifier) @name)+ (function_expression) @definition.function)++; Inherit statements: `inherit (source) name1 name2`+(inherit+ (inherited_attrs (identifier) @name @definition.constant))++; Function calls: `function arg` or `function arg1 arg2` (nested apply_expression)+; Matches e.g. `import ./path` when `import` is applied to arguments.+(apply_expression+ function: (apply_expression+ function: (variable_expression+ name: (identifier) @name))) @reference.call++; Method/attribute calls: `builtins.map`, `pkgs.python3.withPackages`, etc.+(apply_expression+ function: (select_expression+ attrpath: (attrpath attr: (identifier) @name))) @reference.call++; Direct function application: `f arg`+(apply_expression+ function: (variable_expression+ name: (identifier) @name)) @reference.calldiff --git a/test/generic-extract.test.ts b/test/generic-extract.test.tsindex f259c4c2..556e822b 100644--- a/test/generic-extract.test.ts+++ b/test/generic-extract.test.ts@@ -115,6 +115,14 @@ const SNIPPETS: Array<{ lang: string; file: string; src: string; defs: string[];src: `local function helper()\n return 1\nend\n\nlocal assigned = function()\n return helper()\nend\n\nlocal handlers = { draw = function() return helper() end }\n\nfunction Widget:run()\n return helper()\nend\n\nlocal function launch()\n return Widget:run()\nend\n`,defs: ["function:assigned", "function:draw", "function:helper", "function:launch", "method:run"], call: ["launch", "run"],},+ {+ // Nix: a binding whose value is a lambda (let-bound or attrset field) becomes+ // a function def; a non-function binding (`version`) is not emitted, and an+ // application of one binding by another resolves as a call.+ lang: "nix", file: "a.nix",+ src: `let\n helper = x: x + 1;\nin {\n greet = name: helper 2;\n version = "1.0";\n}\n`,+ defs: ["function:greet", "function:helper"], call: ["greet", "helper"],+ },];for (const s of SNIPPETS) {