Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 35 languages (TypeScript,
**Does:** deterministic code-structure extraction across 36 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
Expand All @@ -454,9 +454,9 @@ beyond the fixed `LANGUAGES` set.

## Supported Languages

CodeGraph supports **35 languages** grouped by extraction depth. Quick overview:
CodeGraph supports **36 languages** grouped by extraction depth. Quick overview:

- **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 1 — Full symbol extraction (27):** 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, Terraform, 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.

Expand Down
30 changes: 30 additions & 0 deletions crates/codegraph-bench/fixtures/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
terraform {}

provider "aws" {}

variable "region" {}

locals {
name = "demo"
tagged = var.region
}

data "aws_ami" "ubuntu" {}

resource "aws_s3_bucket" "b" {
bucket = var.region
kms_key_id = aws_kms_key.logs.arn
}

module "vpc" {
source = "./vpc"
region = var.region
}

output "bucket_id" {
value = aws_s3_bucket.b.id
}

output "vpc_id" {
value = module.vpc.id
}
33 changes: 33 additions & 0 deletions crates/codegraph-bench/tests/equivalence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ fn nix_db_is_self_equivalent_to_nix_golden() {
assert_equivalent(&nix_db(), &nix_golden_dir()).unwrap();
}

#[test]
fn generated_golden_matches_committed_terraform_fixture() {
// Guards Terraform/HCL extraction (upstream #1173, extraction slice only):
// the `.tf`/`.tfvars`/`.tofu`->Terraform mapping, block-type dispatch
// (resource/data->Class, module->Module, variable/output->Variable,
// provider->Namespace, locals->Constant per attr) with qualified names, and
// plain attribute-expression traversal refs
// (var.X/local.X/module.M/data.T.N/<type>.<name>)->References with built-ins
// skipped. The module-boundary TerraformResolver, emitModuleWiring's
// :-scoped refs, and the .tfvars var ref are DEFERRED, so no :-scoped ref is
// emitted; the undeclared aws_kms_key.logs stays unresolved.
let tempdir = TestDir::new("generated-golden-terraform");
write_golden(&terraform_db(), tempdir.path()).unwrap();

let expected = load_golden(&terraform_golden_dir()).unwrap();
let actual = load_golden(tempdir.path()).unwrap();

diff_canonical(&expected, &actual, None).unwrap();
}

#[test]
fn terraform_db_is_self_equivalent_to_terraform_golden() {
assert_equivalent(&terraform_db(), &terraform_golden_dir()).unwrap();
}

#[test]
fn tier1_node_drift_is_reported() {
let expected = load_golden(&mini_golden_dir()).unwrap();
Expand Down Expand Up @@ -297,6 +322,14 @@ fn nix_golden_dir() -> PathBuf {
workspace_root().join("reference/golden/nix")
}

fn terraform_db() -> PathBuf {
workspace_root().join("reference/golden/terraform/colby.db")
}

fn terraform_golden_dir() -> PathBuf {
workspace_root().join("reference/golden/terraform")
}

struct TestDir {
path: PathBuf,
}
Expand Down
9 changes: 7 additions & 2 deletions crates/codegraph-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub const EDGE_KIND_STRINGS: [&str; 12] = [
"decorates",
];

pub const LANGUAGE_STRINGS: [&str; 39] = [
pub const LANGUAGE_STRINGS: [&str; 40] = [
"typescript",
"javascript",
"tsx",
Expand Down Expand Up @@ -80,6 +80,7 @@ pub const LANGUAGE_STRINGS: [&str; 39] = [
"r",
"solidity",
"nix",
"terraform",
"yaml",
"twig",
"xml",
Expand Down Expand Up @@ -329,6 +330,8 @@ pub enum Language {
Solidity,
#[serde(rename = "nix")]
Nix,
#[serde(rename = "terraform")]
Terraform,
#[serde(rename = "yaml")]
Yaml,
#[serde(rename = "twig")]
Expand All @@ -350,7 +353,7 @@ pub enum Language {
}

impl Language {
pub const ALL: [Self; 39] = [
pub const ALL: [Self; 40] = [
Self::TypeScript,
Self::JavaScript,
Self::Tsx,
Expand Down Expand Up @@ -381,6 +384,7 @@ impl Language {
Self::R,
Self::Solidity,
Self::Nix,
Self::Terraform,
Self::Yaml,
Self::Twig,
Self::Xml,
Expand Down Expand Up @@ -424,6 +428,7 @@ impl Language {
Self::R => "r",
Self::Solidity => "solidity",
Self::Nix => "nix",
Self::Terraform => "terraform",
Self::Yaml => "yaml",
Self::Twig => "twig",
Self::Xml => "xml",
Expand Down
1 change: 1 addition & 0 deletions crates/codegraph-extract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tree-sitter-css = "0.25.0"
tree-sitter-dart = "0.2.0"
tree-sitter-go = "0.25.0"
tree-sitter-gdscript = "6.1.0"
tree-sitter-hcl = "1.1.0"
tree-sitter-html = "0.23.2"
tree-sitter-java = "0.23.5"
tree-sitter-javascript = "0.25.0"
Expand Down
10 changes: 9 additions & 1 deletion crates/codegraph-extract/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn builtin_language_for_ext(ext: &str) -> Option<Language> {
"r" => Language::R,
"sol" => Language::Solidity,
"nix" => Language::Nix,
"tf" | "tfvars" | "tofu" => Language::Terraform,
"yml" | "yaml" => Language::Yaml,
"twig" => Language::Twig,
"xml" => Language::Xml,
Expand Down Expand Up @@ -872,7 +873,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(), 39);
assert_eq!(Language::ALL.len(), 40);
}

#[test]
Expand All @@ -890,6 +891,13 @@ mod tests {
assert_eq!(detect_language("flake.nix"), Language::Nix);
}

#[test]
fn terraform_extensions_map_to_terraform() {
assert_eq!(detect_language("main.tf"), Language::Terraform);
assert_eq!(detect_language("prod.tfvars"), Language::Terraform);
assert_eq!(detect_language("main.tofu"), Language::Terraform);
}

#[test]
fn plain_ts_stays_typescript() {
assert_eq!(detect_language("m.ts"), Language::TypeScript);
Expand Down
7 changes: 7 additions & 0 deletions crates/codegraph-extract/src/lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod rust;
mod scala;
mod solidity;
mod swift;
mod terraform;
mod tsx;
mod typescript;

Expand Down Expand Up @@ -64,6 +65,11 @@ pub use rust::RUST_SPEC;
pub use scala::SCALA_SPEC;
pub use solidity::SOLIDITY_SPEC;
pub use swift::SWIFT_SPEC;
pub use terraform::TERRAFORM_SPEC;
pub(crate) use terraform::{
TerraformBlockDecl, collect_terraform_references, describe_terraform_block,
read_terraform_block_header, terraform_block_body,
};
pub use tsx::TSX_SPEC;
pub use typescript::TYPESCRIPT_SPEC;

Expand Down Expand Up @@ -94,6 +100,7 @@ pub fn spec_for_language(language: Language) -> Option<&'static dyn LanguageSpec
Language::R => Some(&R_SPEC),
Language::Solidity => Some(&SOLIDITY_SPEC),
Language::Nix => Some(&NIX_SPEC),
Language::Terraform => Some(&TERRAFORM_SPEC),
Language::Gdscript => Some(&GDSCRIPT_SPEC),
_ => None,
}
Expand Down
Loading
Loading