From cc562db72b89b2bd7ecd435375ed0e8e43fdf7e3 Mon Sep 17 00:00:00 2001 From: sunerpy Date: Wed, 15 Jul 2026 00:48:19 +0800 Subject: [PATCH] feat(extraction): index ArkTS (.ets) 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 ArkTS support (#1186). ArkTS is HarmonyOS's TypeScript superset; the dedicated tree-sitter-arkts grammar parses its ArkUI `struct` components, which plain tree-sitter-typescript cannot. `.ets` files now index their functions, classes, ArkUI `struct` components, methods, imports, and call edges as a first-class Tier-1 language. Adds the `Language::ArkTs` variant, the `.ets` extension mapping, an `ARKTS_SPEC` cloned from the TypeScript spec with `struct_declaration` mapped to a struct symbol, the `tree-sitter-arkts = "0.2.0"` crates.io grammar (no vendored grammar), and a dedicated arkts golden fixture. The store's language parser learns "arkts" so indexing an `.ets` file round-trips through the DB. The ArkUI dispatch bridges from the upstream commit — the callback synthesizer, @Component/@Builder/@Styles attribute-chain resolution, state->build() re-render edges, the ohpm workspace-package import resolver, and the decorator hook that feeds them — are deferred: this port has no callback-synthesis subsystem, and those bridges are the same non-Godot framework-resolution machinery it already leaves out. ArkTS joins at the same extraction tier as the other 24 Tier-1 languages. The language enum is stored as a TEXT value, not DDL, so the golden .schema is unchanged and the six existing golden fixtures are byte-identical (no regen); only the new arkts fixture is added. --- Cargo.lock | 31 ++- README.md | 6 +- .../fixtures/arkts/component.ets | 16 ++ crates/codegraph-bench/tests/equivalence.rs | 27 ++ crates/codegraph-core/src/types.rs | 9 +- crates/codegraph-extract/Cargo.toml | 1 + crates/codegraph-extract/src/engine.rs | 14 +- crates/codegraph-extract/src/lang/arkts.rs | 257 ++++++++++++++++++ crates/codegraph-extract/src/lang/mod.rs | 3 + crates/codegraph-extract/src/walker.rs | 31 +++ crates/codegraph-store/src/queries.rs | 1 + docs/equivalence.md | 40 +++ docs/languages.md | 5 +- reference/golden/arkts/colby.db | Bin 0 -> 151552 bytes reference/golden/arkts/edges.json | 80 ++++++ reference/golden/arkts/files.json | 10 + reference/golden/arkts/nodes.json | 156 +++++++++++ reference/golden/arkts/refs.json | 1 + reference/golden/arkts/schema.sql | 117 ++++++++ 19 files changed, 787 insertions(+), 18 deletions(-) create mode 100644 crates/codegraph-bench/fixtures/arkts/component.ets create mode 100644 crates/codegraph-extract/src/lang/arkts.rs create mode 100644 reference/golden/arkts/colby.db create mode 100644 reference/golden/arkts/edges.json create mode 100644 reference/golden/arkts/files.json create mode 100644 reference/golden/arkts/nodes.json create mode 100644 reference/golden/arkts/refs.json create mode 100644 reference/golden/arkts/schema.sql diff --git a/Cargo.lock b/Cargo.lock index acdc1245..9078d52e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,7 +432,7 @@ dependencies = [ [[package]] name = "codegraph-bench" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "clap", @@ -447,7 +447,7 @@ dependencies = [ [[package]] name = "codegraph-core" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "serde", @@ -463,7 +463,7 @@ dependencies = [ [[package]] name = "codegraph-daemon" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -483,7 +483,7 @@ dependencies = [ [[package]] name = "codegraph-extract" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -494,6 +494,7 @@ dependencies = [ "streaming-iterator", "tracing", "tree-sitter", + "tree-sitter-arkts", "tree-sitter-c", "tree-sitter-c-sharp", "tree-sitter-cpp", @@ -525,7 +526,7 @@ dependencies = [ [[package]] name = "codegraph-graph" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -539,7 +540,7 @@ dependencies = [ [[package]] name = "codegraph-mcp" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "axum", @@ -562,7 +563,7 @@ dependencies = [ [[package]] name = "codegraph-resolve" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -576,7 +577,7 @@ dependencies = [ [[package]] name = "codegraph-rs" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "assert_cmd", @@ -612,7 +613,7 @@ dependencies = [ [[package]] name = "codegraph-store" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -624,7 +625,7 @@ dependencies = [ [[package]] name = "codegraph-watch" -version = "0.31.1" +version = "0.33.0" dependencies = [ "anyhow", "codegraph-core", @@ -3421,6 +3422,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-arkts" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a57ea8f49745a1c7687ed0625540aa0b189977ece05954b266d5869214b904cb" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-c" version = "0.24.2" diff --git a/README.md b/README.md index 5f5792db..2d089378 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 32 languages (TypeScript, +**Does:** deterministic code-structure extraction across 33 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 **32 languages** grouped by extraction depth. Quick overview: +CodeGraph supports **33 languages** grouped by extraction depth. Quick overview: -- **Tier 1 — Full symbol extraction (23):** TypeScript, TSX, JavaScript, JSX, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Scala, Lua, Luau, Objective-C, R, GDScript, Pascal. +- **Tier 1 — Full symbol extraction (24):** TypeScript, TSX, JavaScript, JSX, ArkTS, Python, Go, Rust, Java, C, C++, C#, PHP, Ruby, Swift, Kotlin, Dart, Scala, Lua, Luau, Objective-C, R, 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/arkts/component.ets b/crates/codegraph-bench/fixtures/arkts/component.ets new file mode 100644 index 00000000..b765bb52 --- /dev/null +++ b/crates/codegraph-bench/fixtures/arkts/component.ets @@ -0,0 +1,16 @@ +import { Foo } from '../foo'; + +function helper(): void {} + +function driver(): void { + helper() +} + +@Component +struct MyView { + build() { + helper() + } +} + +class Model {} diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index 9f978623..3bee4861 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -116,6 +116,25 @@ fn cuda_db_is_self_equivalent_to_cuda_golden() { assert_equivalent(&cuda_db(), &cuda_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_arkts_fixture() { + // Guards ArkTS extraction (upstream #1186, extraction slice only): the + // `.ets`->ArkTs mapping, `@Component struct`->NodeKind::Struct via the + // dedicated tree-sitter-arkts grammar, function/class/import/call extraction. + let tempdir = TestDir::new("generated-golden-arkts"); + write_golden(&arkts_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&arkts_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn arkts_db_is_self_equivalent_to_arkts_golden() { + assert_equivalent(&arkts_db(), &arkts_golden_dir()).unwrap(); +} + #[test] fn tier1_node_drift_is_reported() { let expected = load_golden(&mini_golden_dir()).unwrap(); @@ -210,6 +229,14 @@ fn cuda_golden_dir() -> PathBuf { workspace_root().join("reference/golden/cuda") } +fn arkts_db() -> PathBuf { + workspace_root().join("reference/golden/arkts/colby.db") +} + +fn arkts_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/arkts") +} + struct TestDir { path: PathBuf, } diff --git a/crates/codegraph-core/src/types.rs b/crates/codegraph-core/src/types.rs index 93243af2..cb266e88 100644 --- a/crates/codegraph-core/src/types.rs +++ b/crates/codegraph-core/src/types.rs @@ -49,11 +49,12 @@ pub const EDGE_KIND_STRINGS: [&str; 12] = [ "decorates", ]; -pub const LANGUAGE_STRINGS: [&str; 36] = [ +pub const LANGUAGE_STRINGS: [&str; 37] = [ "typescript", "javascript", "tsx", "jsx", + "arkts", "python", "go", "rust", @@ -274,6 +275,8 @@ pub enum Language { Tsx, #[serde(rename = "jsx")] Jsx, + #[serde(rename = "arkts")] + ArkTs, #[serde(rename = "python")] Python, #[serde(rename = "go")] @@ -341,11 +344,12 @@ pub enum Language { } impl Language { - pub const ALL: [Self; 36] = [ + pub const ALL: [Self; 37] = [ Self::TypeScript, Self::JavaScript, Self::Tsx, Self::Jsx, + Self::ArkTs, Self::Python, Self::Go, Self::Rust, @@ -386,6 +390,7 @@ impl Language { Self::JavaScript => "javascript", Self::Tsx => "tsx", Self::Jsx => "jsx", + Self::ArkTs => "arkts", Self::Python => "python", Self::Go => "go", Self::Rust => "rust", diff --git a/crates/codegraph-extract/Cargo.toml b/crates/codegraph-extract/Cargo.toml index baa8b83e..2d3b46d2 100644 --- a/crates/codegraph-extract/Cargo.toml +++ b/crates/codegraph-extract/Cargo.toml @@ -23,6 +23,7 @@ codegraph-core = { path = "../codegraph-core" } serde_json = { workspace = true } tracing = { workspace = true } +tree-sitter-arkts = "0.2.0" tree-sitter-c = "0.24.2" tree-sitter-c-sharp = "0.23.5" tree-sitter-cpp = "0.23.4" diff --git a/crates/codegraph-extract/src/engine.rs b/crates/codegraph-extract/src/engine.rs index aa71de28..054b157a 100644 --- a/crates/codegraph-extract/src/engine.rs +++ b/crates/codegraph-extract/src/engine.rs @@ -52,6 +52,8 @@ pub fn builtin_language_for_ext(ext: &str) -> Option { "tsx" => Language::Tsx, "js" | "mjs" | "cjs" | "xsjs" | "xsjslib" => Language::JavaScript, "jsx" => Language::Jsx, + // Only `.ets` maps to ArkTS; plain `.ts` stays TypeScript (matching upstream). + "ets" => Language::ArkTs, "py" | "pyw" => Language::Python, "go" => Language::Go, "rs" => Language::Rust, @@ -868,7 +870,17 @@ 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(), 36); + assert_eq!(Language::ALL.len(), 37); + } + + #[test] + fn arkts_extension_maps_to_arkts() { + assert_eq!(detect_language("view.ets"), Language::ArkTs); + } + + #[test] + fn plain_ts_stays_typescript() { + assert_eq!(detect_language("m.ts"), Language::TypeScript); } #[test] diff --git a/crates/codegraph-extract/src/lang/arkts.rs b/crates/codegraph-extract/src/lang/arkts.rs new file mode 100644 index 00000000..8f61df38 --- /dev/null +++ b/crates/codegraph-extract/src/lang/arkts.rs @@ -0,0 +1,257 @@ +//! ArkTS (HarmonyOS / OpenHarmony `.ets`) `LanguageSpec`. +//! +//! Extraction-tier port of `upstream extraction/languages/arkts.ts` (commit +//! `9915221`). The ArkTS grammar is a TypeScript-superset fork, so this spec +//! mirrors [`crate::lang::typescript::TYPESCRIPT_SPEC`] verbatim except for two +//! things: +//! +//! - the grammar handle is `tree-sitter-arkts` (which understands the ArkUI +//! `@Component struct` syntax `tree-sitter-typescript` cannot parse); and +//! - `struct_types` returns `["struct_declaration"]` so a `@Component struct` +//! extracts as a [`codegraph_core::types::NodeKind::Struct`]. +//! +//! The ArkUI dynamic-dispatch / callback-synthesizer bridges (attribute-chain +//! resolution, `arkui_component_expression` component-instantiation edges, +//! state->build() re-render, emitter emit->subscriber pairing, router->`@Entry`, +//! the decorator `extractModifiers` hook) are DELIBERATELY DEFERRED — the port +//! has no callback synthesizer. Hence `call_types` is `["call_expression"]` +//! only and `extract_modifiers` is left at the trait default. + +use codegraph_core::types::Language; +use tree_sitter::{Language as TsLanguage, Node}; + +use crate::lang::typescript::class_field_is_callable; +use crate::spec::{ImportInfo, LanguageSpec}; +use crate::walker::{child_by_field, node_text}; + +pub struct ArkTsSpec; + +pub static ARKTS_SPEC: ArkTsSpec = ArkTsSpec; + +impl LanguageSpec for ArkTsSpec { + fn language(&self) -> Language { + Language::ArkTs + } + + fn tree_sitter_language(&self) -> TsLanguage { + tree_sitter_arkts::LANGUAGE.into() + } + + fn function_types(&self) -> &'static [&'static str] { + &[ + "function_declaration", + "arrow_function", + "function_expression", + ] + } + + fn class_types(&self) -> &'static [&'static str] { + &["class_declaration", "abstract_class_declaration"] + } + + fn method_types(&self) -> &'static [&'static str] { + &["method_definition", "public_field_definition"] + } + + fn class_member_is_method(&self, node: Node<'_>, _source: &str) -> bool { + class_field_is_callable(node, "public_field_definition") + } + + fn interface_types(&self) -> &'static [&'static str] { + &["interface_declaration"] + } + + fn struct_types(&self) -> &'static [&'static str] { + &["struct_declaration"] + } + + fn enum_types(&self) -> &'static [&'static str] { + &["enum_declaration"] + } + + fn enum_member_types(&self) -> &'static [&'static str] { + &["property_identifier", "enum_assignment"] + } + + fn type_alias_types(&self) -> &'static [&'static str] { + &["type_alias_declaration"] + } + + fn import_types(&self) -> &'static [&'static str] { + &["import_statement"] + } + + fn call_types(&self) -> &'static [&'static str] { + &["call_expression"] + } + + fn variable_types(&self) -> &'static [&'static str] { + &["lexical_declaration", "variable_declaration"] + } + + fn name_field(&self) -> &'static str { + "name" + } + + fn body_field(&self) -> &'static str { + "body" + } + + fn params_field(&self) -> &'static str { + "parameters" + } + + fn return_field(&self) -> &'static str { + "return_type" + } + + fn resolve_body<'tree>(&self, node: Node<'tree>, body_field: &str) -> Option> { + if node.kind() != "public_field_definition" { + return None; + } + + for i in 0..node.named_child_count() { + let child = node.named_child(i as u32)?; + if child.kind() == "arrow_function" || child.kind() == "function_expression" { + return child_by_field(child, body_field); + } + if child.kind() == "call_expression" { + if let Some(args) = child_by_field(child, "arguments") { + for j in 0..args.named_child_count() { + if let Some(arg) = args.named_child(j as u32) { + if arg.kind() == "arrow_function" || arg.kind() == "function_expression" + { + return child_by_field(arg, body_field); + } + } + } + } + } + } + None + } + + fn get_signature(&self, node: Node<'_>, source: &str) -> Option { + let params = child_by_field(node, "parameters")?; + let mut signature = node_text(params, source); + if let Some(return_type) = child_by_field(node, "return_type") { + signature.push_str(": "); + signature.push_str( + node_text(return_type, source) + .trim_start_matches(':') + .trim_start(), + ); + } + Some(signature) + } + + fn get_visibility(&self, node: Node<'_>) -> Option { + for i in 0..node.child_count() { + let child = node.child(i as u32)?; + if child.kind() == "accessibility_modifier" { + for j in 0..child.child_count() { + let modifier = child.child(j as u32)?; + match modifier.kind() { + "public" => return Some("public".to_string()), + "private" => return Some("private".to_string()), + "protected" => return Some("protected".to_string()), + _ => {} + } + } + } + } + None + } + + fn is_exported(&self, node: Node<'_>, _source: &str) -> bool { + let mut current = node.parent(); + while let Some(parent) = current { + if parent.kind() == "export_statement" { + return true; + } + current = parent.parent(); + } + false + } + + fn is_async(&self, node: Node<'_>) -> bool { + has_direct_child_kind(node, "async") + } + + fn is_static(&self, node: Node<'_>, _source: &str) -> bool { + has_direct_child_kind(node, "static") + } + + fn is_const(&self, node: Node<'_>) -> bool { + node.kind() == "lexical_declaration" && has_direct_child_kind(node, "const") + } + + fn extract_import(&self, node: Node<'_>, source: &str) -> Option { + let source_node = child_by_field(node, "source")?; + let module_name = node_text(source_node, source).replace(['\'', '"'], ""); + if module_name.is_empty() { + return None; + } + Some(ImportInfo { + module_name, + signature: node_text(node, source).trim().to_string(), + handled_refs: false, + }) + } +} + +fn has_direct_child_kind(node: Node<'_>, kind: &str) -> bool { + (0..node.child_count()).any(|i| { + node.child(i as u32) + .is_some_and(|child| child.kind() == kind) + }) +} + +#[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_arkts::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() { + let child = node.named_child(i as u32)?; + if let Some(found) = first_of_kind(child, kind) { + return Some(found); + } + } + None + } + + #[test] + fn arkts_struct_type_is_struct_declaration() { + assert_eq!(ARKTS_SPEC.struct_types(), ["struct_declaration"]); + } + + #[test] + fn arkts_field_constants_match_ts() { + assert_eq!(ARKTS_SPEC.name_field(), "name"); + assert_eq!(ARKTS_SPEC.body_field(), "body"); + assert_eq!(ARKTS_SPEC.params_field(), "parameters"); + assert_eq!(ARKTS_SPEC.return_field(), "return_type"); + } + + #[test] + fn arkts_parses_component_struct() { + let src = "@Component struct MyView { build() { } }"; + let tree = parse(src); + let decl = first_of_kind(tree.root_node(), "struct_declaration") + .expect("tree-sitter-arkts parses @Component struct"); + let name = child_by_field(decl, "name").expect("struct has a name field"); + assert_eq!(node_text(name, src), "MyView"); + } +} diff --git a/crates/codegraph-extract/src/lang/mod.rs b/crates/codegraph-extract/src/lang/mod.rs index 73da4067..8f8396c9 100644 --- a/crates/codegraph-extract/src/lang/mod.rs +++ b/crates/codegraph-extract/src/lang/mod.rs @@ -3,6 +3,7 @@ //! Wave 1c intentionally wires only TypeScript. The module boundary is the //! mechanical porting seam for tasks 14-17. +mod arkts; mod c; mod cpp; mod csharp; @@ -31,6 +32,7 @@ use codegraph_core::types::Language; use crate::spec::LanguageSpec; +pub use arkts::ARKTS_SPEC; pub use c::C_SPEC; pub use cpp::CPP_SPEC; pub(crate) use cpp::{ExportMacroClass, detect_export_macro_class}; @@ -62,6 +64,7 @@ pub fn spec_for_language(language: Language) -> Option<&'static dyn LanguageSpec Language::Tsx => Some(&TSX_SPEC), Language::JavaScript => Some(&JAVASCRIPT_SPEC), Language::Jsx => Some(&JSX_SPEC), + Language::ArkTs => Some(&ARKTS_SPEC), Language::Python => Some(&PYTHON_SPEC), Language::Go => Some(&GO_SPEC), Language::Rust => Some(&RUST_SPEC), diff --git a/crates/codegraph-extract/src/walker.rs b/crates/codegraph-extract/src/walker.rs index 3384bde1..3d4805e5 100644 --- a/crates/codegraph-extract/src/walker.rs +++ b/crates/codegraph-extract/src/walker.rs @@ -3510,6 +3510,37 @@ var topVar: String = "x" assert!(has_node(&nodes, NodeKind::Variable, "topVar")); } + // ---- ArkTS (.ets) extraction tier ---- + + #[test] + fn arkts_extracts_struct_function_class_import_call() { + let src = r#" +import { Foo } from '../foo'; + +function helper(): void {} + +function driver(): void { + helper() +} + +@Component +struct MyView { + build() { + helper() + } +} + +class Model {} +"#; + let (nodes, refs) = run("src/component.ets", src, Language::ArkTs); + assert!(has_node(&nodes, NodeKind::Struct, "MyView")); + assert!(has_node(&nodes, NodeKind::Function, "helper")); + assert!(has_node(&nodes, NodeKind::Class, "Model")); + assert!(has_node(&nodes, NodeKind::Import, "../foo")); + assert!(has_ref(&refs, EdgeKind::Imports, "../foo")); + assert!(has_ref(&refs, EdgeKind::Calls, "helper")); + } + // ---- Lua / Luau require variants ---- #[test] diff --git a/crates/codegraph-store/src/queries.rs b/crates/codegraph-store/src/queries.rs index 0aa84af2..f6bdcc3a 100644 --- a/crates/codegraph-store/src/queries.rs +++ b/crates/codegraph-store/src/queries.rs @@ -1500,6 +1500,7 @@ fn parse_language(value: String) -> rusqlite::Result { "javascript" => Language::JavaScript, "tsx" => Language::Tsx, "jsx" => Language::Jsx, + "arkts" => Language::ArkTs, "python" => Language::Python, "go" => Language::Go, "rust" => Language::Rust, diff --git a/docs/equivalence.md b/docs/equivalence.md index 3a15ba2e..9936318a 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -366,6 +366,46 @@ The `generated_golden_matches_committed_{metal,cuda}_fixture` and `{metal,cuda}_db_is_self_equivalent_to_{metal,cuda}_golden` tests in `crates/codegraph-bench/tests/equivalence.rs` enforce byte-stability. +### ArkTS fixture + +A seventh golden fixture, `reference/golden/arkts/`, guards ArkTS (HarmonyOS / +OpenHarmony `.ets`) extraction (the extraction slice of upstream #1186 / +`9915221`). Unlike Metal/CUDA, ArkTS is a **new `Language::ArkTs` variant** backed +by a **dedicated `tree-sitter-arkts` grammar** — a TypeScript-superset fork that +understands the ArkUI `@Component struct` syntax `tree-sitter-typescript` cannot +parse. `.ets` maps to `Language::ArkTs`; plain `.ts` stays TypeScript. The corpus +(`crates/codegraph-bench/fixtures/arkts/component.ets`) has an `import`, a global +`function helper`, a `function driver` that calls `helper`, a `@Component struct +MyView` with a `build()` method, and a plain `class Model`. The golden must show: + +- `component.ets` with `"language": "arkts"`; +- `MyView` as a `NodeKind::Struct` with its `build` method as a member (via the + existing `extract_struct` path — no walker change); +- `helper`/`driver` functions, the `Model` class, and the `../foo` import node; +- the `driver` → `helper` `Calls` edge (plain `call_expression`). + +The ArkUI dynamic-dispatch / callback-synthesizer bridges are DEFERRED — the +port has no callback synthesizer. So `ARKTS_SPEC` uses `call_types = +["call_expression"]` only (no `arkui_component_expression` component-instantiation +edges) and does NOT override `extract_modifiers` (the decorator hook). Adding the +variant is byte-neutral for `colby.schema.sql` (language is a stored TEXT value, +not DDL) and for the six existing goldens (none holds a `.ets` file). + +Regenerate reproducibly (identical recipe to the C++ fixture, substituting +`arkts`): + +```bash +rm -rf /tmp/cg-fixture-arkts && cp -r crates/codegraph-bench/fixtures/arkts /tmp/cg-fixture-arkts +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 ./target/release/codegraph init /tmp/cg-fixture-arkts +cp /tmp/cg-fixture-arkts/.codegraph/codegraph.db reference/golden/arkts/colby.db +cargo run -p codegraph-bench --bin bench -- --gen-golden reference/golden/arkts/colby.db reference/golden/arkts +``` + +The `generated_golden_matches_committed_arkts_fixture` and +`arkts_db_is_self_equivalent_to_arkts_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 16002842..630a4942 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. -**32 concrete languages** are supported, grouped into three extraction tiers based on what +**33 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 (23 languages) +## Tier 1 — Full symbol extraction (24 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 @@ -26,6 +26,7 @@ level. | TSX | `.tsx` | Full tree-sitter | TypeScript grammar, JSX syntax | | JavaScript | `.js` `.mjs` `.cjs` `.xsjs` `.xsjslib` | Full tree-sitter | | | JSX | `.jsx` | Full tree-sitter | JavaScript grammar, JSX syntax | +| ArkTS | `.ets` | Full tree-sitter | HarmonyOS / OpenHarmony; `tree-sitter-arkts` grammar. `@Component struct` → struct symbol. ArkUI dynamic-dispatch bridges deferred. Plain `.ts` stays TypeScript | | Python | `.py` `.pyw` | Full tree-sitter | | | Go | `.go` | Full tree-sitter | | | Rust | `.rs` | Full tree-sitter | | diff --git a/reference/golden/arkts/colby.db b/reference/golden/arkts/colby.db new file mode 100644 index 0000000000000000000000000000000000000000..84e0368d26be00483be0c95f1146ea7b7d538e2f GIT binary patch literal 151552 zcmeI5ZIB#Cd4Okj_WQKkk|k>`i$fz>&fcKA)9!ujeK-m^Nh^7+)15ip*%G2yW@lzk zW9{vpW@k@2yBy~%9H_t#Qh`c-#6?k+#Q8y>65t1cq@Y47R04!5st6_+2!w=!5JEyA z6;n~(?w*<5*^j%EW9&nIx9)ak`s01OpYERSw|lnd!kcDI+mOpOYelu?QDL_b2nfF_ z%YqJ}A@ws=8tf%GVld#VnhKUgXz$O{+sPs>_3N-CVA!cEd6hCh(D&*`@pid0;O8 z=&&P(o>Ect$fMJkTB;a4i;&u)R;!jF5e!H3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m1Sn}R(j zbmso@w40efN z>0y_+le*fH@PF*cBFo2zQOj5~7q zBy5|fGY8v!lrGOKEzTF_ApZIM+#(+uwoYeto0|1cwrw7Q<%~`Jy0f=j2OaErR)gOQ zW`KJ6s8!vh)53M86y}MBV$6QxZWsvS>ic4Gry28oSman+Ols7R*@I-XYvdAxl=F?!b=vW2k9WnvF1yvftvYH~3I&TzkYMXftQ{CvA- zoo9wxfIZ;1%t7`D!N$eir|h|O3IVLxMzuMo@0Lr3hcGOwX7SQ(D_lj1gy|T$$DBW7 zQ_QkM?BP(DHl0h1rn5XyH?B44YZOxVR4!bq*kJfIIMcKwmcrErNMEB<{Ac9?G{pV zb;eiedHT0o-MI>%0G`e53WzJutOZzUysO2?W(_RpD-Gt?l=t`f~fWNs7+xNhPaQiZgMuqHH{hULu2~RCGfY_d9%A9ms8}MC)VPueTod}mHwxrq z{rvgDHf;}M19qu02nOL`)wniTt=NNA9lq-7%4)?>&fU*sUv8J3ZIPY5ub1qsC!1?D#+D4h|Cl literal 0 HcmV?d00001 diff --git a/reference/golden/arkts/edges.json b/reference/golden/arkts/edges.json new file mode 100644 index 00000000..9a31faa5 --- /dev/null +++ b/reference/golden/arkts/edges.json @@ -0,0 +1,80 @@ +[ + { + "col": 0, + "kind": "imports", + "line": 1, + "metadata": { + "confidence": 0.95, + "resolvedBy": "qualified-name" + }, + "provenance": null, + "source": "file:component.ets", + "target": "import:eca17bdaf3571afb1380fcbafbd2f969" + }, + { + "col": 2, + "kind": "calls", + "line": 6, + "metadata": { + "confidence": 0.9, + "resolvedBy": "exact-match" + }, + "provenance": null, + "source": "function:3ccec0adbbb469e92ba0541ff466fb6c", + "target": "function:190c728c90d859bafe85fc2d9d2aea72" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:component.ets", + "target": "class:aa3d6482b1bf9e80c79908cd6c508866" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:component.ets", + "target": "function:190c728c90d859bafe85fc2d9d2aea72" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:component.ets", + "target": "function:3ccec0adbbb469e92ba0541ff466fb6c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:component.ets", + "target": "import:eca17bdaf3571afb1380fcbafbd2f969" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:component.ets", + "target": "struct:bcf7186acd3422af32e5f0c6f566b4e2" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:bcf7186acd3422af32e5f0c6f566b4e2", + "target": "method:1ae7cb887c6ff76065390c4dd3100c38" + } +] diff --git a/reference/golden/arkts/files.json b/reference/golden/arkts/files.json new file mode 100644 index 00000000..ebca10c9 --- /dev/null +++ b/reference/golden/arkts/files.json @@ -0,0 +1,10 @@ +[ + { + "content_hash": "1299fbd03b9bf9cbbd560ce133ea00f5646f35e4574cc6e92123969de1608b80", + "errors": null, + "language": "arkts", + "node_count": 7, + "path": "component.ets", + "size": 173 + } +] diff --git a/reference/golden/arkts/nodes.json b/reference/golden/arkts/nodes.json new file mode 100644 index 00000000..23185d3e --- /dev/null +++ b/reference/golden/arkts/nodes.json @@ -0,0 +1,156 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 14, + "end_line": 16, + "file_path": "component.ets", + "id": "class:aa3d6482b1bf9e80c79908cd6c508866", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "class", + "language": "arkts", + "name": "Model", + "qualified_name": "Model", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 16, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 17, + "file_path": "component.ets", + "id": "file:component.ets", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "arkts", + "name": "component.ets", + "qualified_name": "component.ets", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 26, + "end_line": 3, + "file_path": "component.ets", + "id": "function:190c728c90d859bafe85fc2d9d2aea72", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "arkts", + "name": "helper", + "qualified_name": "helper", + "return_type": null, + "signature": "(): void", + "start_column": 0, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 7, + "file_path": "component.ets", + "id": "function:3ccec0adbbb469e92ba0541ff466fb6c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "function", + "language": "arkts", + "name": "driver", + "qualified_name": "driver", + "return_type": null, + "signature": "(): void", + "start_column": 0, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 29, + "end_line": 1, + "file_path": "component.ets", + "id": "import:eca17bdaf3571afb1380fcbafbd2f969", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "import", + "language": "arkts", + "name": "../foo", + "qualified_name": "../foo", + "return_type": null, + "signature": "import { Foo } from '../foo';", + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 3, + "end_line": 13, + "file_path": "component.ets", + "id": "method:1ae7cb887c6ff76065390c4dd3100c38", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "arkts", + "name": "build", + "qualified_name": "MyView::build", + "return_type": null, + "signature": "()", + "start_column": 2, + "start_line": 11, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 14, + "file_path": "component.ets", + "id": "struct:bcf7186acd3422af32e5f0c6f566b4e2", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "struct", + "language": "arkts", + "name": "MyView", + "qualified_name": "MyView", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 9, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/arkts/refs.json b/reference/golden/arkts/refs.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/reference/golden/arkts/refs.json @@ -0,0 +1 @@ +[] diff --git a/reference/golden/arkts/schema.sql b/reference/golden/arkts/schema.sql new file mode 100644 index 00000000..d36218fe --- /dev/null +++ b/reference/golden/arkts/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);