@@ -6,7 +6,7 @@ use std::{
66use either:: Either ;
77use hir:: {
88 ClosureStyle , DisplayTarget , EditionedFileId , HasVisibility , HirDisplay , HirDisplayError ,
9- HirWrite , ModuleDef , ModuleDefId , Semantics , sym,
9+ HirWrite , InRealFile , ModuleDef , ModuleDefId , Semantics , sym,
1010} ;
1111use ide_db:: { FileRange , RootDatabase , famous_defs:: FamousDefs , text_edit:: TextEditBuilder } ;
1212use ide_db:: { FxHashSet , text_edit:: TextEdit } ;
@@ -34,6 +34,7 @@ mod extern_block;
3434mod generic_param;
3535mod implicit_drop;
3636mod implicit_static;
37+ mod implied_dyn_trait;
3738mod lifetime;
3839mod param_name;
3940mod range_exclusive;
@@ -95,16 +96,16 @@ pub(crate) fn inlay_hints(
9596 return acc;
9697 } ;
9798 let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
99+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
98100
99101 let ctx = & mut InlayHintCtx :: default ( ) ;
100102 let mut hints = |event| {
101103 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) ;
103105 }
104106 } ;
105107 let mut preorder = file. preorder ( ) ;
106108 while let Some ( event) = preorder. next ( ) {
107- // FIXME: This can miss some hints that require the parent of the range to calculate
108109 if matches ! ( ( & event, range_limit) , ( WalkEvent :: Enter ( node) , Some ( range) ) if range. intersect( node. text_range( ) ) . is_none( ) )
109110 {
110111 preorder. skip_subtree ( ) ;
@@ -144,10 +145,12 @@ pub(crate) fn inlay_hints_resolve(
144145 let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
145146 let mut acc = Vec :: new ( ) ;
146147
148+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
149+
147150 let ctx = & mut InlayHintCtx :: default ( ) ;
148151 let mut hints = |event| {
149152 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) ;
151154 }
152155 } ;
153156
@@ -202,17 +205,19 @@ fn handle_event(ctx: &mut InlayHintCtx, node: WalkEvent<SyntaxNode>) -> Option<S
202205fn hints (
203206 hints : & mut Vec < InlayHint > ,
204207 ctx : & mut InlayHintCtx ,
205- famous_defs @ FamousDefs ( sema, _ ) : & FamousDefs < ' _ , ' _ > ,
208+ famous_defs @ FamousDefs ( sema, _krate ) : & FamousDefs < ' _ , ' _ > ,
206209 config : & InlayHintsConfig ,
207210 file_id : EditionedFileId ,
211+ display_target : DisplayTarget ,
208212 node : SyntaxNode ,
209213) {
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+ ) ;
216221 if let Some ( any_has_generic_args) = ast:: AnyHasGenericArgs :: cast ( node. clone ( ) ) {
217222 generic_param:: hints ( hints, famous_defs, config, any_has_generic_args) ;
218223 }
@@ -231,49 +236,57 @@ fn hints(
231236 closure_captures:: hints( hints, famous_defs, config, it. clone( ) ) ;
232237 closure_ret:: hints( hints, famous_defs, config, display_target, it)
233238 } ,
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) ,
235240 _ => Some ( ( ) ) ,
236241 }
237242 } ,
238243 ast:: Pat ( it) => {
239- binding_mode:: hints( hints, famous_defs, config, file_id , & it) ;
244+ binding_mode:: hints( hints, famous_defs, config, & it) ;
240245 match it {
241246 ast:: Pat :: IdentPat ( it) => {
242247 bind_pat:: hints( hints, famous_defs, config, display_target, & it) ;
243248 }
244249 ast:: Pat :: RangePat ( it) => {
245- range_exclusive:: hints( hints, famous_defs, config, file_id , it) ;
250+ range_exclusive:: hints( hints, famous_defs, config, it) ;
246251 }
247252 _ => { }
248253 }
249254 Some ( ( ) )
250255 } ,
251256 ast:: Item ( it) => match it {
252257 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) ;
254259 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) ;
256261 }
257- lifetime:: fn_hints( hints, ctx, famous_defs, config, file_id , it)
262+ lifetime:: fn_hints( hints, ctx, famous_defs, config, it)
258263 } ,
259264 ast:: Item :: Static ( it) => {
260265 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) ;
262267 }
263- implicit_static:: hints( hints, famous_defs, config, file_id , Either :: Left ( it) )
268+ implicit_static:: hints( hints, famous_defs, config, Either :: Left ( it) )
264269 } ,
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) ,
268273 _ => None ,
269274 } ,
270275 // FIXME: trait object type elisions
271276 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+ } ,
274287 _ => Some ( ( ) ) ,
275288 } ,
276- ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, file_id , it) ,
289+ ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, it) ,
277290 _ => Some ( ( ) ) ,
278291 }
279292 } ;
@@ -438,6 +451,7 @@ pub enum InlayKind {
438451 Parameter ,
439452 GenericParameter ,
440453 Type ,
454+ Dyn ,
441455 Drop ,
442456 RangeExclusive ,
443457 ExternUnsafety ,
0 commit comments