1+ use crate :: core:: embedding:: EmbeddingEngine ;
2+ use crate :: core:: graph:: DependencyGraph ;
3+ use crate :: core:: symbol:: SymbolRef ;
4+ use crate :: core:: vector_store:: VectorStore ;
5+ use crate :: db:: ContextDb ;
16use anyhow:: Result ;
27use console:: style;
38use std:: collections:: { HashMap , HashSet } ;
49use std:: fs:: { self , File } ;
510use std:: io:: Write ;
611use std:: path:: Path ;
7- use crate :: core:: embedding:: EmbeddingEngine ;
8- use crate :: core:: graph:: DependencyGraph ;
9- use crate :: core:: symbol:: SymbolRef ;
10- use crate :: core:: vector_store:: VectorStore ;
11- use crate :: db:: ContextDb ;
1212
1313pub struct ContextGenerator ;
1414
@@ -22,7 +22,10 @@ impl ContextGenerator {
2222 }
2323
2424 if !db_dir. exists ( ) {
25- eprintln ! ( "{}" , style( "Error: Database not found. Run 'amdb init' first." ) . red( ) ) ;
25+ eprintln ! (
26+ "{}" ,
27+ style( "Error: Database not found. Run 'amdb init' first." ) . red( )
28+ ) ;
2629 std:: process:: exit ( 1 ) ;
2730 }
2831
@@ -49,7 +52,10 @@ impl ContextGenerator {
4952 for file in & all_files {
5053 if let Ok ( symbols) = db. get_symbols ( file) {
5154 for sym in symbols {
52- symbol_to_files. entry ( sym. name ) . or_default ( ) . push ( file. clone ( ) ) ;
55+ symbol_to_files
56+ . entry ( sym. name )
57+ . or_default ( )
58+ . push ( file. clone ( ) ) ;
5359 }
5460 }
5561 }
@@ -61,13 +67,25 @@ impl ContextGenerator {
6167 let safe_name = query. replace ( " " , "-" ) . replace ( "/" , "-" ) . to_lowercase ( ) ;
6268 output_filename = format ! ( "{}.md" , safe_name) ;
6369
64- println ! ( "{}" , style( format!( "Filtering context for: '{}' with depth {}..." , query, depth) ) . cyan( ) ) ;
70+ println ! (
71+ "{}" ,
72+ style( format!(
73+ "Filtering context for: '{}' with depth {}..." ,
74+ query, depth
75+ ) )
76+ . cyan( )
77+ ) ;
6578
6679 let embedder = EmbeddingEngine :: new ( ) ?;
67- let paths = Self :: resolve_focus_targets ( db_dir, & all_files, & db, query, & embedder, & graph) . await ?;
80+ let paths =
81+ Self :: resolve_focus_targets ( db_dir, & all_files, & db, query, & embedder, & graph)
82+ . await ?;
6883
6984 if paths. is_empty ( ) {
70- println ! ( "{}" , style( "No matches found. Falling back to full context." ) . yellow( ) ) ;
85+ println ! (
86+ "{}" ,
87+ style( "No matches found. Falling back to full context." ) . yellow( )
88+ ) ;
7189 target_files = all_files;
7290 } else {
7391 let mut file_graph: HashMap < String , HashSet < String > > = HashMap :: new ( ) ;
@@ -76,7 +94,10 @@ impl ContextGenerator {
7694 if let Some ( callee_files) = symbol_to_files. get ( & edge. callee ) {
7795 for callee_file in callee_files {
7896 if caller_file != callee_file {
79- file_graph. entry ( caller_file. clone ( ) ) . or_default ( ) . insert ( callee_file. clone ( ) ) ;
97+ file_graph
98+ . entry ( caller_file. clone ( ) )
99+ . or_default ( )
100+ . insert ( callee_file. clone ( ) ) ;
80101 }
81102 }
82103 }
@@ -107,7 +128,12 @@ impl ContextGenerator {
107128 let mut file = File :: create ( & output_path) ?;
108129 file. write_all ( content. as_bytes ( ) ) ?;
109130
110- println ! ( "{}" , style( format!( "Generated: {}" , output_path. display( ) ) ) . green( ) . bold( ) ) ;
131+ println ! (
132+ "{}" ,
133+ style( format!( "Generated: {}" , output_path. display( ) ) )
134+ . green( )
135+ . bold( )
136+ ) ;
111137 Ok ( ( ) )
112138 }
113139
@@ -127,7 +153,9 @@ impl ContextGenerator {
127153 let file_stem = path_obj. file_stem ( ) . unwrap_or_default ( ) . to_string_lossy ( ) ;
128154
129155 if file_name. eq_ignore_ascii_case ( query) || file_stem. eq_ignore_ascii_case ( query) {
130- if !paths. contains ( file) { paths. push ( file. clone ( ) ) ; }
156+ if !paths. contains ( file) {
157+ paths. push ( file. clone ( ) ) ;
158+ }
131159 } else if let Ok ( symbols) = db. get_symbols ( file) {
132160 if symbols. iter ( ) . any ( |s| s. name . eq_ignore_ascii_case ( query) )
133161 && !paths. contains ( file)
@@ -200,7 +228,9 @@ impl ContextGenerator {
200228 content. push_str ( "## File Summaries\n \n " ) ;
201229 for file_path in target_files {
202230 let symbols = db. get_symbols ( file_path) ?;
203- if symbols. is_empty ( ) { continue ; }
231+ if symbols. is_empty ( ) {
232+ continue ;
233+ }
204234
205235 content. push_str ( & format ! ( "### {}\n " , file_path) ) ;
206236
0 commit comments