Unnamed repository; edit this file 'description' to name the repository.
Search for parent blocks and items when resolving inlay hints
Kirill Bulatov 2023-12-11
parent be6d34b · commit 8ae42b5
-rw-r--r--crates/ide/src/inlay_hints.rs24
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs2
2 files changed, 17 insertions, 9 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index cdf83ff7d2..e82d730e4a 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -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(parent_block) => parent_block.syntax().descendants().for_each(hints),
+ 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)
+ {
+ 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,
}
}
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 6ec9fe153b..d8a590c808 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -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