Skip to content
Merged
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
16 changes: 11 additions & 5 deletions crates/codegraph-core/src/edge_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ use napi_derive::napi;

use crate::import_resolution;

/// Kind sets for hierarchy edge resolution -- mirrors the JS constants in
/// `build-edges.js` (`HIERARCHY_SOURCE_KINDS`, `EXTENDS_TARGET_KINDS`,
/// `IMPLEMENTS_TARGET_KINDS`). Keeping them in one place prevents the
/// native/WASM drift that caused the original parity bug.
const HIERARCHY_SOURCE_KINDS: &[&str] = &["class", "struct", "record", "enum"];
const EXTENDS_TARGET_KINDS: &[&str] = &["class", "struct", "trait", "record"];
const IMPLEMENTS_TARGET_KINDS: &[&str] = &["interface", "trait", "class"];

#[napi(object)]
pub struct NodeInfo {
pub id: u32,
Expand Down Expand Up @@ -339,16 +347,14 @@ pub fn build_call_edges(
for cls in &file_input.classes {
let source_row = nodes_by_name_and_file
.get(&(cls.name.as_str(), rel_path.as_str()))
.and_then(|v| v.iter().find(|n| {
n.kind == "class" || n.kind == "struct" || n.kind == "record" || n.kind == "enum"
}));
.and_then(|v| v.iter().find(|n| HIERARCHY_SOURCE_KINDS.contains(&n.kind.as_str())));

if let Some(source) = source_row {
if let Some(ref extends_name) = cls.extends {
let targets = nodes_by_name
.get(extends_name.as_str())
.map(|v| v.iter().filter(|n| {
n.kind == "class" || n.kind == "struct" || n.kind == "trait" || n.kind == "record"
EXTENDS_TARGET_KINDS.contains(&n.kind.as_str())
}).collect::<Vec<_>>())
.unwrap_or_default();
for t in targets {
Expand All @@ -366,7 +372,7 @@ pub fn build_call_edges(
.get(implements_name.as_str())
.map(|v| {
v.iter()
.filter(|n| n.kind == "interface" || n.kind == "class" || n.kind == "trait")
.filter(|n| IMPLEMENTS_TARGET_KINDS.contains(&n.kind.as_str()))
.collect::<Vec<_>>()
})
.unwrap_or_default();
Expand Down
Loading