mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
fix: Fix inlay hint resolution being broken
This commit is contained in:
parent
ff9ebc747d
commit
2c5c12acfe
8 changed files with 89 additions and 37 deletions
|
@ -1,6 +1,5 @@
|
|||
use std::{
|
||||
fmt::{self, Write},
|
||||
hash::{BuildHasher, BuildHasherDefault},
|
||||
mem::take,
|
||||
};
|
||||
|
||||
|
@ -9,7 +8,7 @@ use hir::{
|
|||
known, ClosureStyle, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef,
|
||||
ModuleDefId, Semantics,
|
||||
};
|
||||
use ide_db::{base_db::FileRange, famous_defs::FamousDefs, FxHasher, RootDatabase};
|
||||
use ide_db::{base_db::FileRange, famous_defs::FamousDefs, RootDatabase};
|
||||
use itertools::Itertools;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use stdx::never;
|
||||
|
@ -495,6 +494,7 @@ pub(crate) fn inlay_hints_resolve(
|
|||
position: TextSize,
|
||||
hash: u64,
|
||||
config: &InlayHintsConfig,
|
||||
hasher: impl Fn(&InlayHint) -> u64,
|
||||
) -> Option<InlayHint> {
|
||||
let _p = tracing::span!(tracing::Level::INFO, "inlay_hints").entered();
|
||||
let sema = Semantics::new(db);
|
||||
|
@ -506,20 +506,16 @@ pub(crate) fn inlay_hints_resolve(
|
|||
let mut acc = Vec::new();
|
||||
|
||||
let hints = |node| hints(&mut acc, &famous_defs, config, file_id, node);
|
||||
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 None;
|
||||
}
|
||||
}
|
||||
None => return None,
|
||||
let token = file.token_at_offset(position).left_biased()?;
|
||||
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 None;
|
||||
}
|
||||
|
||||
acc.into_iter().find(|hint| BuildHasherDefault::<FxHasher>::default().hash_one(hint) == hash)
|
||||
acc.into_iter().find(|hint| hasher(hint) == hash)
|
||||
}
|
||||
|
||||
fn hints(
|
||||
|
|
|
@ -58,6 +58,8 @@ mod view_item_tree;
|
|||
mod view_memory_layout;
|
||||
mod view_mir;
|
||||
|
||||
use std::panic::UnwindSafe;
|
||||
|
||||
use cfg::CfgOptions;
|
||||
use fetch_crates::CrateInfo;
|
||||
use hir::ChangeWithProcMacros;
|
||||
|
@ -428,8 +430,11 @@ impl Analysis {
|
|||
file_id: FileId,
|
||||
position: TextSize,
|
||||
hash: u64,
|
||||
hasher: impl Fn(&InlayHint) -> u64 + Send + UnwindSafe,
|
||||
) -> Cancellable<Option<InlayHint>> {
|
||||
self.with_db(|db| inlay_hints::inlay_hints_resolve(db, file_id, position, hash, config))
|
||||
self.with_db(|db| {
|
||||
inlay_hints::inlay_hints_resolve(db, file_id, position, hash, config, hasher)
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the set of folding ranges.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue