@@ -6,7 +6,7 @@ use std::{
6
6
use either:: Either ;
7
7
use hir:: {
8
8
ClosureStyle , DisplayTarget , EditionedFileId , HasVisibility , HirDisplay , HirDisplayError ,
9
- HirWrite , ModuleDef , ModuleDefId , Semantics , sym,
9
+ HirWrite , InRealFile , ModuleDef , ModuleDefId , Semantics , sym,
10
10
} ;
11
11
use ide_db:: { FileRange , RootDatabase , famous_defs:: FamousDefs , text_edit:: TextEditBuilder } ;
12
12
use ide_db:: { FxHashSet , text_edit:: TextEdit } ;
@@ -95,16 +95,16 @@ pub(crate) fn inlay_hints(
95
95
return acc;
96
96
} ;
97
97
let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
98
+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
98
99
99
100
let ctx = & mut InlayHintCtx :: default ( ) ;
100
101
let mut hints = |event| {
101
102
if let Some ( node) = handle_event ( ctx, event) {
102
- hints ( & mut acc, ctx, & famous_defs, config, file_id, node) ;
103
+ hints ( & mut acc, ctx, & famous_defs, config, file_id, display_target , node) ;
103
104
}
104
105
} ;
105
106
let mut preorder = file. preorder ( ) ;
106
107
while let Some ( event) = preorder. next ( ) {
107
- // FIXME: This can miss some hints that require the parent of the range to calculate
108
108
if matches ! ( ( & event, range_limit) , ( WalkEvent :: Enter ( node) , Some ( range) ) if range. intersect( node. text_range( ) ) . is_none( ) )
109
109
{
110
110
preorder. skip_subtree ( ) ;
@@ -144,10 +144,12 @@ pub(crate) fn inlay_hints_resolve(
144
144
let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
145
145
let mut acc = Vec :: new ( ) ;
146
146
147
+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
148
+
147
149
let ctx = & mut InlayHintCtx :: default ( ) ;
148
150
let mut hints = |event| {
149
151
if let Some ( node) = handle_event ( ctx, event) {
150
- hints ( & mut acc, ctx, & famous_defs, config, file_id, node) ;
152
+ hints ( & mut acc, ctx, & famous_defs, config, file_id, display_target , node) ;
151
153
}
152
154
} ;
153
155
@@ -202,17 +204,19 @@ fn handle_event(ctx: &mut InlayHintCtx, node: WalkEvent<SyntaxNode>) -> Option<S
202
204
fn hints (
203
205
hints : & mut Vec < InlayHint > ,
204
206
ctx : & mut InlayHintCtx ,
205
- famous_defs @ FamousDefs ( sema, _ ) : & FamousDefs < ' _ , ' _ > ,
207
+ famous_defs @ FamousDefs ( sema, _krate ) : & FamousDefs < ' _ , ' _ > ,
206
208
config : & InlayHintsConfig ,
207
209
file_id : EditionedFileId ,
210
+ display_target : DisplayTarget ,
208
211
node : SyntaxNode ,
209
212
) {
210
- let file_id = file_id. editioned_file_id ( sema. db ) ;
211
- let Some ( krate) = sema. first_crate ( file_id. file_id ( ) ) else {
212
- return ;
213
- } ;
214
- let display_target = krate. to_display_target ( sema. db ) ;
215
- closing_brace:: hints ( hints, sema, config, file_id, display_target, node. clone ( ) ) ;
213
+ closing_brace:: hints (
214
+ hints,
215
+ sema,
216
+ config,
217
+ display_target,
218
+ InRealFile { file_id, value : node. clone ( ) } ,
219
+ ) ;
216
220
if let Some ( any_has_generic_args) = ast:: AnyHasGenericArgs :: cast ( node. clone ( ) ) {
217
221
generic_param:: hints ( hints, famous_defs, config, any_has_generic_args) ;
218
222
}
@@ -231,49 +235,52 @@ fn hints(
231
235
closure_captures:: hints( hints, famous_defs, config, it. clone( ) ) ;
232
236
closure_ret:: hints( hints, famous_defs, config, display_target, it)
233
237
} ,
234
- ast:: Expr :: RangeExpr ( it) => range_exclusive:: hints( hints, famous_defs, config, file_id , it) ,
238
+ ast:: Expr :: RangeExpr ( it) => range_exclusive:: hints( hints, famous_defs, config, it) ,
235
239
_ => Some ( ( ) ) ,
236
240
}
237
241
} ,
238
242
ast:: Pat ( it) => {
239
- binding_mode:: hints( hints, famous_defs, config, file_id , & it) ;
243
+ binding_mode:: hints( hints, famous_defs, config, & it) ;
240
244
match it {
241
245
ast:: Pat :: IdentPat ( it) => {
242
246
bind_pat:: hints( hints, famous_defs, config, display_target, & it) ;
243
247
}
244
248
ast:: Pat :: RangePat ( it) => {
245
- range_exclusive:: hints( hints, famous_defs, config, file_id , it) ;
249
+ range_exclusive:: hints( hints, famous_defs, config, it) ;
246
250
}
247
251
_ => { }
248
252
}
249
253
Some ( ( ) )
250
254
} ,
251
255
ast:: Item ( it) => match it {
252
256
ast:: Item :: Fn ( it) => {
253
- implicit_drop:: hints( hints, famous_defs, config, file_id , & it) ;
257
+ implicit_drop:: hints( hints, famous_defs, config, display_target , & it) ;
254
258
if let Some ( extern_block) = & ctx. extern_block_parent {
255
- extern_block:: fn_hints( hints, famous_defs, config, file_id , & it, extern_block) ;
259
+ extern_block:: fn_hints( hints, famous_defs, config, & it, extern_block) ;
256
260
}
257
- lifetime:: fn_hints( hints, ctx, famous_defs, config, file_id , it)
261
+ lifetime:: fn_hints( hints, ctx, famous_defs, config, it)
258
262
} ,
259
263
ast:: Item :: Static ( it) => {
260
264
if let Some ( extern_block) = & ctx. extern_block_parent {
261
- extern_block:: static_hints( hints, famous_defs, config, file_id , & it, extern_block) ;
265
+ extern_block:: static_hints( hints, famous_defs, config, & it, extern_block) ;
262
266
}
263
- implicit_static:: hints( hints, famous_defs, config, file_id , Either :: Left ( it) )
267
+ implicit_static:: hints( hints, famous_defs, config, Either :: Left ( it) )
264
268
} ,
265
- ast:: Item :: Const ( it) => implicit_static:: hints( hints, famous_defs, config, file_id , Either :: Right ( it) ) ,
266
- ast:: Item :: Enum ( it) => discriminant:: enum_hints( hints, famous_defs, config, file_id , it) ,
267
- ast:: Item :: ExternBlock ( it) => extern_block:: extern_block_hints( hints, famous_defs, config, file_id , it) ,
269
+ ast:: Item :: Const ( it) => implicit_static:: hints( hints, famous_defs, config, Either :: Right ( it) ) ,
270
+ ast:: Item :: Enum ( it) => discriminant:: enum_hints( hints, famous_defs, config, it) ,
271
+ ast:: Item :: ExternBlock ( it) => extern_block:: extern_block_hints( hints, famous_defs, config, it) ,
268
272
_ => None ,
269
273
} ,
270
274
// FIXME: trait object type elisions
271
275
ast:: Type ( ty) => match ty {
272
- ast:: Type :: FnPtrType ( ptr) => lifetime:: fn_ptr_hints( hints, ctx, famous_defs, config, file_id, ptr) ,
273
- ast:: Type :: PathType ( path) => lifetime:: fn_path_hints( hints, ctx, famous_defs, config, file_id, path) ,
276
+ ast:: Type :: FnPtrType ( ptr) => lifetime:: fn_ptr_hints( hints, ctx, famous_defs, config, ptr) ,
277
+ ast:: Type :: PathType ( path) => {
278
+ lifetime:: fn_path_hints( hints, ctx, famous_defs, config, path) ;
279
+ Some ( ( ) )
280
+ } ,
274
281
_ => Some ( ( ) ) ,
275
282
} ,
276
- ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, file_id , it) ,
283
+ ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, it) ,
277
284
_ => Some ( ( ) ) ,
278
285
}
279
286
} ;
0 commit comments