mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Query for nearest parent block around the hint to resolve
This way, parameter hints will be found for resolution
This commit is contained in:
parent
457b966b17
commit
be6d34b810
4 changed files with 30 additions and 20 deletions
|
@ -422,6 +422,11 @@ fn ty_to_text_edit(
|
|||
Some(builder.finish())
|
||||
}
|
||||
|
||||
pub enum RangeLimit {
|
||||
Fixed(TextRange),
|
||||
NearestParentBlock(TextSize),
|
||||
}
|
||||
|
||||
// Feature: Inlay Hints
|
||||
//
|
||||
// rust-analyzer shows additional information inline with the source code.
|
||||
|
@ -443,7 +448,7 @@ fn ty_to_text_edit(
|
|||
pub(crate) fn inlay_hints(
|
||||
db: &RootDatabase,
|
||||
file_id: FileId,
|
||||
range_limit: Option<TextRange>,
|
||||
range_limit: Option<RangeLimit>,
|
||||
config: &InlayHintsConfig,
|
||||
) -> Vec<InlayHint> {
|
||||
let _p = profile::span("inlay_hints");
|
||||
|
@ -458,13 +463,23 @@ pub(crate) fn inlay_hints(
|
|||
|
||||
let hints = |node| hints(&mut acc, &famous_defs, config, file_id, node);
|
||||
match range_limit {
|
||||
Some(range) => match file.covering_element(range) {
|
||||
Some(RangeLimit::Fixed(range)) => match file.covering_element(range) {
|
||||
NodeOrToken::Token(_) => return acc,
|
||||
NodeOrToken::Node(n) => n
|
||||
.descendants()
|
||||
.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(parent_block) => parent_block.syntax().descendants().for_each(hints),
|
||||
None => return acc,
|
||||
}
|
||||
}
|
||||
None => file.descendants().for_each(hints),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue