use anyhow::Result;
use kodegraf_core::config::Config;
use kodegraf_core::graph::GraphStore;
pub fn run(query: &str) -> Result<()> {
let repo_root = kodegraf_core::config::find_repo_root()?;
let db_path = Config::graph_db_path(&repo_root);
if !db_path.exists() {
anyhow::bail!("Graph not built. Run `kodegraf init && kodegraf build` first.");
}
let store = GraphStore::open(&db_path)?;
let results = store.search_nodes(query, 20)?;
if results.is_empty() {
println!("No symbols found matching '{}'", query);
return Ok(());
}
println!("Found {} symbol(s) matching '{}':", results.len(), query);
println!();
for node in &results {
println!(
" {} {} ({})",
match node.kind {
kodegraf_core::models::NodeKind::File => "๐",
kodegraf_core::models::NodeKind::Class => "๐ท",
kodegraf_core::models::NodeKind::Function => "๐น",
kodegraf_core::models::NodeKind::Type => "๐ธ",
kodegraf_core::models::NodeKind::Enum => "๐ป",
kodegraf_core::models::NodeKind::Constant => "๐",
kodegraf_core::models::NodeKind::Test => "๐งช",
},
node.qualified_name,
node.kind.as_str(),
);
if let (Some(start), Some(end)) = (node.line_start, node.line_end) {
println!(" {}:{}-{}", node.file_path, start, end);
}
if let Some(sig) = &node.signature {
println!(" {}", sig);
}
println!();
}
Ok(())
}