@@ -19,7 +19,7 @@ pub enum InGlobal<'linker> {
1919}
2020
2121/// Information about an object in the source code. Used for hovering, completions, syntax highlighting etc.
22- #[ derive( Clone , Copy , Debug ) ]
22+ #[ derive( Clone , Copy ) ]
2323pub enum LocationInfo < ' linker > {
2424 InGlobal ( GlobalUUID , & ' linker LinkInfo , FlatID , InGlobal < ' linker > ) ,
2525 Parameter (
@@ -33,6 +33,33 @@ pub enum LocationInfo<'linker> {
3333 Interface ( ModuleUUID , & ' linker Module , InterfaceID , & ' linker Interface ) ,
3434}
3535
36+ impl < ' linker > std:: fmt:: Debug for LocationInfo < ' linker > {
37+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
38+ match self {
39+ Self :: InGlobal ( _arg0, global, arg2, arg3) => f
40+ . debug_tuple ( "InGlobal" )
41+ . field ( & global. name )
42+ . field ( arg2)
43+ . field ( arg3)
44+ . finish ( ) ,
45+ Self :: Parameter ( _arg0, global, arg2, arg3) => f
46+ . debug_tuple ( "Parameter" )
47+ . field ( & global. name )
48+ . field ( arg2)
49+ . field ( arg3)
50+ . finish ( ) ,
51+ Self :: Type ( arg0, arg1) => f. debug_tuple ( "Type" ) . field ( arg0) . field ( arg1) . finish ( ) ,
52+ Self :: Global ( arg0) => f. debug_tuple ( "Global" ) . field ( arg0) . finish ( ) ,
53+ Self :: Interface ( _arg0, md, arg2, arg3) => f
54+ . debug_tuple ( "Interface" )
55+ . field ( & md. link_info . name )
56+ . field ( arg2)
57+ . field ( arg3)
58+ . finish ( ) ,
59+ }
60+ }
61+ }
62+
3663/// Permits really efficient [RefersTo::refers_to_same_as] [LocationInfo] checking
3764#[ derive( Clone , Copy , Debug ) ]
3865pub struct RefersTo {
@@ -172,12 +199,12 @@ pub fn get_selected_object<'linker>(
172199 let mut walker = TreeWalker {
173200 linker,
174201 visitor : |span, info| {
202+ // Gotta do this condition in inverse, since we only want to set it if it's not already set, or the new span is more specific
175203 if let Some ( ( best_span, _) ) = best_object
176- && best_span. size ( ) > span. size ( )
204+ && best_span. size ( ) < span. size ( )
177205 {
178206 } else {
179- //assert!(span.size() < self.best_span.size());
180- // May not be the case. Do prioritize later ones, as they tend to be nested
207+ // Better spans are also spans that come later, even if they are the exact same span. Because more specific tree nodes are nested.
181208 best_object = Some ( ( span, info) ) ;
182209 }
183210 } ,
@@ -386,9 +413,6 @@ impl<'linker, Visitor: FnMut(Span, LocationInfo<'linker>), Pruner: Fn(Span) -> b
386413 if !( self . should_prune ) ( link_info. span ) {
387414 self . walk_name_and_template_arguments ( obj_id, link_info) ;
388415
389- for ( wire_ref, _) in link_info. iter_wire_refs ( ) {
390- self . walk_wire_ref ( obj_id, link_info, wire_ref) ;
391- }
392416 for ( id, inst) in & link_info. instructions {
393417 match inst {
394418 Instruction :: SubModule ( sm) => {
@@ -418,8 +442,7 @@ impl<'linker, Visitor: FnMut(Span, LocationInfo<'linker>), Pruner: Fn(Span) -> b
418442 }
419443 }
420444 Instruction :: Expression ( expr) => {
421- if let ExpressionSource :: WireRef ( _) = & expr. source {
422- } else if let Some ( single_output_expr) = expr. as_single_output_expr ( ) {
445+ if let Some ( single_output_expr) = expr. as_single_output_expr ( ) {
423446 self . visit (
424447 expr. span ,
425448 LocationInfo :: InGlobal (
@@ -429,7 +452,17 @@ impl<'linker, Visitor: FnMut(Span, LocationInfo<'linker>), Pruner: Fn(Span) -> b
429452 InGlobal :: Temporary ( single_output_expr) ,
430453 ) ,
431454 )
432- } ;
455+ }
456+ // Don't use [LinkInfo::iter_wire_refs()]
457+ // such that walk_wire_ref is always ordered after the other subexpressions
458+ if let ExpressionSource :: WireRef ( wire_ref) = & expr. source {
459+ self . walk_wire_ref ( obj_id, link_info, wire_ref) ;
460+ }
461+ if let ExpressionOutput :: MultiWrite ( writes) = & expr. output {
462+ for wr in writes {
463+ self . walk_wire_ref ( obj_id, link_info, & wr. to ) ;
464+ }
465+ }
433466 }
434467 Instruction :: Interface ( _) => { }
435468 Instruction :: IfStatement ( _) | Instruction :: ForStatement ( _) => { }
0 commit comments