Skip to main content

ralph/tools/
symbol_tools.rs

1use crate::symbol_index::SymbolIndex;
2
3/// Search the index for symbols matching `query` (case-insensitive, substring).
4pub fn find_symbol(index: &SymbolIndex, query: &str) -> String {
5    let results = index.find(query, 20);
6    if results.is_empty() {
7        return format!(
8            "No symbols found matching '{}'. Try a shorter or different term.",
9            query
10        );
11    }
12    let mut out = format!(
13        "Found {} symbol(s) matching '{}':\n\n",
14        results.len(),
15        query
16    );
17    for sym in &results {
18        out.push_str(&format!(
19            "  {} {}  —  {}:{}\n",
20            sym.kind,
21            sym.name,
22            sym.file.display(),
23            sym.line_start,
24        ));
25    }
26    out
27}
28
29/// Return the source body of the first symbol named `name` (exact, case-insensitive).
30pub fn read_symbol(index: &SymbolIndex, name: &str) -> String {
31    match index.read_body(name) {
32        Some(body) => body,
33        None => format!(
34            "Symbol '{}' not found. Use find_symbol to search by partial name.",
35            name
36        ),
37    }
38}