From 99ccba93b3f257651d054cad72628848117dea9d Mon Sep 17 00:00:00 2001 From: sunerpy Date: Wed, 15 Jul 2026 04:09:40 +0800 Subject: [PATCH] feat(extraction): index Nix (.nix) at the extraction tier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ports the extraction half of upstream colby Nix support (#1190). `.nix` files now index their bindings (let/attrset/top level), lambda functions with a curried parameter signature, `inherit` names, function-application call edges, and static `import ./path` / `callPackage ./path` imports, via the tree-sitter-nix crates.io grammar (no vendored grammar). Nix is expression-based, not declaration-based: there are no class/struct/ method/enum node kinds and a call is `apply_expression`, not `call_expression`. So NIX_SPEC carries empty type-sets and a single Nix-guarded `visit_nix_node` walker arm (the same pattern GDScript uses) owns binding→symbol, lambda→ function, apply→call/import, and inherit-name extraction. The arm is gated to Language::Nix and shape-guarded, so no other language's extraction changes. Adds the Language::Nix variant, the `.nix` extension mapping, the store language-parser arm, and a dedicated nix golden fixture. The module-system option-path synthesizer, the callback synthesizer, the lexical-scope resolution gates, and the import-resolver module-list wiring from the upstream commit are deferred: this port has none of those subsystems, and they are the same non-Godot framework-resolution machinery it already leaves out. Nix joins at the extraction tier like the other Tier-1 languages. The language enum is a stored TEXT value, not DDL, so the golden .schema is unchanged and the eight existing golden fixtures are byte-identical (no regen); only the new nix fixture is added. --- Cargo.lock | 31 +- README.md | 6 +- crates/codegraph-bench/fixtures/nix/bar.nix | 5 + .../codegraph-bench/fixtures/nix/default.nix | 19 + crates/codegraph-bench/fixtures/nix/foo.nix | 8 + crates/codegraph-bench/tests/equivalence.rs | 31 ++ crates/codegraph-core/src/types.rs | 9 +- crates/codegraph-extract/Cargo.toml | 1 + crates/codegraph-extract/src/engine.rs | 8 +- crates/codegraph-extract/src/lang/mod.rs | 8 + crates/codegraph-extract/src/lang/nix.rs | 385 ++++++++++++++ crates/codegraph-extract/src/walker.rs | 286 +++++++++++ crates/codegraph-store/src/queries.rs | 6 + docs/equivalence.md | 48 ++ docs/languages.md | 5 +- reference/golden/nix/colby.db | Bin 0 -> 151552 bytes reference/golden/nix/edges.json | 221 ++++++++ reference/golden/nix/files.json | 26 + reference/golden/nix/nodes.json | 486 ++++++++++++++++++ reference/golden/nix/refs.json | 32 ++ reference/golden/nix/schema.sql | 117 +++++ 21 files changed, 1720 insertions(+), 18 deletions(-) create mode 100644 crates/codegraph-bench/fixtures/nix/bar.nix create mode 100644 crates/codegraph-bench/fixtures/nix/default.nix create mode 100644 crates/codegraph-bench/fixtures/nix/foo.nix create mode 100644 crates/codegraph-extract/src/lang/nix.rs create mode 100644 reference/golden/nix/colby.db create mode 100644 reference/golden/nix/edges.json create mode 100644 reference/golden/nix/files.json create mode 100644 reference/golden/nix/nodes.json create mode 100644 reference/golden/nix/refs.json create mode 100644 reference/golden/nix/schema.sql diff --git a/Cargo.lock b/Cargo.lock index 1b513b09..6c80e93f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,7 +432,7 @@ dependencies = [ [[package]] name = "codegraph-bench" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "clap", @@ -447,7 +447,7 @@ dependencies = [ [[package]] name = "codegraph-core" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "serde", @@ -463,7 +463,7 @@ dependencies = [ [[package]] name = "codegraph-daemon" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -483,7 +483,7 @@ dependencies = [ [[package]] name = "codegraph-extract" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -509,6 +509,7 @@ dependencies = [ "tree-sitter-kotlin-ng", "tree-sitter-lua", "tree-sitter-luau", + "tree-sitter-nix", "tree-sitter-objc", "tree-sitter-pascal", "tree-sitter-php", @@ -527,7 +528,7 @@ dependencies = [ [[package]] name = "codegraph-graph" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -541,7 +542,7 @@ dependencies = [ [[package]] name = "codegraph-mcp" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "axum", @@ -564,7 +565,7 @@ dependencies = [ [[package]] name = "codegraph-resolve" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -578,7 +579,7 @@ dependencies = [ [[package]] name = "codegraph-rs" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "assert_cmd", @@ -614,7 +615,7 @@ dependencies = [ [[package]] name = "codegraph-store" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -626,7 +627,7 @@ dependencies = [ [[package]] name = "codegraph-watch" -version = "0.34.0" +version = "0.35.0" dependencies = [ "anyhow", "codegraph-core", @@ -3579,6 +3580,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-nix" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4952a9733f3a98f6683a0ccd1035d84ab7a52f7e84eeed58548d86765ad92de3" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-objc" version = "3.0.2" diff --git a/README.md b/README.md index 170b1bed..e9c28782 100644 --- a/README.md +++ b/README.md @@ -439,7 +439,7 @@ Omit `--install` to print to stdout. Full per-shell install paths and notes: ## What CodeGraph Does (and Doesn't) -**Does:** deterministic code-structure extraction across 34 languages (TypeScript, +**Does:** deterministic code-structure extraction across 35 languages (TypeScript, Python, Go, Rust, Java, C/C++, C#, Vue, Svelte, GDScript, and more — see [`docs/languages.md`](docs/languages.md)), cross-file resolution (including Godot project graphs), graph traversal, FTS5 search, whole-graph export with @@ -454,9 +454,9 @@ beyond the fixed `LANGUAGES` set. ## Supported Languages -CodeGraph supports **34 languages** grouped by extraction depth. Quick overview: +CodeGraph supports **35 languages** grouped by extraction depth. Quick overview: -- **Tier 1 — Full symbol extraction (25):** TypeScript, TSX, JavaScript, JSX, ArkTS, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Scala, Lua, Luau, Objective-C, R, Solidity, GDScript, Pascal. +- **Tier 1 — Full symbol extraction (26):** TypeScript, TSX, JavaScript, JSX, ArkTS, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Scala, Lua, Luau, Objective-C, R, Solidity, Nix, GDScript, Pascal. - **Tier 2 — Embedded / template extraction (6):** Vue, Svelte, Astro, Razor/`.cshtml`, Liquid, XML/MyBatis mapper. - **Tier 3 — File-level only (3):** YAML, Twig, Properties. diff --git a/crates/codegraph-bench/fixtures/nix/bar.nix b/crates/codegraph-bench/fixtures/nix/bar.nix new file mode 100644 index 00000000..c792dd28 --- /dev/null +++ b/crates/codegraph-bench/fixtures/nix/bar.nix @@ -0,0 +1,5 @@ +{ stdenv }: +stdenv.mkDerivation { + pname = "bar"; + version = "1.0"; +} diff --git a/crates/codegraph-bench/fixtures/nix/default.nix b/crates/codegraph-bench/fixtures/nix/default.nix new file mode 100644 index 00000000..76ac8e3c --- /dev/null +++ b/crates/codegraph-bench/fixtures/nix/default.nix @@ -0,0 +1,19 @@ +{ pkgs, lib }: +let + helper = import ./foo.nix; + pkg = pkgs.callPackage ./bar.nix { }; + greeting = "hello"; +in +{ + inherit lib; + + imports = [ ./foo.nix ./bar.nix ]; + + build = { src }: pkgs.mkDerivation { + name = "demo"; + inherit src; + }; + + value = helper; + named = greeting; +} diff --git a/crates/codegraph-bench/fixtures/nix/foo.nix b/crates/codegraph-bench/fixtures/nix/foo.nix new file mode 100644 index 00000000..69bb4082 --- /dev/null +++ b/crates/codegraph-bench/fixtures/nix/foo.nix @@ -0,0 +1,8 @@ +{ lib }: +let + answer = 42; +in +{ + double = x: x * 2; + const = answer; +} diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index af8b299d..0c93da1f 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -156,6 +156,29 @@ fn solidity_db_is_self_equivalent_to_solidity_golden() { assert_equivalent(&solidity_db(), &solidity_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_nix_fixture() { + // Guards Nix extraction (upstream #1190, extraction slice only): the + // `.nix`->Nix mapping, `binding`->Function|Variable, curried lambda->Function + // with a formatted signature, `inherit`->Variable names, `import`/ + // `callPackage`/`imports`-list literal paths->Import node + Imports ref, and + // `apply_expression`->Calls ref with curried-chain dedup. The module-system + // synthesizer / lexical-scope gates / callback synthesizer / import-resolver + // wiring are DEFERRED, so path refs stay unresolved. + let tempdir = TestDir::new("generated-golden-nix"); + write_golden(&nix_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&nix_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn nix_db_is_self_equivalent_to_nix_golden() { + assert_equivalent(&nix_db(), &nix_golden_dir()).unwrap(); +} + #[test] fn tier1_node_drift_is_reported() { let expected = load_golden(&mini_golden_dir()).unwrap(); @@ -266,6 +289,14 @@ fn solidity_golden_dir() -> PathBuf { workspace_root().join("reference/golden/solidity") } +fn nix_db() -> PathBuf { + workspace_root().join("reference/golden/nix/colby.db") +} + +fn nix_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/nix") +} + struct TestDir { path: PathBuf, } diff --git a/crates/codegraph-core/src/types.rs b/crates/codegraph-core/src/types.rs index 3e8985f3..92ea64e4 100644 --- a/crates/codegraph-core/src/types.rs +++ b/crates/codegraph-core/src/types.rs @@ -49,7 +49,7 @@ pub const EDGE_KIND_STRINGS: [&str; 12] = [ "decorates", ]; -pub const LANGUAGE_STRINGS: [&str; 38] = [ +pub const LANGUAGE_STRINGS: [&str; 39] = [ "typescript", "javascript", "tsx", @@ -79,6 +79,7 @@ pub const LANGUAGE_STRINGS: [&str; 38] = [ "objc", "r", "solidity", + "nix", "yaml", "twig", "xml", @@ -326,6 +327,8 @@ pub enum Language { R, #[serde(rename = "solidity")] Solidity, + #[serde(rename = "nix")] + Nix, #[serde(rename = "yaml")] Yaml, #[serde(rename = "twig")] @@ -347,7 +350,7 @@ pub enum Language { } impl Language { - pub const ALL: [Self; 38] = [ + pub const ALL: [Self; 39] = [ Self::TypeScript, Self::JavaScript, Self::Tsx, @@ -377,6 +380,7 @@ impl Language { Self::ObjC, Self::R, Self::Solidity, + Self::Nix, Self::Yaml, Self::Twig, Self::Xml, @@ -419,6 +423,7 @@ impl Language { Self::ObjC => "objc", Self::R => "r", Self::Solidity => "solidity", + Self::Nix => "nix", Self::Yaml => "yaml", Self::Twig => "twig", Self::Xml => "xml", diff --git a/crates/codegraph-extract/Cargo.toml b/crates/codegraph-extract/Cargo.toml index f1e183c8..72fe6829 100644 --- a/crates/codegraph-extract/Cargo.toml +++ b/crates/codegraph-extract/Cargo.toml @@ -38,6 +38,7 @@ tree-sitter-json = "0.24.8" tree-sitter-kotlin-ng = "1.1.0" tree-sitter-lua = "0.5.0" tree-sitter-luau = "1.2.0" +tree-sitter-nix = "0.3.0" tree-sitter-objc = "3.0.2" tree-sitter-pascal = "0.10.2" tree-sitter-php = "0.24.2" diff --git a/crates/codegraph-extract/src/engine.rs b/crates/codegraph-extract/src/engine.rs index 3131c4d3..39069f0a 100644 --- a/crates/codegraph-extract/src/engine.rs +++ b/crates/codegraph-extract/src/engine.rs @@ -83,6 +83,7 @@ pub fn builtin_language_for_ext(ext: &str) -> Option { "m" | "mm" => Language::ObjC, "r" => Language::R, "sol" => Language::Solidity, + "nix" => Language::Nix, "yml" | "yaml" => Language::Yaml, "twig" => Language::Twig, "xml" => Language::Xml, @@ -871,7 +872,7 @@ mod tests { assert_eq!(detect_language("s.metal"), Language::Cpp); assert_eq!(detect_language("k.cu"), Language::Cpp); assert_eq!(detect_language("k.cuh"), Language::Cpp); - assert_eq!(Language::ALL.len(), 38); + assert_eq!(Language::ALL.len(), 39); } #[test] @@ -884,6 +885,11 @@ mod tests { assert_eq!(detect_language("Token.sol"), Language::Solidity); } + #[test] + fn nix_extension_maps_to_nix() { + assert_eq!(detect_language("flake.nix"), Language::Nix); + } + #[test] fn plain_ts_stays_typescript() { assert_eq!(detect_language("m.ts"), Language::TypeScript); diff --git a/crates/codegraph-extract/src/lang/mod.rs b/crates/codegraph-extract/src/lang/mod.rs index 14733d97..4a2074b5 100644 --- a/crates/codegraph-extract/src/lang/mod.rs +++ b/crates/codegraph-extract/src/lang/mod.rs @@ -16,6 +16,7 @@ mod jsx; mod kotlin; mod lua; mod luau; +mod nix; mod objc; mod pascal; mod php; @@ -47,6 +48,12 @@ pub use jsx::JSX_SPEC; pub use kotlin::KOTLIN_SPEC; pub use lua::LUA_SPEC; pub use luau::LUAU_SPEC; +pub use nix::NIX_SPEC; +pub(crate) use nix::{ + format_function_signature, is_callpackage_name, is_returned_attrset_member, + is_static_project_path, nix_callee_name, nix_curried_params_and_body, nix_direct_callee_name, + nix_first_apply_argument, nix_inherited_attrs, nix_static_import_path, +}; pub use objc::OBJC_SPEC; pub use pascal::PASCAL_SPEC; pub use php::PHP_SPEC; @@ -86,6 +93,7 @@ pub fn spec_for_language(language: Language) -> Option<&'static dyn LanguageSpec Language::ObjC => Some(&OBJC_SPEC), Language::R => Some(&R_SPEC), Language::Solidity => Some(&SOLIDITY_SPEC), + Language::Nix => Some(&NIX_SPEC), Language::Gdscript => Some(&GDSCRIPT_SPEC), _ => None, } diff --git a/crates/codegraph-extract/src/lang/nix.rs b/crates/codegraph-extract/src/lang/nix.rs new file mode 100644 index 00000000..b5f490c0 --- /dev/null +++ b/crates/codegraph-extract/src/lang/nix.rs @@ -0,0 +1,385 @@ +//! Nix (`.nix`) `LanguageSpec`. +//! +//! Extraction-tier port of `upstream extraction/languages/nix.ts` (commit +//! `7f32513`, #1190 — the extraction slice only). Nix is an expression-based +//! language with no C-family `class`/`struct`/`method`/`enum`/`interface` node +//! kinds; its "symbols" are `binding`s (an attrpath name + a value) and lambda +//! `function_expression`s, and a "call" is an `apply_expression` (`f a b`), not +//! a `call_expression`. So — faithful to upstream's entirely empty +//! `nixExtractor` config — [`NixSpec`] returns `&[]` for every type-set and the +//! extraction is driven entirely by the `Language::Nix`-guarded +//! `visit_nix_node` walker extension in [`crate::walker`]. +//! +//! The module-system option-path synthesizer, lexical-scope resolution gates, +//! callback synthesizer, and import-resolver module-list wiring that upstream +//! bundles with the same commit are DEFERRED — the port has no +//! callback-synthesis / option-wiring subsystem. +//! +//! The pure AST helper fns below are `pub(crate)` and re-exported through +//! [`crate::lang`] so the walker can reach them as `crate::lang::`. + +use codegraph_core::types::Language; +use tree_sitter::{Language as TsLanguage, Node}; + +use crate::spec::LanguageSpec; +use crate::walker::node_text; + +pub struct NixSpec; + +pub static NIX_SPEC: NixSpec = NixSpec; + +impl LanguageSpec for NixSpec { + fn language(&self) -> Language { + Language::Nix + } + + fn tree_sitter_language(&self) -> TsLanguage { + tree_sitter_nix::LANGUAGE.into() + } + + fn function_types(&self) -> &'static [&'static str] { + &[] + } + + fn class_types(&self) -> &'static [&'static str] { + &[] + } + + fn method_types(&self) -> &'static [&'static str] { + &[] + } + + fn interface_types(&self) -> &'static [&'static str] { + &[] + } + + fn struct_types(&self) -> &'static [&'static str] { + &[] + } + + fn enum_types(&self) -> &'static [&'static str] { + &[] + } + + fn enum_member_types(&self) -> &'static [&'static str] { + &[] + } + + fn type_alias_types(&self) -> &'static [&'static str] { + &[] + } + + fn import_types(&self) -> &'static [&'static str] { + &[] + } + + fn call_types(&self) -> &'static [&'static str] { + &[] + } + + fn variable_types(&self) -> &'static [&'static str] { + &[] + } + + fn name_field(&self) -> &'static str { + "" + } + + fn body_field(&self) -> &'static str { + "" + } + + fn params_field(&self) -> &'static str { + "" + } + + fn return_field(&self) -> &'static str { + "" + } +} + +/// `variable_expression` → its first named child (the `identifier`); any other +/// node is returned unchanged. Ports `unwrapVariableExpression` (nix.ts:5-8). +pub(crate) fn unwrap_variable_expression(node: Node<'_>) -> Node<'_> { + if node.kind() != "variable_expression" { + return node; + } + node.named_child(0).unwrap_or(node) +} + +/// Callee name of an `apply_expression`: unroll the `function` field to the +/// innermost node, unwrap a `variable_expression`, and return the text of an +/// `identifier` / `select_expression`. Ports `getCalleeName` (nix.ts:10-22). +pub(crate) fn nix_callee_name(node: Node<'_>, source: &str) -> Option { + let mut current = node; + while current.kind() == "apply_expression" { + let Some(func) = current + .child_by_field_name("function") + .or_else(|| current.named_child(0)) + else { + break; + }; + current = func; + } + current = unwrap_variable_expression(current); + if matches!(current.kind(), "identifier" | "select_expression") { + return Some(node_text(current, source).trim().to_string()); + } + None +} + +/// Direct callee: the `function` field (or first named child), unwrapped, its +/// text. Ports `getDirectCalleeName` (nix.ts:24-29). +pub(crate) fn nix_direct_callee_name(node: Node<'_>, source: &str) -> Option { + let func = node + .child_by_field_name("function") + .or_else(|| node.named_child(0))?; + let func = unwrap_variable_expression(func); + Some(node_text(func, source).trim().to_string()) +} + +/// A `./` or `../` project-relative path with no shell/interpolation +/// metacharacters. Ports `isStaticProjectPath` (nix.ts:31-36). +pub(crate) fn is_static_project_path(value: &str) -> bool { + (value.starts_with("./") || value.starts_with("../")) + && !value + .chars() + .any(|c| c.is_whitespace() || "{}()[];\"'<>$".contains(c)) +} + +/// Unwrap `parenthesized_expression`, strip matching quotes, gate on +/// [`is_static_project_path`]. Ports `getStaticImportPath` (nix.ts:38-56). +pub(crate) fn nix_static_import_path(arg: Node<'_>, source: &str) -> Option { + let mut current = arg; + while current.kind() == "parenthesized_expression" { + let Some(inner) = current.named_child(0) else { + break; + }; + current = inner; + } + + let mut text = node_text(current, source).trim().to_string(); + let bytes = text.as_bytes(); + if text.len() >= 2 + && ((bytes[0] == b'"' && bytes[bytes.len() - 1] == b'"') + || (bytes[0] == b'\'' && bytes[bytes.len() - 1] == b'\'')) + { + text = text[1..text.len() - 1].to_string(); + } + + if is_static_project_path(&text) { + Some(text) + } else { + None + } +} + +/// True when `node` is a member of a RETURNED attrset (not a `let` binding, a +/// nested `binding` value, or a lambda `formals` parameter). Parent walk per +/// upstream `isReturnedAttrsetMember` (nix.ts:58-87). +pub(crate) fn is_returned_attrset_member(node: Node<'_>) -> bool { + let mut current = node; + let mut seen_returned_attrset = false; + + while let Some(parent) = current.parent() { + if parent.kind() == "let_expression" { + let body = parent + .child_by_field_name("body") + .or_else(|| parent.child_by_field_name("expression")); + match body { + Some(body) if body == current => {} + _ => return false, + } + } + + if parent.kind() == "binding" && current != node { + return false; + } + if matches!(parent.kind(), "formal_parameters" | "formals") { + return false; + } + + if matches!( + parent.kind(), + "attrset" | "rec_attrset" | "attrset_expression" | "rec_attrset_expression" + ) { + seen_returned_attrset = true; + } + + current = parent; + } + + seen_returned_attrset +} + +/// Unroll nested `function_expression`s, collecting the source-slice param text +/// before each body start; return `(params, body)`. Ports +/// `getCurriedParamsAndBody` (nix.ts:89-112). +pub(crate) fn nix_curried_params_and_body<'t>( + node: Node<'t>, + source: &str, +) -> (Vec, Option>) { + let mut params: Vec = Vec::new(); + let mut current = node; + + while current.kind() == "function_expression" && current.named_child_count() > 0 { + let Some(body) = current.named_child(current.named_child_count() as u32 - 1) else { + break; + }; + + let start = current.start_byte(); + let end = body.start_byte(); + let param_part = source.get(start..end).unwrap_or_default().trim(); + let param_text = param_part + .strip_suffix(':') + .map(str::trim) + .unwrap_or(param_part); + if !param_text.is_empty() { + params.push(param_text.to_string()); + } + + if body.kind() == "function_expression" { + current = body; + } else { + return (params, Some(body)); + } + } + + let body = if current.named_child_count() > 0 { + current.named_child(current.named_child_count() as u32 - 1) + } else { + None + }; + (params, body) +} + +/// Format a curried-lambda signature. Ports `formatFunctionSignature` +/// (nix.ts:114-121): `()` for none, `p : q` for ≥2, and `(p)` for a single bare +/// param (unless it already starts `(` or contains `{`/`@`). +pub(crate) fn format_function_signature(params: &[String]) -> String { + if params.is_empty() { + return "()".to_string(); + } + if params.len() > 1 { + return params.join(" : "); + } + let param = ¶ms[0]; + if param.is_empty() { + return "()".to_string(); + } + if param.starts_with('(') || param.contains('{') || param.contains('@') { + param.clone() + } else { + format!("({param})") + } +} + +/// The `inherited_attrs` named child of an `inherit` / `inherit_from`. Ports +/// `inheritedAttrs` (nix.ts:123-125). +pub(crate) fn nix_inherited_attrs(node: Node<'_>) -> Option> { + node.named_children(&mut node.walk()) + .find(|child| child.kind() == "inherited_attrs") +} + +/// `callPackage`/`callPackages` or a `.callPackage`/`.callPackages` suffix (the +/// nixpkgs auto-wiring idiom). Ports `isCallPackageName` (nix.ts:131-138). +pub(crate) fn is_callpackage_name(name: &str) -> bool { + name == "callPackage" + || name == "callPackages" + || name.ends_with(".callPackage") + || name.ends_with(".callPackages") +} + +/// Innermost `argument` of a curried apply chain (`f a b` → `a`). Ports +/// `getFirstApplyArgument` (nix.ts:141-152). +pub(crate) fn nix_first_apply_argument(node: Node<'_>) -> Option> { + let mut inner = node; + loop { + let fnn = inner + .child_by_field_name("function") + .or_else(|| inner.named_child(0)); + match fnn { + Some(f) if f.kind() == "apply_expression" => { + inner = f; + } + _ => break, + } + } + inner + .child_by_field_name("argument") + .or_else(|| inner.named_child(1)) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn parse(src: &str) -> tree_sitter::Tree { + let mut parser = tree_sitter::Parser::new(); + parser + .set_language(&tree_sitter_nix::LANGUAGE.into()) + .unwrap(); + parser.parse(src, None).unwrap() + } + + fn first_of_kind<'t>(node: Node<'t>, kind: &str) -> Option> { + if node.kind() == kind { + return Some(node); + } + for i in 0..node.named_child_count() as u32 { + let child = node.named_child(i)?; + if let Some(found) = first_of_kind(child, kind) { + return Some(found); + } + } + None + } + + #[test] + fn nix_spec_has_empty_type_sets() { + assert!(NIX_SPEC.function_types().is_empty()); + assert!(NIX_SPEC.class_types().is_empty()); + assert!(NIX_SPEC.method_types().is_empty()); + assert!(NIX_SPEC.call_types().is_empty()); + assert!(NIX_SPEC.variable_types().is_empty()); + assert!(NIX_SPEC.import_types().is_empty()); + assert_eq!(NIX_SPEC.language(), Language::Nix); + } + + #[test] + fn nix_format_function_signature() { + assert_eq!(format_function_signature(&[]), "()"); + assert_eq!(format_function_signature(&["pkgs".to_string()]), "(pkgs)"); + assert_eq!( + format_function_signature(&["{ pkgs }".to_string()]), + "{ pkgs }" + ); + assert_eq!( + format_function_signature(&["a".to_string(), "b".to_string()]), + "a : b" + ); + } + + #[test] + fn is_static_project_path_gate() { + assert!(is_static_project_path("./foo.nix")); + assert!(is_static_project_path("../common/base.nix")); + assert!(!is_static_project_path("nixpkgs")); + assert!(!is_static_project_path("./a b")); + assert!(!is_static_project_path("./${x}.nix")); + } + + #[test] + fn nix_parses_lambda_and_binding() { + let tree = parse("{ pkgs }: let x = 1; in x"); + let root = tree.root_node(); + assert!( + first_of_kind(root, "function_expression").is_some(), + "tree-sitter-nix parses a lambda" + ); + assert!( + first_of_kind(root, "binding").is_some(), + "tree-sitter-nix parses a let binding" + ); + } +} diff --git a/crates/codegraph-extract/src/walker.rs b/crates/codegraph-extract/src/walker.rs index 328e5483..35fe0d69 100644 --- a/crates/codegraph-extract/src/walker.rs +++ b/crates/codegraph-extract/src/walker.rs @@ -229,10 +229,233 @@ impl<'a, 'tree> TreeSitterWalker<'a, 'tree> { Language::Gdscript => self.visit_gdscript_node(node), Language::Cpp => self.visit_cpp_node(node), Language::Solidity => self.visit_solidity_node(node), + Language::Nix => self.visit_nix_node(node), _ => false, } } + /// Nix extraction (upstream `nixExtractor.visitNode`, `nix.ts`, #1190 — the + /// extraction slice only). Nix's expression AST has no C-family type-set + /// node kinds, so `NIX_SPEC` returns `&[]` for every type-set and this + /// custom visitor (like `visit_gdscript_node`) owns the four handled kinds: + /// `binding` → Function|Variable, bare `function_expression` body descent, + /// `inherit`/`inherit_from` → Variable names, and `apply_expression` → + /// Calls / import-path Imports. Every other kind returns `false` → the + /// generic `visit_named_children` descent. Strictly `Language::Nix`-guarded. + fn visit_nix_node(&mut self, node: SyntaxNode<'tree>) -> bool { + match node.kind() { + "binding" => { + self.visit_nix_binding(node); + true + } + "function_expression" => { + // Bare lambda (not owned by a binding): visit the body (last + // named child) only. nix.ts:243-247. + if node.named_child_count() > 0 { + if let Some(body) = node.named_child(node.named_child_count() as u32 - 1) { + self.visit_node(body); + } + } + true + } + "inherit" | "inherit_from" => { + self.visit_nix_inherit(node); + true + } + "apply_expression" => { + self.visit_nix_apply(node); + // Visit all named children (nix.ts:316-318). + self.visit_named_children(node); + true + } + _ => false, + } + } + + fn visit_nix_binding(&mut self, node: SyntaxNode<'tree>) { + let Some(attrpath) = child_by_field(node, "attrpath").or_else(|| node.named_child(0)) + else { + return; + }; + let name = node_text(attrpath, self.source).trim().to_string(); + if name.is_empty() { + return; + } + let Some(value) = child_by_field(node, "expression") + .or_else(|| child_by_field(node, "value")) + .or_else(|| node.named_child(1)) + else { + return; + }; + + if value.kind() == "function_expression" { + let (params, body) = crate::lang::nix_curried_params_and_body(value, self.source); + let signature = crate::lang::format_function_signature(¶ms); + if let Some(func) = self.create_node( + NodeKind::Function, + &name, + node, + NodeExtra { + signature: Some(signature), + is_exported: crate::lang::is_returned_attrset_member(node), + ..NodeExtra::default() + }, + ) { + self.node_stack.push(func.id); + if let Some(body) = body { + self.visit_node(body); + } + self.node_stack.pop(); + } + } else { + let init_value = node_text(value, self.source); + let init_slice: String = init_value.chars().take(100).collect(); + let signature = if init_slice.is_empty() { + None + } else { + let ellipsis = if init_value.chars().count() >= 100 { + "..." + } else { + "" + }; + Some(format!("= {init_slice}{ellipsis}")) + }; + self.create_node( + NodeKind::Variable, + &name, + node, + NodeExtra { + signature, + is_exported: crate::lang::is_returned_attrset_member(node), + ..NodeExtra::default() + }, + ); + + // NixOS/home-manager `imports = [ ./hardware.nix ]` (and flake-era + // `modules = [ ./configuration.nix ]`) reference files without an + // `import` call. Only literal `path_expression` entries count. + // nix.ts:225-235. + let final_segment = name.rsplit('.').next().unwrap_or(name.as_str()); + if matches!(final_segment, "imports" | "modules") && value.kind() == "list_expression" { + for child in value.named_children(&mut value.walk()) { + if child.kind() == "path_expression" { + let entry = node_text(child, self.source).trim().to_string(); + if crate::lang::is_static_project_path(&entry) { + self.emit_nix_file_import(&entry, child); + } + } + } + } + + self.visit_node(value); + } + } + + fn visit_nix_inherit(&mut self, node: SyntaxNode<'tree>) { + if let Some(attrs) = crate::lang::nix_inherited_attrs(node) { + for child in attrs.named_children(&mut attrs.walk()) { + let name = node_text(child, self.source).trim().to_string(); + if !name.is_empty() { + self.create_node( + NodeKind::Variable, + &name, + child, + NodeExtra { + is_exported: crate::lang::is_returned_attrset_member(child), + ..NodeExtra::default() + }, + ); + } + } + } + for child in node.named_children(&mut node.walk()) { + if child.kind() != "inherited_attrs" { + self.visit_node(child); + } + } + } + + fn visit_nix_apply(&mut self, node: SyntaxNode<'tree>) { + let direct_callee = crate::lang::nix_direct_callee_name(node, self.source); + let is_direct_import = matches!( + direct_callee.as_deref(), + Some("import") | Some("builtins.import") + ); + + // Wrapper objects are re-created per access, so compare node identity + // (start/end byte span), never a fresh handle — otherwise every level of + // a curried chain (`f a b`) re-emits the same refs. nix.ts:274-278. + let is_callee_of_parent = node + .parent() + .filter(|p| p.kind() == "apply_expression") + .and_then(|p| { + p.child_by_field_name("function") + .or_else(|| p.named_child(0)) + }) + .map(|parent_fn| { + parent_fn.start_byte() == node.start_byte() + && parent_fn.end_byte() == node.end_byte() + }) + .unwrap_or(false); + + if is_callee_of_parent && !is_direct_import { + return; + } + + if is_direct_import { + let arg = child_by_field(node, "argument").or_else(|| node.named_child(1)); + if let Some(arg) = arg { + if let Some(path) = crate::lang::nix_static_import_path(arg, self.source) { + self.emit_nix_file_import(&path, node); + } + } + return; + } + + let callee = crate::lang::nix_callee_name(node, self.source); + if let Some(callee) = callee.as_deref() { + if callee != "import" + && callee != "builtins.import" + && let Some(from) = self.node_stack.last().cloned() + { + self.push_ref(&from, callee, EdgeKind::Calls, node); + } + + // `callPackage ./pkg.nix { }` loads the file like `import` does; the + // first argument of the apply chain is the package file. Only a + // literal static path counts. nix.ts:303-312. + if crate::lang::is_callpackage_name(callee) { + if let Some(first_arg) = crate::lang::nix_first_apply_argument(node) { + if let Some(path) = crate::lang::nix_static_import_path(first_arg, self.source) + { + self.emit_nix_file_import(&path, node); + } + } + } + } + } + + /// Import node + unresolved `imports` ref for a static project path. Ports + /// `emitFileImport` (nix.ts:155-172). + fn emit_nix_file_import(&mut self, import_path: &str, anchor: SyntaxNode<'tree>) { + let anchor_text = node_text(anchor, self.source); + let signature: String = anchor_text.trim().chars().take(100).collect(); + let created = self.create_node( + NodeKind::Import, + import_path, + anchor, + NodeExtra { + signature: Some(signature), + ..NodeExtra::default() + }, + ); + if created.is_some() { + if let Some(from) = self.node_stack.last().cloned() { + self.push_ref(&from, import_path, EdgeKind::Imports, anchor); + } + } + } + fn visit_solidity_node(&mut self, node: SyntaxNode<'tree>) -> bool { // #1170 — upstream `solidityExtractor.visitNode` emits a `field` node for // `event_definition` / `error_declaration` UNCONDITIONALLY, file-level @@ -5506,4 +5729,67 @@ public: // Trailing/interior whitespace around stripped args is trimmed. assert_eq!(strip_cpp_template_args("Base "), "Base"); } + + // ---- Nix (custom visit_nix_node; NIX_SPEC has empty type-sets) ---- + + #[test] + fn nix_binding_lambda_is_function() { + let (nodes, _refs) = run("m.nix", "{ f = { pkgs }: pkgs.hello; }", Language::Nix); + let func = node(&nodes, NodeKind::Function, "f"); + assert_eq!(func.signature.as_deref(), Some("{ pkgs }")); + } + + #[test] + fn nix_binding_value_is_variable_or_field() { + let (nodes, _refs) = run("m.nix", "{ x = 42; }", Language::Nix); + assert!(has_node(&nodes, NodeKind::Variable, "x")); + } + + #[test] + fn nix_apply_expression_is_call() { + let (_nodes, refs) = run("m.nix", "{ y = mkDerivation { }; }", Language::Nix); + assert!(has_ref(&refs, EdgeKind::Calls, "mkDerivation")); + let curried = run("m.nix", "{ z = foo a b; }", Language::Nix).1; + let count = curried + .iter() + .filter(|r| r.reference_kind == EdgeKind::Calls && r.reference_name == "foo") + .count(); + assert_eq!(count, 1, "curried chain dedup: {curried:?}"); + } + + #[test] + fn nix_import_and_callpackage_are_imports() { + let (nodes, refs) = run( + "m.nix", + "{ a = import ./foo.nix; b = callPackage ./bar.nix {}; }", + Language::Nix, + ); + assert!(has_node(&nodes, NodeKind::Import, "./foo.nix")); + assert!(has_node(&nodes, NodeKind::Import, "./bar.nix")); + assert!(has_ref(&refs, EdgeKind::Imports, "./foo.nix")); + assert!(has_ref(&refs, EdgeKind::Imports, "./bar.nix")); + } + + #[test] + fn nix_imports_list_emits_file_imports() { + let (_nodes, refs) = run( + "m.nix", + "{ imports = [ ./hardware.nix ../common.nix pkgsVar ]; }", + Language::Nix, + ); + assert!(has_ref(&refs, EdgeKind::Imports, "./hardware.nix")); + assert!(has_ref(&refs, EdgeKind::Imports, "../common.nix")); + let bare = refs + .iter() + .filter(|r| r.reference_kind == EdgeKind::Imports) + .count(); + assert_eq!(bare, 2, "bare-variable entry emits no import: {refs:?}"); + } + + #[test] + fn nix_inherit_names_extracted() { + let (nodes, _refs) = run("m.nix", "{ inherit lib pkgs; }", Language::Nix); + assert!(has_node(&nodes, NodeKind::Variable, "lib")); + assert!(has_node(&nodes, NodeKind::Variable, "pkgs")); + } } diff --git a/crates/codegraph-store/src/queries.rs b/crates/codegraph-store/src/queries.rs index 6e16dc17..b3e0c675 100644 --- a/crates/codegraph-store/src/queries.rs +++ b/crates/codegraph-store/src/queries.rs @@ -1525,6 +1525,7 @@ fn parse_language(value: String) -> rusqlite::Result { "objc" => Language::ObjC, "r" => Language::R, "solidity" => Language::Solidity, + "nix" => Language::Nix, "yaml" => Language::Yaml, "twig" => Language::Twig, "xml" => Language::Xml, @@ -2193,6 +2194,11 @@ mod tests { ); } + #[test] + fn parse_language_accepts_nix() { + assert_eq!(parse_language("nix".to_string()).unwrap(), Language::Nix); + } + #[test] fn edges_by_target_and_all_getters() { let mut store = store("edges-target"); diff --git a/docs/equivalence.md b/docs/equivalence.md index 00a8b6ad..5e88a2ee 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -456,6 +456,54 @@ The `generated_golden_matches_committed_solidity_fixture` and `solidity_db_is_self_equivalent_to_solidity_golden` tests in `crates/codegraph-bench/tests/equivalence.rs` enforce byte-stability. +### Nix fixture + +A ninth golden fixture, `reference/golden/nix/`, guards Nix (`.nix`) extraction +(upstream #1190 / `7f32513`, the extraction slice only). Nix is a **new +`Language::Nix` variant** backed by a **dedicated `tree-sitter-nix` grammar**. +`.nix` maps to `Language::Nix`. Because Nix is an expression language with no +C-family `class`/`struct`/`method`/`enum` node kinds, `NIX_SPEC` has all-empty +type-sets and the extraction is driven by the `Language::Nix`-guarded +`visit_nix_node` walker extension. The corpus +(`crates/codegraph-bench/fixtures/nix/`) has a top-level lambda +`{ pkgs, lib }: …`, a `let … in`, a returned attrset with bindings, an +`import ./foo.nix`, a `pkgs.callPackage ./bar.nix { }`, an `inherit lib;`, an +`imports = [ ./foo.nix ./bar.nix ]` module list, and a curried `build = { src }: +…` lambda. What it guards: + +- all three `.nix` files with `"language": "nix"`; +- a `binding` whose value is a lambda → `NodeKind::Function` with a formatted + curried-param signature (`build` → `{ src }`, `double` → `(x)`); +- a non-lambda `binding` and each `inherit`ed name → `NodeKind::Variable`; +- `import ./foo.nix`, `callPackage ./bar.nix { }`, and the literal + `imports`-list paths → `NodeKind::Import` nodes + `Imports` refs; +- an `apply_expression` call → `Calls` ref, deduped across curried levels + (`pkgs.mkDerivation`, `pkgs.callPackage`, `stdenv.mkDerivation`). + +The `imports`/`callPackage` path refs to `./foo.nix` / `./bar.nix` resolve +in-corpus (both files exist), so `refs.json` retains only the three unresolved +`Calls` refs — the module-system option-path synthesizer, lexical-scope +resolution gates, callback synthesizer, and import-resolver module-list wiring +that upstream bundles with the same commit are **DEFERRED**, so no new Nix +resolve code binds anything. Adding the variant is byte-neutral for +`colby.schema.sql` (language is a stored TEXT value, not DDL) and for the eight +existing goldens (none holds a `.nix` file). + +Regenerate reproducibly (identical recipe to the Solidity fixture, substituting +`nix`): + +```bash +rm -rf /tmp/cg-fixture-nix && cp -r crates/codegraph-bench/fixtures/nix /tmp/cg-fixture-nix +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 ./target/release/codegraph init /tmp/cg-fixture-nix +cp /tmp/cg-fixture-nix/.codegraph/codegraph.db reference/golden/nix/colby.db +cargo run -p codegraph-bench --bin bench -- --gen-golden reference/golden/nix/colby.db reference/golden/nix +``` + +The `generated_golden_matches_committed_nix_fixture` and +`nix_db_is_self_equivalent_to_nix_golden` tests in +`crates/codegraph-bench/tests/equivalence.rs` enforce byte-stability. + ### KNOWN_DIFFS.md format Tier-3 differences are allowlisted by grep-able lines in repo-root diff --git a/docs/languages.md b/docs/languages.md index 4a18e7e6..ab430970 100644 --- a/docs/languages.md +++ b/docs/languages.md @@ -4,7 +4,7 @@ CodeGraph extracts code structure deterministically using tree-sitter grammars a embedded extractors. No AI, vectors, or embeddings are involved. The output is byte-stable across runs. -**34 concrete languages** are supported, grouped into three extraction tiers based on what +**35 concrete languages** are supported, grouped into three extraction tiers based on what the extractor produces. > **Note on TypeScript/JavaScript variants:** `typescript` and `tsx`, and `javascript` and @@ -14,7 +14,7 @@ the extractor produces. --- -## Tier 1 — Full symbol extraction (25 languages) +## Tier 1 — Full symbol extraction (26 languages) Tree-sitter parses the file and extracts all symbols (functions, classes, structs, methods, variables, imports, etc.) plus call and dependency edges. This is the richest extraction @@ -45,6 +45,7 @@ level. | Objective-C | `.m` `.mm` | Full tree-sitter | | | R | `.r` | Full tree-sitter | | | Solidity | `.sol` | Full tree-sitter | `tree-sitter-solidity` grammar; contracts/libraries/interfaces, structs, enums, modifiers, events, errors; `is`-inheritance → Extends (resolver promotes to Implements for interfaces); emit/revert/modifier-guard call edges | +| Nix | `.nix` | Full tree-sitter | `tree-sitter-nix` grammar; `let`/attrset bindings, curried lambdas, `inherit`; `import`/`callPackage`/`imports`-list file imports; module-system option synthesizer deferred | | GDScript | `.gd` | Full tree-sitter | Godot scripting; extracts functions, classes, enums, variables, signals, extends, preload. Dynamic dispatch edges (connect/get_node/$/%/call/group) added by the Godot resolver — see [`docs/godot.md`](godot.md) | | Pascal | `.pas` `.dpr` `.dpk` `.lpr` `.dfm` `.fmx` | Full tree-sitter / custom | `.dfm`/`.fmx` form files use a custom path | diff --git a/reference/golden/nix/colby.db b/reference/golden/nix/colby.db new file mode 100644 index 0000000000000000000000000000000000000000..bb868d1f93b0ac47526511fe96aca9ef5f0154cf GIT binary patch literal 151552 zcmeI53zQ^Rd6=uZ`u)1|ZY`^2Yahc*vopKZ@9rUsSZQZhBdun|>@3nE;ijImt?lWa z?e1A=B@1~FuK?x|Z~{4S04H|L33l*_jZHWh+aZaKO&p&S>=+CII}j7%gCRH=a6I|% ztw&e&^kWc+vx0x5t*ZO_|NnmXQTN`ezIExP7it|{G@7kVxg+MdG0x}XULuMd#|iLn z7XI0PN8!S6IgY`Zx32B8<@B5c?&OU(1ZZUPJsL1ez8C#K^kR57dOS24{Jr3l!O6f! z1B(B9{`U%>7q0uh;d{zA&J&M}AEjgGsp-(cL#go7mpiT6#)jT%G&Q|lm22#L*V^)# z^<{B=ZRPy=1ihLWoIs2UcMyGuP#4u z(h@^2sVI6jlhdnSk<`y6mO8tlUld(lJzJj&r4|?YomfX!>bjXlu(ql;8wMD`aCF_% zHj*=UURW0AdV}ZYuZj1st=xBJ?TUEs@|6YgMp}GeW&Q4pm)FI$iw~@v-I@%gPMzX+ zNRKvZW9@O5ddp*KkUlGXZoZ}g?)7C_J|4~O$HhA@T)Z>=s)rbKyzZPH3#ASp4!` z)h~9{Q@@yBw|+6FQ@_l#P>(u#qjTDbsD%tdPIB6n#oTLknfG!RpRweuSA2Xbc%=G)l|N@$&7Tbu%;cb~gb2W>YhV1u#Oh?`>Ye ztN}p<9TqbtEK7s=GGw_44XS-L%in@)#d5OcBjeQRmP^8 zVW-Ibfgo)6zE} z-QL>G?Ut&0Yodt*`tJ?B(=WuSggtF@Q}4+1&dkzu8%R@mL{~ekdbnGjsm0acOpmQr z^M>A#ftIP-E~IW3;HmVc{rj!%rV5V$Gn@Mr5KX`KhL4rTn_MFb*1-Ip(qLZQ(qO&N zp4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r*L>X2~AMyEC`f~>%rGrVm+NQS1X&6eD;JCbfI z=-wteH@9dRwP02Y3rd4;CoLUTv>R0#-ON1gl^V^~CM<(L4!JbLPr*aI?RrOK(OAWq z*H3Po6z@85LIed@n|8zn(P*|Hk*e3=$@e0QUu#&;>CAQWq0c?j!mvJ&)%R+KodPi1 zWluPFj`D0AvGau48+vEnJri-k(|&pat(IgxvUlL`x&O#pTXpk6mlMZ(1A^g_+Ny2Q zUkfm((R9Lhojb(e!I57lj}Y$rfBp|i|MC`}-oN|>!PM+5f75eMf|{PU?>Y4PxR<~A zV4Jpw{Cr2LFTjLwp`l-2Xw*9k4Gj)$d2_3-r|+F*vLEV|opH&|92+D%4n=O2_X#6D;qjAD{ns=u`|avC;6n{Ycy#Uy&QpZ}Y$U$NP^cLBnjcssLp(}~aj@%g{?w%@$By8IBH K|34cKJN`ebb}Ci? literal 0 HcmV?d00001 diff --git a/reference/golden/nix/edges.json b/reference/golden/nix/edges.json new file mode 100644 index 00000000..a14451e4 --- /dev/null +++ b/reference/golden/nix/edges.json @@ -0,0 +1,221 @@ +[ + { + "col": 11, + "kind": "imports", + "line": 3, + "metadata": { + "confidence": 0.7, + "resolvedBy": "file-path" + }, + "provenance": null, + "source": "file:default.nix", + "target": "file:foo.nix" + }, + { + "col": 14, + "kind": "imports", + "line": 10, + "metadata": { + "confidence": 0.7, + "resolvedBy": "file-path" + }, + "provenance": null, + "source": "file:default.nix", + "target": "file:foo.nix" + }, + { + "col": 24, + "kind": "imports", + "line": 10, + "metadata": { + "confidence": 0.7, + "resolvedBy": "file-path" + }, + "provenance": null, + "source": "file:default.nix", + "target": "file:bar.nix" + }, + { + "col": 8, + "kind": "imports", + "line": 4, + "metadata": { + "confidence": 0.7, + "resolvedBy": "file-path" + }, + "provenance": null, + "source": "file:default.nix", + "target": "file:bar.nix" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:bar.nix", + "target": "variable:44d07e5e97a9eb169c8b5ff98fce1ab3" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:bar.nix", + "target": "variable:6cd992ebd6196831208b1a52f453db07" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "function:efd81fcc22ebb21765d9c3cc0793cb95" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "import:28bda77b3554035c8b80d465d5ca5ea6" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "import:9172fe6a41024c2ccb850e98721d523a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "import:9fe67dad07458e7da8f22ab3af144ea4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "import:cda00c0cb1b705c54a2ff7e084077bcb" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:25db1fa61912f8976b97968eac1e508f" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:42eabe8a9f2b3fcd2ad6e8e85f3ee9a2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:59312d0eb6e9b389e669ce3b8f196b90" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:9addcb9072c75370f6e30031303105f6" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:c6f664dc7d14514becf6026e5433db28" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:d6de27bfea9dffedb1e66122f1f7a327" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:default.nix", + "target": "variable:f2f450017e009b920df0f28a08977b33" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:foo.nix", + "target": "function:ef79bf042d673a9aeda54c1b6f0551d4" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:foo.nix", + "target": "variable:a1cbe9b12b88bae3e7e7b9c254000901" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:foo.nix", + "target": "variable:b737f15346177f2dd9c3f909ffdbd14f" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "function:efd81fcc22ebb21765d9c3cc0793cb95", + "target": "variable:5652709e8a42bb2e9a078eb0dafd0f2a" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "function:efd81fcc22ebb21765d9c3cc0793cb95", + "target": "variable:6d6c846d384f81d48df540abaddbce5f" + } +] diff --git a/reference/golden/nix/files.json b/reference/golden/nix/files.json new file mode 100644 index 00000000..d3f47c55 --- /dev/null +++ b/reference/golden/nix/files.json @@ -0,0 +1,26 @@ +[ + { + "content_hash": "7ea2d3f7da76e263d391b2ec6d7d99574db4c40cc9e4f33a5a305346c82ee3d5", + "errors": null, + "language": "nix", + "node_count": 3, + "path": "bar.nix", + "size": 72 + }, + { + "content_hash": "ed9b1d6a781e97666ec258cf392af57c8ab2cb1e818daac8ea099bef7e041a71", + "errors": null, + "language": "nix", + "node_count": 15, + "path": "default.nix", + "size": 290 + }, + { + "content_hash": "89378235fc3afa5147a2c9abeddc1fb5c31f736bb076c1ad13159b90791bce31", + "errors": null, + "language": "nix", + "node_count": 4, + "path": "foo.nix", + "size": 74 + } +] diff --git a/reference/golden/nix/nodes.json b/reference/golden/nix/nodes.json new file mode 100644 index 00000000..6242bc90 --- /dev/null +++ b/reference/golden/nix/nodes.json @@ -0,0 +1,486 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 6, + "file_path": "bar.nix", + "id": "file:bar.nix", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "nix", + "name": "bar.nix", + "qualified_name": "bar.nix", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 20, + "file_path": "default.nix", + "id": "file:default.nix", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "nix", + "name": "default.nix", + "qualified_name": "default.nix", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 9, + "file_path": "foo.nix", + "id": "file:foo.nix", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "nix", + "name": "foo.nix", + "qualified_name": "foo.nix", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 20, + "end_line": 6, + "file_path": "foo.nix", + "id": "function:ef79bf042d673a9aeda54c1b6f0551d4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "nix", + "name": "double", + "qualified_name": "double", + "return_type": null, + "signature": "(x)", + "start_column": 2, + "start_line": 6, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 4, + "end_line": 15, + "file_path": "default.nix", + "id": "function:efd81fcc22ebb21765d9c3cc0793cb95", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "nix", + "name": "build", + "qualified_name": "build", + "return_type": null, + "signature": "{ src }", + "start_column": 2, + "start_line": 12, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 23, + "end_line": 10, + "file_path": "default.nix", + "id": "import:28bda77b3554035c8b80d465d5ca5ea6", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "nix", + "name": "./foo.nix", + "qualified_name": "./foo.nix", + "return_type": null, + "signature": "./foo.nix", + "start_column": 14, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 38, + "end_line": 4, + "file_path": "default.nix", + "id": "import:9172fe6a41024c2ccb850e98721d523a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "nix", + "name": "./bar.nix", + "qualified_name": "./bar.nix", + "return_type": null, + "signature": "pkgs.callPackage ./bar.nix { }", + "start_column": 8, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 33, + "end_line": 10, + "file_path": "default.nix", + "id": "import:9fe67dad07458e7da8f22ab3af144ea4", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "nix", + "name": "./bar.nix", + "qualified_name": "./bar.nix", + "return_type": null, + "signature": "./bar.nix", + "start_column": 24, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 27, + "end_line": 3, + "file_path": "default.nix", + "id": "import:cda00c0cb1b705c54a2ff7e084077bcb", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "nix", + "name": "./foo.nix", + "qualified_name": "./foo.nix", + "return_type": null, + "signature": "import ./foo.nix", + "start_column": 11, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 21, + "end_line": 5, + "file_path": "default.nix", + "id": "variable:25db1fa61912f8976b97968eac1e508f", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "greeting", + "qualified_name": "greeting", + "return_type": null, + "signature": "= \"hello\"", + "start_column": 2, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 28, + "end_line": 3, + "file_path": "default.nix", + "id": "variable:42eabe8a9f2b3fcd2ad6e8e85f3ee9a2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "helper", + "qualified_name": "helper", + "return_type": null, + "signature": "= import ./foo.nix", + "start_column": 2, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 16, + "end_line": 3, + "file_path": "bar.nix", + "id": "variable:44d07e5e97a9eb169c8b5ff98fce1ab3", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "pname", + "qualified_name": "pname", + "return_type": null, + "signature": "= \"bar\"", + "start_column": 2, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 15, + "end_line": 14, + "file_path": "default.nix", + "id": "variable:5652709e8a42bb2e9a078eb0dafd0f2a", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "src", + "qualified_name": "build::src", + "return_type": null, + "signature": null, + "start_column": 12, + "start_line": 14, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 19, + "end_line": 18, + "file_path": "default.nix", + "id": "variable:59312d0eb6e9b389e669ce3b8f196b90", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "named", + "qualified_name": "named", + "return_type": null, + "signature": "= greeting", + "start_column": 2, + "start_line": 18, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 18, + "end_line": 4, + "file_path": "bar.nix", + "id": "variable:6cd992ebd6196831208b1a52f453db07", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "version", + "qualified_name": "version", + "return_type": null, + "signature": "= \"1.0\"", + "start_column": 2, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 18, + "end_line": 13, + "file_path": "default.nix", + "id": "variable:6d6c846d384f81d48df540abaddbce5f", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "name", + "qualified_name": "build::name", + "return_type": null, + "signature": "= \"demo\"", + "start_column": 4, + "start_line": 13, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 13, + "end_line": 8, + "file_path": "default.nix", + "id": "variable:9addcb9072c75370f6e30031303105f6", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "lib", + "qualified_name": "lib", + "return_type": null, + "signature": null, + "start_column": 10, + "start_line": 8, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 14, + "end_line": 3, + "file_path": "foo.nix", + "id": "variable:a1cbe9b12b88bae3e7e7b9c254000901", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "answer", + "qualified_name": "answer", + "return_type": null, + "signature": "= 42", + "start_column": 2, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 17, + "end_line": 7, + "file_path": "foo.nix", + "id": "variable:b737f15346177f2dd9c3f909ffdbd14f", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "const", + "qualified_name": "const", + "return_type": null, + "signature": "= answer", + "start_column": 2, + "start_line": 7, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 17, + "end_line": 17, + "file_path": "default.nix", + "id": "variable:c6f664dc7d14514becf6026e5433db28", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "value", + "qualified_name": "value", + "return_type": null, + "signature": "= helper", + "start_column": 2, + "start_line": 17, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 36, + "end_line": 10, + "file_path": "default.nix", + "id": "variable:d6de27bfea9dffedb1e66122f1f7a327", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "imports", + "qualified_name": "imports", + "return_type": null, + "signature": "= [ ./foo.nix ./bar.nix ]", + "start_column": 2, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 39, + "end_line": 4, + "file_path": "default.nix", + "id": "variable:f2f450017e009b920df0f28a08977b33", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "variable", + "language": "nix", + "name": "pkg", + "qualified_name": "pkg", + "return_type": null, + "signature": "= pkgs.callPackage ./bar.nix { }", + "start_column": 2, + "start_line": 4, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/nix/refs.json b/reference/golden/nix/refs.json new file mode 100644 index 00000000..d005b9bb --- /dev/null +++ b/reference/golden/nix/refs.json @@ -0,0 +1,32 @@ +[ + { + "candidates": null, + "col": 0, + "file_path": "bar.nix", + "from_node_id": "file:bar.nix", + "language": "nix", + "line": 2, + "reference_kind": "calls", + "reference_name": "stdenv.mkDerivation" + }, + { + "candidates": null, + "col": 19, + "file_path": "default.nix", + "from_node_id": "function:efd81fcc22ebb21765d9c3cc0793cb95", + "language": "nix", + "line": 12, + "reference_kind": "calls", + "reference_name": "pkgs.mkDerivation" + }, + { + "candidates": null, + "col": 8, + "file_path": "default.nix", + "from_node_id": "file:default.nix", + "language": "nix", + "line": 4, + "reference_kind": "calls", + "reference_name": "pkgs.callPackage" + } +] diff --git a/reference/golden/nix/schema.sql b/reference/golden/nix/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/nix/schema.sql @@ -0,0 +1,117 @@ +CREATE TABLE schema_versions ( +version INTEGER PRIMARY KEY, +applied_at INTEGER NOT NULL, +description TEXT +); +CREATE TABLE nodes ( +id TEXT PRIMARY KEY, +kind TEXT NOT NULL, +name TEXT NOT NULL, +qualified_name TEXT NOT NULL, +file_path TEXT NOT NULL, +language TEXT NOT NULL, +start_line INTEGER NOT NULL, +end_line INTEGER NOT NULL, +start_column INTEGER NOT NULL, +end_column INTEGER NOT NULL, +docstring TEXT, +signature TEXT, +visibility TEXT, +is_exported INTEGER DEFAULT 0, +is_async INTEGER DEFAULT 0, +is_static INTEGER DEFAULT 0, +is_abstract INTEGER DEFAULT 0, +decorators TEXT, -- JSON array +type_parameters TEXT, -- JSON array +return_type TEXT, -- normalized return/result type name (e.g. C++ method return, for receiver-type inference) +updated_at INTEGER NOT NULL +); +CREATE TABLE edges ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +source TEXT NOT NULL, +target TEXT NOT NULL, +kind TEXT NOT NULL, +metadata TEXT, -- JSON object +line INTEGER, +col INTEGER, +provenance TEXT DEFAULT NULL, +FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE, +FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE TABLE sqlite_sequence(name,seq); +CREATE TABLE files ( +path TEXT PRIMARY KEY, +content_hash TEXT NOT NULL, +language TEXT NOT NULL, +size INTEGER NOT NULL, +modified_at INTEGER NOT NULL, +indexed_at INTEGER NOT NULL, +node_count INTEGER DEFAULT 0, +errors TEXT -- JSON array +); +CREATE TABLE unresolved_refs ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +from_node_id TEXT NOT NULL, +reference_name TEXT NOT NULL, +reference_kind TEXT NOT NULL, +line INTEGER NOT NULL, +col INTEGER NOT NULL, +candidates TEXT, -- JSON array +file_path TEXT NOT NULL DEFAULT '', +language TEXT NOT NULL DEFAULT 'unknown', +reference_subkind TEXT, +FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE INDEX idx_nodes_kind ON nodes(kind); +CREATE INDEX idx_nodes_name ON nodes(name); +CREATE INDEX idx_nodes_qualified_name ON nodes(qualified_name); +CREATE INDEX idx_nodes_file_path ON nodes(file_path); +CREATE INDEX idx_nodes_language ON nodes(language); +CREATE INDEX idx_nodes_file_line ON nodes(file_path, start_line); +CREATE INDEX idx_nodes_lower_name ON nodes(lower(name)); +CREATE VIRTUAL TABLE nodes_fts USING fts5( +id, +name, +qualified_name, +docstring, +signature, +content='nodes', +content_rowid='rowid' +) +/* nodes_fts(id,name,qualified_name,docstring,signature) */; +CREATE TABLE 'nodes_fts_data'(id INTEGER PRIMARY KEY, block BLOB); +CREATE TABLE 'nodes_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID; +CREATE TABLE 'nodes_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB); +CREATE TABLE 'nodes_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID; +CREATE TRIGGER nodes_ai AFTER INSERT ON nodes BEGIN +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE TRIGGER nodes_ad AFTER DELETE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +END; +CREATE TRIGGER nodes_au AFTER UPDATE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE INDEX idx_edges_kind ON edges(kind); +CREATE INDEX idx_edges_source_kind ON edges(source, kind); +CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); +CREATE INDEX idx_files_language ON files(language); +CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); +CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); +CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); +CREATE INDEX idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name); +CREATE INDEX idx_edges_provenance ON edges(provenance); +CREATE TABLE project_metadata ( +key TEXT PRIMARY KEY, +value TEXT NOT NULL, +updated_at INTEGER NOT NULL +); +CREATE TABLE sqlite_stat1(tbl,idx,stat);