@@ -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 } ;
@@ -95,16 +95,16 @@ pub(crate) fn inlay_hints(
9595 return acc;
9696 } ;
9797 let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
98+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
9899
99100 let ctx = & mut InlayHintCtx :: default ( ) ;
100101 let mut hints = |event| {
101102 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) ;
103104 }
104105 } ;
105106 let mut preorder = file. preorder ( ) ;
106107 while let Some ( event) = preorder. next ( ) {
107- // FIXME: This can miss some hints that require the parent of the range to calculate
108108 if matches ! ( ( & event, range_limit) , ( WalkEvent :: Enter ( node) , Some ( range) ) if range. intersect( node. text_range( ) ) . is_none( ) )
109109 {
110110 preorder. skip_subtree ( ) ;
@@ -144,10 +144,12 @@ pub(crate) fn inlay_hints_resolve(
144144 let famous_defs = FamousDefs ( & sema, scope. krate ( ) ) ;
145145 let mut acc = Vec :: new ( ) ;
146146
147+ let display_target = famous_defs. 1 . to_display_target ( sema. db ) ;
148+
147149 let ctx = & mut InlayHintCtx :: default ( ) ;
148150 let mut hints = |event| {
149151 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) ;
151153 }
152154 } ;
153155
@@ -202,17 +204,19 @@ fn handle_event(ctx: &mut InlayHintCtx, node: WalkEvent<SyntaxNode>) -> Option<S
202204fn hints (
203205 hints : & mut Vec < InlayHint > ,
204206 ctx : & mut InlayHintCtx ,
205- famous_defs @ FamousDefs ( sema, _ ) : & FamousDefs < ' _ , ' _ > ,
207+ famous_defs @ FamousDefs ( sema, _krate ) : & FamousDefs < ' _ , ' _ > ,
206208 config : & InlayHintsConfig ,
207209 file_id : EditionedFileId ,
210+ display_target : DisplayTarget ,
208211 node : SyntaxNode ,
209212) {
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+ ) ;
216220 if let Some ( any_has_generic_args) = ast:: AnyHasGenericArgs :: cast ( node. clone ( ) ) {
217221 generic_param:: hints ( hints, famous_defs, config, any_has_generic_args) ;
218222 }
@@ -231,49 +235,52 @@ fn hints(
231235 closure_captures:: hints( hints, famous_defs, config, it. clone( ) ) ;
232236 closure_ret:: hints( hints, famous_defs, config, display_target, it)
233237 } ,
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) ,
235239 _ => Some ( ( ) ) ,
236240 }
237241 } ,
238242 ast:: Pat ( it) => {
239- binding_mode:: hints( hints, famous_defs, config, file_id , & it) ;
243+ binding_mode:: hints( hints, famous_defs, config, & it) ;
240244 match it {
241245 ast:: Pat :: IdentPat ( it) => {
242246 bind_pat:: hints( hints, famous_defs, config, display_target, & it) ;
243247 }
244248 ast:: Pat :: RangePat ( it) => {
245- range_exclusive:: hints( hints, famous_defs, config, file_id , it) ;
249+ range_exclusive:: hints( hints, famous_defs, config, it) ;
246250 }
247251 _ => { }
248252 }
249253 Some ( ( ) )
250254 } ,
251255 ast:: Item ( it) => match it {
252256 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) ;
254258 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) ;
256260 }
257- lifetime:: fn_hints( hints, ctx, famous_defs, config, file_id , it)
261+ lifetime:: fn_hints( hints, ctx, famous_defs, config, it)
258262 } ,
259263 ast:: Item :: Static ( it) => {
260264 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) ;
262266 }
263- implicit_static:: hints( hints, famous_defs, config, file_id , Either :: Left ( it) )
267+ implicit_static:: hints( hints, famous_defs, config, Either :: Left ( it) )
264268 } ,
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) ,
268272 _ => None ,
269273 } ,
270274 // FIXME: trait object type elisions
271275 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+ } ,
274281 _ => Some ( ( ) ) ,
275282 } ,
276- ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, file_id , it) ,
283+ ast:: GenericParamList ( it) => bounds:: hints( hints, famous_defs, config, it) ,
277284 _ => Some ( ( ) ) ,
278285 }
279286 } ;
0 commit comments