Skip to content

Commit 8ae42b5

Browse files
Search for parent blocks and items when resolving inlay hints
1 parent be6d34b commit 8ae42b5

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn ty_to_text_edit(
424424

425425
pub enum RangeLimit {
426426
Fixed(TextRange),
427-
NearestParentBlock(TextSize),
427+
NearestParent(TextSize),
428428
}
429429

430430
// Feature: Inlay Hints
@@ -470,13 +470,21 @@ pub(crate) fn inlay_hints(
470470
.filter(|descendant| range.intersect(descendant.text_range()).is_some())
471471
.for_each(hints),
472472
},
473-
Some(RangeLimit::NearestParentBlock(position)) => {
474-
match file
475-
.token_at_offset(position)
476-
.left_biased()
477-
.and_then(|token| token.parent_ancestors().find_map(ast::BlockExpr::cast))
478-
{
479-
Some(parent_block) => parent_block.syntax().descendants().for_each(hints),
473+
Some(RangeLimit::NearestParent(position)) => {
474+
match file.token_at_offset(position).left_biased() {
475+
Some(token) => {
476+
if let Some(parent_block) =
477+
token.parent_ancestors().find_map(ast::BlockExpr::cast)
478+
{
479+
parent_block.syntax().descendants().for_each(hints)
480+
} else if let Some(parent_item) =
481+
token.parent_ancestors().find_map(ast::Item::cast)
482+
{
483+
parent_item.syntax().descendants().for_each(hints)
484+
} else {
485+
return acc;
486+
}
487+
}
480488
None => return acc,
481489
}
482490
}

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ pub(crate) fn handle_inlay_hints_resolve(
14461446
let resolve_hints = snap.analysis.inlay_hints(
14471447
&forced_resolve_inlay_hints_config,
14481448
file_id,
1449-
Some(RangeLimit::NearestParentBlock(hint_position)),
1449+
Some(RangeLimit::NearestParent(hint_position)),
14501450
)?;
14511451

14521452
let mut resolved_hints = resolve_hints

0 commit comments

Comments
 (0)