@@ -14,11 +14,14 @@ use syntax::{SyntaxToken, TextRange};
14
14
15
15
use crate :: display:: TryToNav ;
16
16
use crate :: hover:: hover_for_definition;
17
- use crate :: { Analysis , Fold , HoverConfig , HoverDocFormat , HoverResult } ;
17
+ use crate :: {
18
+ Analysis , Fold , HoverConfig , HoverDocFormat , HoverResult , InlayHint , InlayHintsConfig ,
19
+ } ;
18
20
19
21
/// A static representation of fully analyzed source code.
20
22
///
21
23
/// The intended use-case is powering read-only code browsers and emitting LSIF
24
+ #[ derive( Debug ) ]
22
25
pub struct StaticIndex < ' a > {
23
26
pub files : Vec < StaticIndexedFile > ,
24
27
pub tokens : TokenStore ,
@@ -27,21 +30,29 @@ pub struct StaticIndex<'a> {
27
30
def_map : HashMap < Definition , TokenId > ,
28
31
}
29
32
33
+ #[ derive( Debug ) ]
30
34
pub struct ReferenceData {
31
35
pub range : FileRange ,
32
36
pub is_definition : bool ,
33
37
}
34
38
39
+ #[ derive( Debug ) ]
35
40
pub struct TokenStaticData {
36
41
pub hover : Option < HoverResult > ,
37
42
pub definition : Option < FileRange > ,
38
43
pub references : Vec < ReferenceData > ,
39
44
}
40
45
41
- #[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
46
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
42
47
pub struct TokenId ( usize ) ;
43
48
44
- #[ derive( Default ) ]
49
+ impl TokenId {
50
+ pub fn raw ( self ) -> usize {
51
+ self . 0
52
+ }
53
+ }
54
+
55
+ #[ derive( Default , Debug ) ]
45
56
pub struct TokenStore ( Vec < TokenStaticData > ) ;
46
57
47
58
impl TokenStore {
@@ -64,9 +75,11 @@ impl TokenStore {
64
75
}
65
76
}
66
77
78
+ #[ derive( Debug ) ]
67
79
pub struct StaticIndexedFile {
68
80
pub file_id : FileId ,
69
81
pub folds : Vec < Fold > ,
82
+ pub inlay_hints : Vec < InlayHint > ,
70
83
pub tokens : Vec < ( TextRange , TokenId ) > ,
71
84
}
72
85
@@ -86,6 +99,18 @@ fn all_modules(db: &dyn HirDatabase) -> Vec<Module> {
86
99
impl StaticIndex < ' _ > {
87
100
fn add_file ( & mut self , file_id : FileId ) {
88
101
let folds = self . analysis . folding_ranges ( file_id) . unwrap ( ) ;
102
+ let inlay_hints = self
103
+ . analysis
104
+ . inlay_hints (
105
+ & InlayHintsConfig {
106
+ type_hints : true ,
107
+ parameter_hints : true ,
108
+ chaining_hints : true ,
109
+ max_length : Some ( 25 ) ,
110
+ } ,
111
+ file_id,
112
+ )
113
+ . unwrap ( ) ;
89
114
// hovers
90
115
let sema = hir:: Semantics :: new ( self . db ) ;
91
116
let tokens_or_nodes = sema. parse ( file_id) . syntax ( ) . clone ( ) ;
@@ -99,7 +124,7 @@ impl StaticIndex<'_> {
99
124
IDENT | INT_NUMBER | LIFETIME_IDENT | T ! [ self ] | T ! [ super ] | T ! [ crate ] => true ,
100
125
_ => false ,
101
126
} ) ;
102
- let mut result = StaticIndexedFile { file_id, folds, tokens : vec ! [ ] } ;
127
+ let mut result = StaticIndexedFile { file_id, inlay_hints , folds, tokens : vec ! [ ] } ;
103
128
for token in tokens {
104
129
let range = token. text_range ( ) ;
105
130
let node = token. parent ( ) . unwrap ( ) ;
@@ -133,7 +158,8 @@ impl StaticIndex<'_> {
133
158
self . files . push ( result) ;
134
159
}
135
160
136
- pub fn compute < ' a > ( db : & ' a RootDatabase , analysis : & ' a Analysis ) -> StaticIndex < ' a > {
161
+ pub fn compute < ' a > ( analysis : & ' a Analysis ) -> StaticIndex < ' a > {
162
+ let db = & * analysis. db ;
137
163
let work = all_modules ( db) . into_iter ( ) . filter ( |module| {
138
164
let file_id = module. definition_source ( db) . file_id . original_file ( db) ;
139
165
let source_root = db. file_source_root ( file_id) ;
@@ -181,7 +207,7 @@ mod tests {
181
207
182
208
fn check_all_ranges ( ra_fixture : & str ) {
183
209
let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
184
- let s = StaticIndex :: compute ( & * analysis . db , & analysis) ;
210
+ let s = StaticIndex :: compute ( & analysis) ;
185
211
let mut range_set: HashSet < _ > = ranges. iter ( ) . map ( |x| x. 0 ) . collect ( ) ;
186
212
for f in s. files {
187
213
for ( range, _) in f. tokens {
@@ -199,7 +225,7 @@ mod tests {
199
225
200
226
fn check_definitions ( ra_fixture : & str ) {
201
227
let ( analysis, ranges) = fixture:: annotations_without_marker ( ra_fixture) ;
202
- let s = StaticIndex :: compute ( & * analysis . db , & analysis) ;
228
+ let s = StaticIndex :: compute ( & analysis) ;
203
229
let mut range_set: HashSet < _ > = ranges. iter ( ) . map ( |x| x. 0 ) . collect ( ) ;
204
230
for ( _, t) in s. tokens . iter ( ) {
205
231
if let Some ( x) = t. definition {
0 commit comments