Skip to content

Commit b44570f

Browse files
committed
Lazily compute location links in type hints again
1 parent 802d9d5 commit b44570f

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ struct InlayHintLabelBuilder<'a> {
650650
db: &'a RootDatabase,
651651
result: InlayHintLabel,
652652
last_part: String,
653-
location: Option<FileRange>,
653+
resolve: bool,
654+
location: Option<LazyProperty<FileRange>>,
654655
}
655656

656657
impl fmt::Write for InlayHintLabelBuilder<'_> {
@@ -663,11 +664,16 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
663664
fn start_location_link(&mut self, def: ModuleDefId) {
664665
never!(self.location.is_some(), "location link is already started");
665666
self.make_new_part();
666-
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
667-
let location = location.call_site();
668-
let location =
669-
FileRange { file_id: location.file_id, range: location.focus_or_full_range() };
670-
self.location = Some(location);
667+
668+
self.location = Some(if self.resolve {
669+
LazyProperty::Lazy
670+
} else {
671+
LazyProperty::Computed({
672+
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
673+
let location = location.call_site();
674+
FileRange { file_id: location.file_id, range: location.focus_or_full_range() }
675+
})
676+
});
671677
}
672678

673679
fn end_location_link(&mut self) {
@@ -681,7 +687,7 @@ impl InlayHintLabelBuilder<'_> {
681687
if !text.is_empty() {
682688
self.result.parts.push(InlayHintLabelPart {
683689
text,
684-
linked_location: self.location.take().map(LazyProperty::Computed),
690+
linked_location: self.location.take(),
685691
tooltip: None,
686692
});
687693
}
@@ -753,6 +759,7 @@ fn label_of_ty(
753759
last_part: String::new(),
754760
location: None,
755761
result: InlayHintLabel::default(),
762+
resolve: config.fields_to_resolve.resolve_label_location,
756763
};
757764
let _ = rec(sema, famous_defs, config.max_length, ty, &mut label_builder, config, edition);
758765
let r = label_builder.finish();

src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use syntax::{
1212
};
1313

1414
use crate::{
15-
inlay_hints::LazyProperty, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind,
15+
inlay_hints::LazyProperty, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig,
16+
InlayKind,
1617
};
1718

1819
pub(super) fn hints(

src/tools/rust-analyzer/crates/ide/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ pub use crate::{
9191
inlay_hints::{
9292
AdjustmentHints, AdjustmentHintsMode, ClosureReturnTypeHints, DiscriminantHints,
9393
GenericParameterHints, InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart,
94-
InlayHintPosition, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints, LazyProperty
94+
InlayHintPosition, InlayHintsConfig, InlayKind, InlayTooltip, LazyProperty,
95+
LifetimeElisionHints,
9596
},
9697
join_lines::JoinLinesConfig,
9798
markup::Markup,

0 commit comments

Comments
 (0)