@@ -22,15 +22,28 @@ use super::short_label::ShortLabel;
22
22
/// code, like a function or a struct, but this is not strictly required.
23
23
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
24
24
pub struct NavigationTarget {
25
- // FIXME: use FileRange?
26
- file_id : FileId ,
27
- full_range : TextRange ,
28
- name : SmolStr ,
29
- kind : SyntaxKind ,
30
- focus_range : Option < TextRange > ,
31
- container_name : Option < SmolStr > ,
32
- description : Option < String > ,
33
- docs : Option < String > ,
25
+ pub file_id : FileId ,
26
+ /// Range which encompasses the whole element.
27
+ ///
28
+ /// Should include body, doc comments, attributes, etc.
29
+ ///
30
+ /// Clients should use this range to answer "is the cursor inside the
31
+ /// element?" question.
32
+ pub full_range : TextRange ,
33
+ /// A "most interesting" range withing the `full_range`.
34
+ ///
35
+ /// Typically, `full_range` is the whole syntax node, including doc
36
+ /// comments, and `focus_range` is the range of the identifier. "Most
37
+ /// interesting" range within the full range, typically the range of
38
+ /// identifier.
39
+ ///
40
+ /// Clients should place the cursor on this range when navigating to this target.
41
+ pub focus_range : Option < TextRange > ,
42
+ pub name : SmolStr ,
43
+ pub kind : SyntaxKind ,
44
+ pub container_name : Option < SmolStr > ,
45
+ pub description : Option < String > ,
46
+ pub docs : Option < String > ,
34
47
}
35
48
36
49
pub ( crate ) trait ToNav {
@@ -42,44 +55,9 @@ pub(crate) trait TryToNav {
42
55
}
43
56
44
57
impl NavigationTarget {
45
- /// When `focus_range` is specified, returns it. otherwise
46
- /// returns `full_range`
47
- pub fn range ( & self ) -> TextRange {
58
+ pub fn focus_or_full_range ( & self ) -> TextRange {
48
59
self . focus_range . unwrap_or ( self . full_range )
49
60
}
50
- /// A "most interesting" range withing the `full_range`.
51
- ///
52
- /// Typically, `full_range` is the whole syntax node,
53
- /// including doc comments, and `focus_range` is the range of the identifier.
54
- pub fn focus_range ( & self ) -> Option < TextRange > {
55
- self . focus_range
56
- }
57
- pub fn full_range ( & self ) -> TextRange {
58
- self . full_range
59
- }
60
- pub fn file_id ( & self ) -> FileId {
61
- self . file_id
62
- }
63
-
64
- pub fn name ( & self ) -> & SmolStr {
65
- & self . name
66
- }
67
-
68
- pub fn container_name ( & self ) -> Option < & SmolStr > {
69
- self . container_name . as_ref ( )
70
- }
71
-
72
- pub fn kind ( & self ) -> SyntaxKind {
73
- self . kind
74
- }
75
-
76
- pub fn docs ( & self ) -> Option < & str > {
77
- self . docs . as_deref ( )
78
- }
79
-
80
- pub fn description ( & self ) -> Option < & str > {
81
- self . description . as_deref ( )
82
- }
83
61
84
62
pub ( crate ) fn from_module_to_decl ( db : & RootDatabase , module : hir:: Module ) -> NavigationTarget {
85
63
let name = module. name ( db) . map ( |it| it. to_string ( ) . into ( ) ) . unwrap_or_default ( ) ;
@@ -107,17 +85,12 @@ impl NavigationTarget {
107
85
108
86
#[ cfg( test) ]
109
87
pub ( crate ) fn debug_render ( & self ) -> String {
110
- let mut buf = format ! (
111
- "{} {:?} {:?} {:?}" ,
112
- self . name( ) ,
113
- self . kind( ) ,
114
- self . file_id( ) ,
115
- self . full_range( )
116
- ) ;
117
- if let Some ( focus_range) = self . focus_range ( ) {
88
+ let mut buf =
89
+ format ! ( "{} {:?} {:?} {:?}" , self . name, self . kind, self . file_id, self . full_range) ;
90
+ if let Some ( focus_range) = self . focus_range {
118
91
buf. push_str ( & format ! ( " {:?}" , focus_range) )
119
92
}
120
- if let Some ( container_name) = self . container_name ( ) {
93
+ if let Some ( container_name) = & self . container_name {
121
94
buf. push_str ( & format ! ( " {}" , container_name) )
122
95
}
123
96
buf
0 commit comments