11//! FIXME: write short doc here
22
3+ use std:: fmt;
4+
35use either:: Either ;
46use hir:: { AssocItem , Documentation , FieldSource , HasAttrs , HasSource , InFile , ModuleSource } ;
57use ide_db:: {
@@ -35,16 +37,14 @@ pub enum SymbolKind {
3537 TypeAlias ,
3638 Trait ,
3739 Macro ,
38- // Do we actually need this?
39- DocTest ,
4040}
4141
4242/// `NavigationTarget` represents and element in the editor's UI which you can
4343/// click on to navigate to a particular piece of code.
4444///
4545/// Typically, a `NavigationTarget` corresponds to some element in the source
4646/// code, like a function or a struct, but this is not strictly required.
47- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
47+ #[ derive( Clone , PartialEq , Eq , Hash ) ]
4848pub struct NavigationTarget {
4949 pub file_id : FileId ,
5050 /// Range which encompasses the whole element.
@@ -64,12 +64,30 @@ pub struct NavigationTarget {
6464 /// Clients should place the cursor on this range when navigating to this target.
6565 pub focus_range : Option < TextRange > ,
6666 pub name : SmolStr ,
67- pub kind : SymbolKind ,
67+ pub kind : Option < SymbolKind > ,
6868 pub container_name : Option < SmolStr > ,
6969 pub description : Option < String > ,
7070 pub docs : Option < Documentation > ,
7171}
7272
73+ impl fmt:: Debug for NavigationTarget {
74+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
75+ let mut f = f. debug_struct ( "NavigationTarget" ) ;
76+ macro_rules! opt {
77+ ( $( $name: ident) * ) => { $(
78+ if let Some ( it) = & self . $name {
79+ f. field( stringify!( $name) , it) ;
80+ }
81+ ) * }
82+ }
83+ f. field ( "file_id" , & self . file_id ) . field ( "full_range" , & self . full_range ) ;
84+ opt ! ( focus_range) ;
85+ f. field ( "name" , & self . name ) ;
86+ opt ! ( kind container_name description docs) ;
87+ f. finish ( )
88+ }
89+ }
90+
7391pub ( crate ) trait ToNav {
7492 fn to_nav ( & self , db : & RootDatabase ) -> NavigationTarget ;
7593}
@@ -110,8 +128,13 @@ impl NavigationTarget {
110128
111129 #[ cfg( test) ]
112130 pub ( crate ) fn debug_render ( & self ) -> String {
113- let mut buf =
114- format ! ( "{} {:?} {:?} {:?}" , self . name, self . kind, self . file_id, self . full_range) ;
131+ let mut buf = format ! (
132+ "{} {:?} {:?} {:?}" ,
133+ self . name,
134+ self . kind. unwrap( ) ,
135+ self . file_id,
136+ self . full_range
137+ ) ;
115138 if let Some ( focus_range) = self . focus_range {
116139 buf. push_str ( & format ! ( " {:?}" , focus_range) )
117140 }
@@ -146,7 +169,7 @@ impl NavigationTarget {
146169 NavigationTarget {
147170 file_id,
148171 name,
149- kind,
172+ kind : Some ( kind ) ,
150173 full_range,
151174 focus_range,
152175 container_name : None ,
@@ -161,7 +184,7 @@ impl ToNav for FileSymbol {
161184 NavigationTarget {
162185 file_id : self . file_id ,
163186 name : self . name . clone ( ) ,
164- kind : match self . kind {
187+ kind : Some ( match self . kind {
165188 FileSymbolKind :: Function => SymbolKind :: Function ,
166189 FileSymbolKind :: Struct => SymbolKind :: Struct ,
167190 FileSymbolKind :: Enum => SymbolKind :: Enum ,
@@ -171,7 +194,7 @@ impl ToNav for FileSymbol {
171194 FileSymbolKind :: Const => SymbolKind :: Const ,
172195 FileSymbolKind :: Static => SymbolKind :: Static ,
173196 FileSymbolKind :: Macro => SymbolKind :: Macro ,
174- } ,
197+ } ) ,
175198 full_range : self . range ,
176199 focus_range : self . name_range ,
177200 container_name : self . container_name . clone ( ) ,
@@ -386,7 +409,7 @@ impl ToNav for hir::Local {
386409 NavigationTarget {
387410 file_id : full_range. file_id ,
388411 name,
389- kind : SymbolKind :: Local ,
412+ kind : Some ( SymbolKind :: Local ) ,
390413 full_range : full_range. range ,
391414 focus_range : None ,
392415 container_name : None ,
@@ -410,7 +433,7 @@ impl ToNav for hir::TypeParam {
410433 NavigationTarget {
411434 file_id : src. file_id . original_file ( db) ,
412435 name : self . name ( db) . to_string ( ) . into ( ) ,
413- kind : SymbolKind :: TypeParam ,
436+ kind : Some ( SymbolKind :: TypeParam ) ,
414437 full_range,
415438 focus_range,
416439 container_name : None ,
@@ -427,7 +450,7 @@ impl ToNav for hir::LifetimeParam {
427450 NavigationTarget {
428451 file_id : src. file_id . original_file ( db) ,
429452 name : self . name ( db) . to_string ( ) . into ( ) ,
430- kind : SymbolKind :: LifetimeParam ,
453+ kind : Some ( SymbolKind :: LifetimeParam ) ,
431454 full_range,
432455 focus_range : Some ( full_range) ,
433456 container_name : None ,
@@ -484,34 +507,21 @@ fn foo() { enum FooInner { } }
484507 0,
485508 ),
486509 full_range: 0..17,
487- focus_range: Some(
488- 5..13,
489- ),
510+ focus_range: 5..13,
490511 name: "FooInner",
491512 kind: Enum,
492- container_name: None,
493- description: Some(
494- "enum FooInner",
495- ),
496- docs: None,
513+ description: "enum FooInner",
497514 },
498515 NavigationTarget {
499516 file_id: FileId(
500517 0,
501518 ),
502519 full_range: 29..46,
503- focus_range: Some(
504- 34..42,
505- ),
520+ focus_range: 34..42,
506521 name: "FooInner",
507522 kind: Enum,
508- container_name: Some(
509- "foo",
510- ),
511- description: Some(
512- "enum FooInner",
513- ),
514- docs: None,
523+ container_name: "foo",
524+ description: "enum FooInner",
515525 },
516526 ]
517527 "# ] ]
0 commit comments