@@ -11,8 +11,8 @@ use anyhow::Context;
1111
1212use ide:: {
1313 AnnotationConfig , AssistKind , AssistResolveStrategy , Cancellable , FilePosition , FileRange ,
14- HoverAction , HoverGotoTypeData , Query , RangeInfo , ReferenceCategory , Runnable , RunnableKind ,
15- SingleResolve , SourceChange , TextEdit ,
14+ HoverAction , HoverGotoTypeData , InlayFieldsToResolve , Query , RangeInfo , ReferenceCategory ,
15+ Runnable , RunnableKind , SingleResolve , SourceChange , TextEdit ,
1616} ;
1717use ide_db:: SymbolKind ;
1818use lsp_server:: ErrorCode ;
@@ -30,7 +30,7 @@ use serde_json::json;
3030use stdx:: { format_to, never} ;
3131use syntax:: { algo, ast, AstNode , TextRange , TextSize } ;
3232use triomphe:: Arc ;
33- use vfs:: { AbsPath , AbsPathBuf , VfsPath } ;
33+ use vfs:: { AbsPath , AbsPathBuf , FileId , VfsPath } ;
3434
3535use crate :: {
3636 cargo_target_spec:: CargoTargetSpec ,
@@ -1412,17 +1412,71 @@ pub(crate) fn handle_inlay_hints(
14121412 snap. analysis
14131413 . inlay_hints ( & inlay_hints_config, file_id, Some ( range) ) ?
14141414 . into_iter ( )
1415- . map ( |it| to_proto:: inlay_hint ( & snap, & line_index, it) )
1415+ . map ( |it| {
1416+ to_proto:: inlay_hint (
1417+ & snap,
1418+ & inlay_hints_config. fields_to_resolve ,
1419+ & line_index,
1420+ file_id,
1421+ it,
1422+ )
1423+ } )
14161424 . collect :: < Cancellable < Vec < _ > > > ( ) ?,
14171425 ) )
14181426}
14191427
14201428pub ( crate ) fn handle_inlay_hints_resolve (
1421- _snap : GlobalStateSnapshot ,
1422- hint : InlayHint ,
1429+ snap : GlobalStateSnapshot ,
1430+ mut original_hint : InlayHint ,
14231431) -> anyhow:: Result < InlayHint > {
14241432 let _p = profile:: span ( "handle_inlay_hints_resolve" ) ;
1425- Ok ( hint)
1433+
1434+ let data = match original_hint. data . take ( ) {
1435+ Some ( it) => it,
1436+ None => return Ok ( original_hint) ,
1437+ } ;
1438+
1439+ let resolve_data: lsp_ext:: InlayHintResolveData = serde_json:: from_value ( data) ?;
1440+ let file_id = FileId ( resolve_data. file_id ) ;
1441+ let line_index = snap. file_line_index ( file_id) ?;
1442+ let range = from_proto:: text_range (
1443+ & line_index,
1444+ lsp_types:: Range { start : original_hint. position , end : original_hint. position } ,
1445+ ) ?;
1446+ let range_start = range. start ( ) ;
1447+ let range_end = range. end ( ) ;
1448+ let large_range = TextRange :: new (
1449+ range_start. checked_sub ( 1 . into ( ) ) . unwrap_or ( range_start) ,
1450+ range_end. checked_add ( 1 . into ( ) ) . unwrap_or ( range_end) ,
1451+ ) ;
1452+ let mut forced_resolve_inlay_hints_config = snap. config . inlay_hints ( ) ;
1453+ forced_resolve_inlay_hints_config. fields_to_resolve = InlayFieldsToResolve :: empty ( ) ;
1454+ let resolve_hints = snap. analysis . inlay_hints (
1455+ & forced_resolve_inlay_hints_config,
1456+ file_id,
1457+ Some ( large_range) ,
1458+ ) ?;
1459+
1460+ let mut resolved_hints = resolve_hints
1461+ . into_iter ( )
1462+ . filter_map ( |it| {
1463+ to_proto:: inlay_hint (
1464+ & snap,
1465+ & forced_resolve_inlay_hints_config. fields_to_resolve ,
1466+ & line_index,
1467+ file_id,
1468+ it,
1469+ )
1470+ . ok ( )
1471+ } )
1472+ . filter ( |hint| hint. position == original_hint. position )
1473+ . filter ( |hint| hint. kind == original_hint. kind ) ;
1474+ if let Some ( resolved_hint) = resolved_hints. next ( ) {
1475+ if resolved_hints. next ( ) . is_none ( ) {
1476+ return Ok ( resolved_hint) ;
1477+ }
1478+ }
1479+ Ok ( original_hint)
14261480}
14271481
14281482pub ( crate ) fn handle_call_hierarchy_prepare (
0 commit comments