Skip to content

Commit

Permalink
Lazily compute location links in type hints again
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jan 24, 2025
1 parent f5b86e0 commit 41e6a87
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
21 changes: 14 additions & 7 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ struct InlayHintLabelBuilder<'a> {
db: &'a RootDatabase,
result: InlayHintLabel,
last_part: String,
location: Option<FileRange>,
resolve: bool,
location: Option<LazyProperty<FileRange>>,
}

impl fmt::Write for InlayHintLabelBuilder<'_> {
Expand All @@ -663,11 +664,16 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
fn start_location_link(&mut self, def: ModuleDefId) {
never!(self.location.is_some(), "location link is already started");
self.make_new_part();
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
let location = location.call_site();
let location =
FileRange { file_id: location.file_id, range: location.focus_or_full_range() };
self.location = Some(location);

self.location = Some(if self.resolve {
LazyProperty::Lazy
} else {
LazyProperty::Computed({
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
let location = location.call_site();
FileRange { file_id: location.file_id, range: location.focus_or_full_range() }
})
});
}

fn end_location_link(&mut self) {
Expand All @@ -681,7 +687,7 @@ impl InlayHintLabelBuilder<'_> {
if !text.is_empty() {
self.result.parts.push(InlayHintLabelPart {
text,
linked_location: self.location.take().map(LazyProperty::Computed),
linked_location: self.location.take(),
tooltip: None,
});
}
Expand Down Expand Up @@ -753,6 +759,7 @@ fn label_of_ty(
last_part: String::new(),
location: None,
result: InlayHintLabel::default(),
resolve: config.fields_to_resolve.resolve_label_location,
};
let _ = rec(sema, famous_defs, config.max_length, ty, &mut label_builder, config, edition);
let r = label_builder.finish();
Expand Down
3 changes: 2 additions & 1 deletion crates/ide/src/inlay_hints/closing_brace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use syntax::{
};

use crate::{
inlay_hints::LazyProperty, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind,
inlay_hints::LazyProperty, InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig,
InlayKind,
};

pub(super) fn hints(
Expand Down
3 changes: 2 additions & 1 deletion crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ pub use crate::{
inlay_hints::{
AdjustmentHints, AdjustmentHintsMode, ClosureReturnTypeHints, DiscriminantHints,
GenericParameterHints, InlayFieldsToResolve, InlayHint, InlayHintLabel, InlayHintLabelPart,
InlayHintPosition, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints, LazyProperty
InlayHintPosition, InlayHintsConfig, InlayKind, InlayTooltip, LazyProperty,
LifetimeElisionHints,
},
join_lines::JoinLinesConfig,
markup::Markup,
Expand Down

0 comments on commit 41e6a87

Please sign in to comment.