@@ -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 } ;
@@ -34,6 +34,7 @@ mod extern_block;
34
34
mod generic_param;
35
35
mod implicit_drop;
36
36
mod implicit_static;
37
+ mod implied_dyn_trait;
37
38
mod lifetime;
38
39
mod param_name;
39
40
mod range_exclusive;
@@ -95,16 +96,16 @@ pub(crate) fn inlay_hints(
95
96
return acc;
96
97
} ;
97
98
let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
99
+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
98
100
99
101
let ctx = & mut InlayHintCtx :: default ( ) ;
100
102
let mut hints = |event| {
101
103
if let Some ( node) = handle_event ( ctx, event) {
102
- hints ( & mut acc, ctx, & famous_defs, config, file_id, node) ;
104
+ hints ( & mut acc, ctx, & famous_defs, config, file_id, display_target , node) ;
103
105
}
104
106
} ;
105
107
let mut preorder = file. preorder ( ) ;
106
108
while let Some ( event) = preorder. next ( ) {
107
- // FIXME: This can miss some hints that require the parent of the range to calculate
108
109
if matches ! ( ( & event, range_limit) , ( WalkEvent :: Enter ( node) , Some ( range) ) if range. intersect( node. text_range( ) ) . is_none( ) )
109
110
{
110
111
preorder. skip_subtree ( ) ;
@@ -144,10 +145,12 @@ pub(crate) fn inlay_hints_resolve(
144
145
let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
145
146
let mut acc = Vec :: new ( ) ;
146
147
148
+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
149
+
147
150
let ctx = & mut InlayHintCtx :: default ( ) ;
148
151
let mut hints = |event| {
149
152
if let Some ( node) = handle_event ( ctx, event) {
150
- hints ( & mut acc, ctx, & famous_defs, config, file_id, node) ;
153
+ hints ( & mut acc, ctx, & famous_defs, config, file_id, display_target , node) ;
151
154
}
152
155
} ;
153
156
@@ -202,17 +205,19 @@ fn handle_event(ctx: &mut InlayHintCtx, node: WalkEvent<SyntaxNode>) -> Option<S
202
205
fn hints (
203
206
hints : & mut Vec < InlayHint > ,
204
207
ctx : & mut InlayHintCtx ,
205
- famous_defs @ FamousDefs ( sema, _ ) : & FamousDefs < ' _ , ' _ > ,
208
+ famous_defs @ FamousDefs ( sema, _krate ) : & FamousDefs < ' _ , ' _ > ,
206
209
config : & InlayHintsConfig ,
207
210
file_id : EditionedFileId ,
211
+ display_target : DisplayTarget ,
208
212
node : SyntaxNode ,
209
213
) {
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 ( ) ) ;
214
+ closing_brace:: hints (
215
+ hints,
216
+ sema,
217
+ config,
218
+ display_target,
219
+ InRealFile { file_id, value : node. clone ( ) } ,
220
+ ) ;
216
221
if let Some ( any_has_generic_args) = ast:: AnyHasGenericArgs :: cast ( node. clone ( ) ) {
217
222
generic_param:: hints ( hints, famous_defs, config, any_has_generic_args) ;
218
223
}
@@ -231,49 +236,57 @@ fn hints(
231
236
closure_captures:: hints( hints, famous_defs, config, it. clone( ) ) ;
232
237
closure_ret:: hints( hints, famous_defs, config, display_target, it)
233
238
} ,
234
- ast:: Expr :: RangeExpr ( it) => range_exclusive:: hints( hints, famous_defs, config, file_id , it) ,
239
+ ast:: Expr :: RangeExpr ( it) => range_exclusive:: hints( hints, famous_defs, config, it) ,
235
240
_ => Some ( ( ) ) ,
236
241
}
237
242
} ,
238
243
ast:: Pat ( it) => {
239
- binding_mode:: hints( hints, famous_defs, config, file_id , & it) ;
244
+ binding_mode:: hints( hints, famous_defs, config, & it) ;
240
245
match it {
241
246
ast:: Pat :: IdentPat ( it) => {
242
247
bind_pat:: hints( hints, famous_defs, config, display_target, & it) ;
243
248
}
244
249
ast:: Pat :: RangePat ( it) => {
245
- range_exclusive:: hints( hints, famous_defs, config, file_id , it) ;
250
+ range_exclusive:: hints( hints, famous_defs, config, it) ;
246
251
}
247
252
_ => { }
248
253
}
249
254
Some ( ( ) )
250
255
} ,
251
256
ast:: Item ( it) => match it {
252
257
ast:: Item :: Fn ( it) => {
253
- implicit_drop:: hints( hints, famous_defs, config, file_id , & it) ;
258
+ implicit_drop:: hints( hints, famous_defs, config, display_target , & it) ;
254
259
if let Some ( extern_block) = & ctx. extern_block_parent {
255
- extern_block:: fn_hints( hints, famous_defs, config, file_id , & it, extern_block) ;
260
+ extern_block:: fn_hints( hints, famous_defs, config, & it, extern_block) ;
256
261
}
257
- lifetime:: fn_hints( hints, ctx, famous_defs, config, file_id , it)
262
+ lifetime:: fn_hints( hints, ctx, famous_defs, config, it)
258
263
} ,
259
264
ast:: Item :: Static ( it) => {
260
265
if let Some ( extern_block) = & ctx. extern_block_parent {
261
- extern_block:: static_hints( hints, famous_defs, config, file_id , & it, extern_block) ;
266
+ extern_block:: static_hints( hints, famous_defs, config, & it, extern_block) ;
262
267
}
263
- implicit_static:: hints( hints, famous_defs, config, file_id , Either :: Left ( it) )
268
+ implicit_static:: hints( hints, famous_defs, config, Either :: Left ( it) )
264
269
} ,
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) ,
270
+ ast:: Item :: Const ( it) => implicit_static:: hints( hints, famous_defs, config, Either :: Right ( it) ) ,
271
+ ast:: Item :: Enum ( it) => discriminant:: enum_hints( hints, famous_defs, config, it) ,
272
+ ast:: Item :: ExternBlock ( it) => extern_block:: extern_block_hints( hints, famous_defs, config, it) ,
268
273
_ => None ,
269
274
} ,
270
275
// FIXME: trait object type elisions
271
276
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) ,
277
+ ast:: Type :: FnPtrType ( ptr) => lifetime:: fn_ptr_hints( hints, ctx, famous_defs, config, ptr) ,
278
+ ast:: Type :: PathType ( path) => {
279
+ lifetime:: fn_path_hints( hints, ctx, famous_defs, config, & path) ;
280
+ implied_dyn_trait:: hints( hints, famous_defs, config, Either :: Left ( path) ) ;
281
+ Some ( ( ) )
282
+ } ,
283
+ ast:: Type :: DynTraitType ( dyn_) => {
284
+ implied_dyn_trait:: hints( hints, famous_defs, config, Either :: Right ( dyn_) ) ;
285
+ Some ( ( ) )
286
+ } ,
274
287
_ => Some ( ( ) ) ,
275
288
} ,
276
- ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, file_id , it) ,
289
+ ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, it) ,
277
290
_ => Some ( ( ) ) ,
278
291
}
279
292
} ;
@@ -438,6 +451,7 @@ pub enum InlayKind {
438
451
Parameter ,
439
452
GenericParameter ,
440
453
Type ,
454
+ Dyn ,
441
455
Drop ,
442
456
RangeExclusive ,
443
457
ExternUnsafety ,
0 commit comments