Search for parent blocks and items when resolving inlay hints

This commit is contained in:
Kirill Bulatov 2023-12-11 15:16:55 +02:00
parent be6d34b810
commit 8ae42b55e7
2 changed files with 17 additions and 9 deletions

View file

@ -424,7 +424,7 @@ fn ty_to_text_edit(
pub enum RangeLimit {
Fixed(TextRange),
NearestParentBlock(TextSize),
NearestParent(TextSize),
}
// Feature: Inlay Hints
@ -470,13 +470,21 @@ pub(crate) fn inlay_hints(
.filter(|descendant| range.intersect(descendant.text_range()).is_some())
.for_each(hints),
},
Some(RangeLimit::NearestParentBlock(position)) => {
match file
.token_at_offset(position)
.left_biased()
.and_then(|token| token.parent_ancestors().find_map(ast::BlockExpr::cast))
Some(RangeLimit::NearestParent(position)) => {
match file.token_at_offset(position).left_biased() {
Some(token) => {
if let Some(parent_block) =
token.parent_ancestors().find_map(ast::BlockExpr::cast)
{
Some(parent_block) => parent_block.syntax().descendants().for_each(hints),
parent_block.syntax().descendants().for_each(hints)
} else if let Some(parent_item) =
token.parent_ancestors().find_map(ast::Item::cast)
{
parent_item.syntax().descendants().for_each(hints)
} else {
return acc;
}
}
None => return acc,
}
}

View file

@ -1446,7 +1446,7 @@ pub(crate) fn handle_inlay_hints_resolve(
let resolve_hints = snap.analysis.inlay_hints(
&forced_resolve_inlay_hints_config,
file_id,
Some(RangeLimit::NearestParentBlock(hint_position)),
Some(RangeLimit::NearestParent(hint_position)),
)?;
let mut resolved_hints = resolve_hints