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 00000000..84e0368d Binary files /dev/null and b/reference/golden/arkts/colby.db differ 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);