diff options
| author | Kirill Bulatov <mail4score@gmail.com> | 2023-12-11 15:16:55 +0200 |
|---|---|---|
| committer | Kirill Bulatov <mail4score@gmail.com> | 2023-12-11 15:16:55 +0200 |
| commit | 8ae42b55e79a127c811d85411ecea204b9529091 (patch) | |
| tree | 7836ee958a94a262650559e7cf1da212bc7c24aa | |
| parent | be6d34b810141710f60a94959a8cc67adceb1fca (diff) | |
| download | rust-8ae42b55e79a127c811d85411ecea204b9529091.tar.gz rust-8ae42b55e79a127c811d85411ecea204b9529091.zip | |
Search for parent blocks and items when resolving inlay hints
| -rw-r--r-- | crates/ide/src/inlay_hints.rs | 24 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/handlers/request.rs | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index cdf83ff7d28..e82d730e4a3 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 6ec9fe153b9..d8a590c8088 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 |
