mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-31 23:38:45 +00:00
Search for parent blocks and items when resolving inlay hints
This commit is contained in:
parent
be6d34b810
commit
8ae42b55e7
2 changed files with 17 additions and 9 deletions
|
@ -424,7 +424,7 @@ fn ty_to_text_edit(
|
||||||
|
|
||||||
pub enum RangeLimit {
|
pub enum RangeLimit {
|
||||||
Fixed(TextRange),
|
Fixed(TextRange),
|
||||||
NearestParentBlock(TextSize),
|
NearestParent(TextSize),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feature: Inlay Hints
|
// Feature: Inlay Hints
|
||||||
|
@ -470,13 +470,21 @@ pub(crate) fn inlay_hints(
|
||||||
.filter(|descendant| range.intersect(descendant.text_range()).is_some())
|
.filter(|descendant| range.intersect(descendant.text_range()).is_some())
|
||||||
.for_each(hints),
|
.for_each(hints),
|
||||||
},
|
},
|
||||||
Some(RangeLimit::NearestParentBlock(position)) => {
|
Some(RangeLimit::NearestParent(position)) => {
|
||||||
match file
|
match file.token_at_offset(position).left_biased() {
|
||||||
.token_at_offset(position)
|
Some(token) => {
|
||||||
.left_biased()
|
if let Some(parent_block) =
|
||||||
.and_then(|token| token.parent_ancestors().find_map(ast::BlockExpr::cast))
|
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,
|
None => return acc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1446,7 +1446,7 @@ pub(crate) fn handle_inlay_hints_resolve(
|
||||||
let resolve_hints = snap.analysis.inlay_hints(
|
let resolve_hints = snap.analysis.inlay_hints(
|
||||||
&forced_resolve_inlay_hints_config,
|
&forced_resolve_inlay_hints_config,
|
||||||
file_id,
|
file_id,
|
||||||
Some(RangeLimit::NearestParentBlock(hint_position)),
|
Some(RangeLimit::NearestParent(hint_position)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut resolved_hints = resolve_hints
|
let mut resolved_hints = resolve_hints
|
||||||
|
|
Loading…
Reference in a new issue