lean_ctx/tools/
ctx_repomap.rs1use crate::core::repomap;
4
5pub fn handle(
12 project_root: &str,
13 max_tokens: usize,
14 focus_files: &[String],
15 session_files: &[String],
16) -> String {
17 let graph = repomap::RepoGraph::build(project_root);
18
19 if graph.files.is_empty() {
20 return format!(
21 "No indexable files found in '{project_root}'. \
22 Ensure it contains source files (.rs, .ts, .py, etc.)."
23 );
24 }
25
26 let ranked = repomap::rank_symbols(&graph, session_files, focus_files);
27
28 if ranked.is_empty() {
29 return format!(
30 "No symbols extracted from {} files in '{project_root}'.",
31 graph.files.len()
32 );
33 }
34
35 repomap::fit_to_budget(&ranked, max_tokens)
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn nonexistent_root_returns_helpful_message() {
44 let result = handle("/tmp/nonexistent_repo_map_test_dir", 2048, &[], &[]);
45 assert!(
46 result.contains("No indexable files") || result.contains("No symbols"),
47 "unexpected: {result}"
48 );
49 }
50}