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
20 changes: 17 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i
`reference/golden/cpp/`
(corpus `crates/codegraph-bench/fixtures/cpp/`; guards #1043 C++ class/struct
inheritance incl. templated-base stripping byte-for-byte, and retroactively
the earlier C++ extraction work).
the earlier C++ extraction work; grown to 17 files by Tier 3 with the MSVC COM
`interface` positives + five guard negatives (#1519) and the C / C++ / ObjC
`union` fixtures incl. both `typedef union` re-kinds and both instantiation
paths (PR #1516) — it is the C-FAMILY corpus, not a strictly-C++ one, since it
holds `.c` and `.mm` files too), and `reference/golden/rust/`
(corpus `crates/codegraph-bench/fixtures/rust/`; the repo's only Rust corpus,
guards #1513/PR #1514 unit structs — 3 `struct` nodes and 4 `implements` edges,
where the unit struct produced NO node before — plus the Rust half of PR #1516's
first-class `union` kind, byte-for-byte; it deliberately claims NO `instantiates`
edge, because that edge fires only for the call-expression construction form and
a Rust union is constructible only as `U { … }`).
The Python cross-file edge is resolved by Gate 3a's unique-name fallback;
import Gate 3b is deliberately unreachable for real Python nodes because the
extractor does not mark them exported. Regen recipe: `docs/equivalence.md`
"Godot fixture" / "Ruby fixture" / "Python fixture" / "Kotlin fixture" /
"TypeScript resolution fixture" / "C++ fixture" sections.
"TypeScript resolution fixture" / "C++ fixture" / "Rust fixture" sections.
- **node-id formula**: `{kind}:{sha256("{filePath}:{kind}:{name}:{line}").hex[:32]}`; file nodes are the
literal `file:{relpath}`; lines are 1-based; paths relative with `/`.
- **No AI / vector / LLM crates** — enforced by `scripts/guardrail.sh` (CI gate):
Expand All @@ -45,7 +55,11 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i

`codegraph-core` (types/config/logger) · `codegraph-store` (SQLite+FTS5) · `codegraph-extract`
(tree-sitter walker + embedded + custom extractors; incl. C++ `base_class_clause` → `Extends`
inheritance extraction with templated-base stripping, #1043) · `codegraph-graph` (traversal + FTS search) ·
inheritance extraction with templated-base stripping, #1043; a shared `extract_aggregate` behind
`extract_struct`/`extract_union` so the `union` kind — C/C++/ObjC `union_specifier`, Rust
`union_item`, PR #1516 — inherits struct behaviour by construction, plus the opt-in
`allow_bodiless_struct()` that makes a Rust `struct Unit;` a definition rather than a forward
declaration, #1513) · `codegraph-graph` (traversal + FTS search) ·
`codegraph-resolve` (import + name matcher + FrameworkResolver; concrete `GodotResolver` impl — autoload-call + signal-handler resolution) · `codegraph-mcp`
(stdio JSON-RPC; `codegraph_explore` runs a change-surface rescue, #1064, that surfaces a
callable's buried parameter/return-type files into the explored subgraph; every source-emitting
Expand Down
20 changes: 20 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/com_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct SControl : IBase {
virtual void Ping() = 0;
void Run() { }
};

interface IWidget : IBase {
virtual void Ping() = 0;
void Run() { }
};

interface IPlain {
virtual void Ping() = 0;
};

interface INewlineBrace
{
virtual void Ping() = 0;
};

int interface_count = 0;
4 changes: 4 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/instantiate_agg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
union Reg { int raw; float val; };
struct Ctl { int id; };
void mk_union() { Reg r = Reg(); (void)r; }
void mk_struct() { Ctl c = Ctl(); (void)c; }
5 changes: 5 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/instantiate_rank.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
union Value { int i; float f; };
struct Packet { int id; };
void Value() { }
void ctor_union() { Value v{1}; (void)v; }
void ctor_struct() { Packet p{2}; (void)p; }
11 changes: 11 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/neg_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
interface INegComment;
*/
interface class INegCli { public: virtual void B()=0; };
interface struct INegStructKw { int x; };
const char* idl = R"(
interface INegGhost { virtual void B() = 0; };
)";
#define NEG_DECL \
interface INegMacro
struct NegReal { int x; };
9 changes: 9 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/union_agg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
union Named { int i; float f; };
struct Ctl { int x; };
typedef union { int a; float b; } AnonU;
typedef struct { int a; int b; } AnonS;
typedef union NamedTag { int c; } NamedU;
union Fwd;
struct FwdS;
union { int q; } anon_var;
int read_named(union Named *p) { return p->i; }
10 changes: 10 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/union_agg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
union WithMethod {
int i; float f;
int read_field() { return i; }
};
struct SWithMethod {
int i;
int read_field() { return i; }
};
void drive_union() { WithMethod w; w.read_field(); }
void drive_struct() { SWithMethod s; s.read_field(); }
2 changes: 2 additions & 0 deletions crates/codegraph-bench/fixtures/cpp/union_agg.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union ObjcU { int i; float f; };
struct ObjcS { int i; };
9 changes: 9 additions & 0 deletions crates/codegraph-bench/fixtures/rust/consumer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::{Bits, Greet, UnitStruct};

pub fn describe_unit(u: &UnitStruct) -> String {
u.greet()
}

pub fn describe_bits(b: &Bits) -> String {
b.greet()
}
54 changes: 54 additions & 0 deletions crates/codegraph-bench/fixtures/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
pub trait Greet {
fn greet(&self) -> String;
}

pub struct UnitStruct;

pub struct BraceStruct {
pub x: u32,
}

pub struct TupleStruct(pub u8);

impl Greet for UnitStruct {
fn greet(&self) -> String {
"unit".to_string()
}
}

impl Greet for BraceStruct {
fn greet(&self) -> String {
"brace".to_string()
}
}

impl Greet for TupleStruct {
fn greet(&self) -> String {
"tuple".to_string()
}
}

pub union Bits {
pub i: u32,
pub f: f32,
}

impl Bits {
pub fn raw(&self) -> u32 {
unsafe { self.i }
}
}

impl Greet for Bits {
fn greet(&self) -> String {
"bits".to_string()
}
}

pub fn make_unit() -> UnitStruct {
UnitStruct
}

pub fn make_bits() -> Bits {
Bits { i: 0 }
}
26 changes: 26 additions & 0 deletions crates/codegraph-bench/tests/equivalence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ fn cpp_db_is_self_equivalent_to_cpp_golden() {
assert_equivalent(&cpp_db(), &cpp_golden_dir()).unwrap();
}

#[test]
fn generated_golden_matches_committed_rust_fixture() {
// Guards item 7 (Rust unit structs are indexed, so `impl Trait for Unit`
// forms) and item 9-Rust (`union` is a first-class kind) against byte-drift.
let tempdir = TestDir::new("generated-golden-rust");
write_golden(&rust_db(), tempdir.path()).unwrap();

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

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

#[test]
fn rust_db_is_self_equivalent_to_rust_golden() {
assert_equivalent(&rust_db(), &rust_golden_dir()).unwrap();
}

#[test]
fn generated_golden_matches_committed_python_fixture() {
let tempdir = TestDir::new("generated-golden-python");
Expand Down Expand Up @@ -412,6 +430,14 @@ fn cpp_golden_dir() -> PathBuf {
workspace_root().join("reference/golden/cpp")
}

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

fn rust_golden_dir() -> PathBuf {
workspace_root().join("reference/golden/rust")
}

fn python_db() -> PathBuf {
workspace_root().join("reference/golden/python/colby.db")
}
Expand Down
11 changes: 9 additions & 2 deletions crates/codegraph-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use std::fmt;
// protocol, function, method, property, field, variable, constant, enum,
// enum_member, type_alias, namespace, parameter, import, export, route,
// component.
// `union` is APPENDED (upstream PR #1516): appending keeps every other
// variant's discriminant, and therefore every existing node id, stable.
// EdgeKind lines 48-60: contains, calls, imports, exports, extends,
// implements, references, type_of, returns, instantiates, overrides,
// decorates.
pub const NODE_KIND_STRINGS: [&str; 22] = [
pub const NODE_KIND_STRINGS: [&str; 23] = [
"file",
"module",
"class",
Expand All @@ -32,6 +34,7 @@ pub const NODE_KIND_STRINGS: [&str; 22] = [
"export",
"route",
"component",
"union",
];

pub const EDGE_KIND_STRINGS: [&str; 12] = [
Expand Down Expand Up @@ -140,10 +143,12 @@ pub enum NodeKind {
Route,
#[serde(rename = "component")]
Component,
#[serde(rename = "union")]
Union,
}

impl NodeKind {
pub const ALL: [Self; 22] = [
pub const ALL: [Self; 23] = [
Self::File,
Self::Module,
Self::Class,
Expand All @@ -166,6 +171,7 @@ impl NodeKind {
Self::Export,
Self::Route,
Self::Component,
Self::Union,
];

pub const fn as_str(self) -> &'static str {
Expand All @@ -192,6 +198,7 @@ impl NodeKind {
Self::Export => "export",
Self::Route => "route",
Self::Component => "component",
Self::Union => "union",
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/codegraph-extract/src/lang/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ impl LanguageSpec for CSpec {
fn struct_types(&self) -> &'static [&'static str] {
&["struct_specifier"]
}
fn union_types(&self) -> &'static [&'static str] {
&["union_specifier"]
}
fn enum_types(&self) -> &'static [&'static str] {
&["enum_specifier"]
}
Expand Down Expand Up @@ -77,6 +80,9 @@ impl LanguageSpec for CSpec {
if child.kind() == "struct_specifier" && child_by_field(child, "body").is_some() {
return Some(NodeKind::Struct);
}
if child.kind() == "union_specifier" && child_by_field(child, "body").is_some() {
return Some(NodeKind::Union);
}
}
None
}
Expand Down
Loading
Loading