mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Remove hover inlay tooltips, replace them with location links
This commit is contained in:
parent
aafb0f1f8d
commit
60075a6625
15 changed files with 187 additions and 380 deletions
|
@ -29,7 +29,6 @@ use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
|
|||
use serde_json::json;
|
||||
use stdx::{format_to, never};
|
||||
use syntax::{algo, ast, AstNode, TextRange, TextSize};
|
||||
use tracing::error;
|
||||
use vfs::AbsPathBuf;
|
||||
|
||||
use crate::{
|
||||
|
@ -1360,55 +1359,10 @@ pub(crate) fn handle_inlay_hints(
|
|||
}
|
||||
|
||||
pub(crate) fn handle_inlay_hints_resolve(
|
||||
snap: GlobalStateSnapshot,
|
||||
mut hint: InlayHint,
|
||||
_snap: GlobalStateSnapshot,
|
||||
hint: InlayHint,
|
||||
) -> Result<InlayHint> {
|
||||
let _p = profile::span("handle_inlay_hints_resolve");
|
||||
let data = match hint.data.take() {
|
||||
Some(it) => it,
|
||||
None => return Ok(hint),
|
||||
};
|
||||
|
||||
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
|
||||
|
||||
match snap.url_file_version(&resolve_data.text_document.uri) {
|
||||
Some(version) if version == resolve_data.text_document.version => {}
|
||||
Some(version) => {
|
||||
error!(
|
||||
"attempted inlayHints/resolve of '{}' at version {} while server version is {}",
|
||||
resolve_data.text_document.uri, resolve_data.text_document.version, version,
|
||||
);
|
||||
return Ok(hint);
|
||||
}
|
||||
None => {
|
||||
error!(
|
||||
"attempted inlayHints/resolve of unknown file '{}' at version {}",
|
||||
resolve_data.text_document.uri, resolve_data.text_document.version,
|
||||
);
|
||||
return Ok(hint);
|
||||
}
|
||||
}
|
||||
let file_range = from_proto::file_range_uri(
|
||||
&snap,
|
||||
&resolve_data.text_document.uri,
|
||||
match resolve_data.position {
|
||||
PositionOrRange::Position(pos) => Range::new(pos, pos),
|
||||
PositionOrRange::Range(range) => range,
|
||||
},
|
||||
)?;
|
||||
let info = match snap.analysis.hover(&snap.config.hover(), file_range)? {
|
||||
None => return Ok(hint),
|
||||
Some(info) => info,
|
||||
};
|
||||
|
||||
let markup_kind =
|
||||
snap.config.hover().documentation.map_or(ide::HoverDocFormat::Markdown, |kind| kind);
|
||||
|
||||
// FIXME: hover actions?
|
||||
hint.tooltip = Some(lsp_types::InlayHintTooltip::MarkupContent(to_proto::markup_content(
|
||||
info.info.markup,
|
||||
markup_kind,
|
||||
)));
|
||||
Ok(hint)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use lsp_types::request::Request;
|
||||
use lsp_types::PositionEncodingKind;
|
||||
use lsp_types::{
|
||||
notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams,
|
||||
PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams,
|
||||
};
|
||||
use lsp_types::{PositionEncodingKind, VersionedTextDocumentIdentifier};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub enum AnalyzerStatus {}
|
||||
|
@ -568,10 +568,7 @@ pub struct CompletionResolveData {
|
|||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InlayHintResolveData {
|
||||
pub text_document: VersionedTextDocumentIdentifier,
|
||||
pub position: PositionOrRange,
|
||||
}
|
||||
pub struct InlayHintResolveData {}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct CompletionImport {
|
||||
|
|
|
@ -9,9 +9,9 @@ use ide::{
|
|||
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionItem,
|
||||
CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit,
|
||||
Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint,
|
||||
InlayHintLabel, InlayKind, Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable,
|
||||
Severity, SignatureHelp, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange,
|
||||
TextSize,
|
||||
InlayHintLabel, InlayHintLabelPart, InlayKind, Markup, NavigationTarget, ReferenceCategory,
|
||||
RenameError, Runnable, Severity, SignatureHelp, SourceChange, StructureNodeKind, SymbolKind,
|
||||
TextEdit, TextRange, TextSize,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use serde_json::to_value;
|
||||
|
@ -438,6 +438,8 @@ pub(crate) fn inlay_hint(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
let (label, tooltip) = inlay_hint_label(snap, inlay_hint.label)?;
|
||||
|
||||
Ok(lsp_types::InlayHint {
|
||||
position: match inlay_hint.kind {
|
||||
// before annotated thing
|
||||
|
@ -481,7 +483,9 @@ pub(crate) fn inlay_hint(
|
|||
| InlayKind::TypeHint
|
||||
| InlayKind::DiscriminantHint
|
||||
| InlayKind::ClosingBraceHint => false,
|
||||
InlayKind::BindingModeHint => inlay_hint.label.as_simple_str() != Some("&"),
|
||||
InlayKind::BindingModeHint => {
|
||||
matches!(&label, lsp_types::InlayHintLabel::String(s) if s != "&")
|
||||
}
|
||||
InlayKind::ParameterHint | InlayKind::LifetimeHint => true,
|
||||
}),
|
||||
kind: match inlay_hint.kind {
|
||||
|
@ -500,68 +504,67 @@ pub(crate) fn inlay_hint(
|
|||
| InlayKind::ClosingBraceHint => None,
|
||||
},
|
||||
text_edits: None,
|
||||
data: (|| match inlay_hint.tooltip {
|
||||
Some(ide::InlayTooltip::HoverOffset(file_id, offset)) => {
|
||||
let uri = url(snap, file_id);
|
||||
let line_index = snap.file_line_index(file_id).ok()?;
|
||||
|
||||
let text_document = lsp_types::VersionedTextDocumentIdentifier {
|
||||
version: snap.url_file_version(&uri)?,
|
||||
uri,
|
||||
};
|
||||
to_value(lsp_ext::InlayHintResolveData {
|
||||
text_document,
|
||||
position: lsp_ext::PositionOrRange::Position(position(&line_index, offset)),
|
||||
})
|
||||
.ok()
|
||||
}
|
||||
Some(ide::InlayTooltip::HoverRanged(file_id, text_range)) => {
|
||||
let uri = url(snap, file_id);
|
||||
let text_document = lsp_types::VersionedTextDocumentIdentifier {
|
||||
version: snap.url_file_version(&uri)?,
|
||||
uri,
|
||||
};
|
||||
let line_index = snap.file_line_index(file_id).ok()?;
|
||||
to_value(lsp_ext::InlayHintResolveData {
|
||||
text_document,
|
||||
position: lsp_ext::PositionOrRange::Range(range(&line_index, text_range)),
|
||||
})
|
||||
.ok()
|
||||
}
|
||||
_ => None,
|
||||
})(),
|
||||
tooltip: Some(match inlay_hint.tooltip {
|
||||
Some(ide::InlayTooltip::String(s)) => lsp_types::InlayHintTooltip::String(s),
|
||||
_ => lsp_types::InlayHintTooltip::String(inlay_hint.label.to_string()),
|
||||
}),
|
||||
label: inlay_hint_label(snap, inlay_hint.label)?,
|
||||
data: None,
|
||||
tooltip,
|
||||
label,
|
||||
})
|
||||
}
|
||||
|
||||
fn inlay_hint_label(
|
||||
snap: &GlobalStateSnapshot,
|
||||
label: InlayHintLabel,
|
||||
) -> Cancellable<lsp_types::InlayHintLabel> {
|
||||
Ok(match label.as_simple_str() {
|
||||
Some(s) => lsp_types::InlayHintLabel::String(s.into()),
|
||||
None => lsp_types::InlayHintLabel::LabelParts(
|
||||
label
|
||||
mut label: InlayHintLabel,
|
||||
) -> Cancellable<(lsp_types::InlayHintLabel, Option<lsp_types::InlayHintTooltip>)> {
|
||||
let res = match &*label.parts {
|
||||
[InlayHintLabelPart { linked_location: None, .. }] => {
|
||||
let InlayHintLabelPart { text, tooltip, .. } = label.parts.pop().unwrap();
|
||||
(
|
||||
lsp_types::InlayHintLabel::String(text),
|
||||
match tooltip {
|
||||
Some(ide::InlayTooltip::String(s)) => {
|
||||
Some(lsp_types::InlayHintTooltip::String(s))
|
||||
}
|
||||
Some(ide::InlayTooltip::Markdown(s)) => {
|
||||
Some(lsp_types::InlayHintTooltip::MarkupContent(lsp_types::MarkupContent {
|
||||
kind: lsp_types::MarkupKind::Markdown,
|
||||
value: s,
|
||||
}))
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let parts = label
|
||||
.parts
|
||||
.into_iter()
|
||||
.map(|part| {
|
||||
Ok(lsp_types::InlayHintLabelPart {
|
||||
value: part.text,
|
||||
tooltip: None,
|
||||
location: part
|
||||
.linked_location
|
||||
.map(|range| location(snap, range))
|
||||
.transpose()?,
|
||||
command: None,
|
||||
})
|
||||
part.linked_location.map(|range| location(snap, range)).transpose().map(
|
||||
|location| lsp_types::InlayHintLabelPart {
|
||||
value: part.text,
|
||||
tooltip: match part.tooltip {
|
||||
Some(ide::InlayTooltip::String(s)) => {
|
||||
Some(lsp_types::InlayHintLabelPartTooltip::String(s))
|
||||
}
|
||||
Some(ide::InlayTooltip::Markdown(s)) => {
|
||||
Some(lsp_types::InlayHintLabelPartTooltip::MarkupContent(
|
||||
lsp_types::MarkupContent {
|
||||
kind: lsp_types::MarkupKind::Markdown,
|
||||
value: s,
|
||||
},
|
||||
))
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
location,
|
||||
command: None,
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<Cancellable<Vec<_>>>()?,
|
||||
),
|
||||
})
|
||||
.collect::<Cancellable<_>>()?;
|
||||
(lsp_types::InlayHintLabel::LabelParts(parts), None)
|
||||
}
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue