@@ -3,14 +3,15 @@ use std::collections::{HashMap, HashSet};
3
3
use camino:: Utf8PathBuf ;
4
4
use common:: { config:: Config , graph:: EdgeWeight , urlext:: canonical_url} ;
5
5
use resolver:: {
6
- graph:: { petgraph, DiGraph , GraphResolver , NodeIndex } ,
7
- ingot:: BasicIngotNodeHandler ,
6
+ files:: { FilesResource , FilesResolver } ,
7
+ graph:: { petgraph, DiGraph , GraphResolver , GraphResolutionHandler , NodeIndex } ,
8
+ ResolutionHandler ,
8
9
} ;
9
10
use url:: Url ;
10
11
11
12
pub fn print_tree ( path : & Utf8PathBuf ) {
12
- let mut graph_resolver = resolver :: ingot :: basic_ingot_graph_resolver ( ) ;
13
- let mut node_handler = BasicIngotNodeHandler :: default ( ) ;
13
+ let mut graph_resolver = basic_ingot_graph_resolver ( ) ;
14
+ let mut node_handler = TreeIngotNodeHandler :: default ( ) ;
14
15
let ingot_url = match canonical_url ( path) {
15
16
Ok ( url) => url,
16
17
Err ( _) => {
@@ -21,12 +22,36 @@ pub fn print_tree(path: &Utf8PathBuf) {
21
22
22
23
match graph_resolver. graph_resolve ( & mut node_handler, & ingot_url) {
23
24
Ok ( ingot_graph) => {
25
+ // Report diagnostics from graph resolution first
26
+ let graph_diagnostics = graph_resolver. take_diagnostics ( ) ;
27
+ for diagnostic in & graph_diagnostics {
28
+ eprintln ! ( "⚠️ {}" , diagnostic) ;
29
+ }
30
+
31
+ // Report diagnostics from node handler
32
+ let node_diagnostics = node_handler. diagnostics ( ) ;
33
+ for diagnostic in node_diagnostics {
34
+ eprintln ! ( "⚠️ {}" , diagnostic) ;
35
+ }
36
+
37
+ // Print tree after diagnostics
24
38
print ! (
25
39
"{}" ,
26
40
print_tree_impl( & ingot_graph, & ingot_url, & node_handler. configs)
27
41
) ;
28
42
}
29
43
Err ( err) => {
44
+ // Even if resolution failed, show available diagnostics first
45
+ let graph_diagnostics = graph_resolver. take_diagnostics ( ) ;
46
+ for diagnostic in & graph_diagnostics {
47
+ eprintln ! ( "⚠️ {}" , diagnostic) ;
48
+ }
49
+
50
+ let node_diagnostics = node_handler. diagnostics ( ) ;
51
+ for diagnostic in node_diagnostics {
52
+ eprintln ! ( "⚠️ {}" , diagnostic) ;
53
+ }
54
+
30
55
println ! ( "❌ Failed to resolve dependency tree: {err}" ) ;
31
56
}
32
57
}
@@ -199,3 +224,97 @@ fn find_cycle_nodes<N, E>(graph: &DiGraph<N, E>) -> HashSet<NodeIndex> {
199
224
}
200
225
cycles
201
226
}
227
+
228
+ // Tree-specific ingot resolution types and functions
229
+
230
+ pub type TreeIngotGraphResolver = resolver:: graph:: GraphResolverImpl < FilesResolver , TreeIngotNodeHandler , EdgeWeight > ;
231
+
232
+ pub fn basic_ingot_graph_resolver ( ) -> TreeIngotGraphResolver {
233
+ let files_resolver = FilesResolver :: new ( )
234
+ . with_required_file ( "fe.toml" ) ;
235
+ resolver:: graph:: GraphResolverImpl :: new ( files_resolver)
236
+ }
237
+
238
+ #[ derive( Debug ) ]
239
+ pub enum IngotResolutionDiagnostic {
240
+ ConfigParseWarning ( Url , String ) ,
241
+ }
242
+
243
+ impl std:: fmt:: Display for IngotResolutionDiagnostic {
244
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
245
+ match self {
246
+ IngotResolutionDiagnostic :: ConfigParseWarning ( url, msg) => {
247
+ write ! ( f, "Warning parsing config at {url}: {msg}" )
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ #[ derive( Default ) ]
254
+ pub struct TreeIngotNodeHandler {
255
+ pub configs : HashMap < Url , Config > ,
256
+ pub diagnostics : Vec < IngotResolutionDiagnostic > ,
257
+ }
258
+
259
+ impl TreeIngotNodeHandler {
260
+ pub fn diagnostics ( & self ) -> & [ IngotResolutionDiagnostic ] {
261
+ & self . diagnostics
262
+ }
263
+ }
264
+
265
+ impl ResolutionHandler < FilesResolver > for TreeIngotNodeHandler {
266
+ type Item = Vec < ( Url , EdgeWeight ) > ;
267
+
268
+ fn handle_resolution ( & mut self , ingot_url : & Url , resource : FilesResource ) -> Self :: Item {
269
+ tracing:: trace!( target: "resolver" , "Handling ingot resolution for: {}" , ingot_url) ;
270
+
271
+ // Look for fe.toml file
272
+ if let Some ( config_file) = resource. files . iter ( ) . find ( |f| f. path . file_name ( ) == Some ( "fe.toml" ) ) {
273
+ match Config :: parse ( & config_file. content ) {
274
+ Ok ( config) => {
275
+ tracing:: trace!( target: "resolver" , "Successfully parsed config for ingot: {}" , ingot_url) ;
276
+ self . configs . insert ( ingot_url. clone ( ) , config. clone ( ) ) ;
277
+ let dependencies = config
278
+ . based_dependencies ( ingot_url)
279
+ . into_iter ( )
280
+ . map ( |based_dependency| {
281
+ tracing:: trace!( target: "resolver" , "Found dependency: {} -> {}" , ingot_url, based_dependency. url) ;
282
+ (
283
+ based_dependency. url ,
284
+ EdgeWeight {
285
+ alias : based_dependency. alias ,
286
+ arguments : based_dependency. parameters ,
287
+ } ,
288
+ )
289
+ } )
290
+ . collect ( ) ;
291
+ dependencies
292
+ }
293
+ Err ( err) => {
294
+ tracing:: warn!( target: "resolver" , "Failed to parse config for ingot {}: {}" , ingot_url, err) ;
295
+ self . diagnostics
296
+ . push ( IngotResolutionDiagnostic :: ConfigParseWarning (
297
+ ingot_url. clone ( ) ,
298
+ err. to_string ( ) ,
299
+ ) ) ;
300
+ vec ! [ ]
301
+ }
302
+ }
303
+ } else {
304
+ // This case should not happen since we require fe.toml, but handle it gracefully
305
+ vec ! [ ]
306
+ }
307
+ }
308
+ }
309
+
310
+ impl GraphResolutionHandler < Url , DiGraph < Url , EdgeWeight > > for TreeIngotNodeHandler {
311
+ type Item = DiGraph < Url , EdgeWeight > ;
312
+
313
+ fn handle_graph_resolution (
314
+ & mut self ,
315
+ _ingot_url : & Url ,
316
+ graph : DiGraph < Url , EdgeWeight > ,
317
+ ) -> Self :: Item {
318
+ graph
319
+ }
320
+ }
0 commit comments