mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +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
|
@ -11,7 +11,7 @@ use smallvec::{smallvec, SmallVec};
|
||||||
use stdx::never;
|
use stdx::never;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
match_ast, NodeOrToken, SyntaxNode, TextRange, TextSize,
|
match_ast, NodeOrToken, SyntaxNode, TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{navigation_target::TryToNav, FileId};
|
use crate::{navigation_target::TryToNav, FileId};
|
||||||
|
@ -110,16 +110,21 @@ pub struct InlayHint {
|
||||||
pub kind: InlayKind,
|
pub kind: InlayKind,
|
||||||
/// The actual label to show in the inlay hint.
|
/// The actual label to show in the inlay hint.
|
||||||
pub label: InlayHintLabel,
|
pub label: InlayHintLabel,
|
||||||
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
|
}
|
||||||
/// hover requests to show.
|
|
||||||
pub tooltip: Option<InlayTooltip>,
|
impl InlayHint {
|
||||||
|
fn closing_paren(range: TextRange) -> InlayHint {
|
||||||
|
InlayHint { range, kind: InlayKind::ClosingParenthesis, label: InlayHintLabel::from(")") }
|
||||||
|
}
|
||||||
|
fn opening_paren(range: TextRange) -> InlayHint {
|
||||||
|
InlayHint { range, kind: InlayKind::OpeningParenthesis, label: InlayHintLabel::from("(") }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InlayTooltip {
|
pub enum InlayTooltip {
|
||||||
String(String),
|
String(String),
|
||||||
HoverRanged(FileId, TextRange),
|
Markdown(String),
|
||||||
HoverOffset(FileId, TextSize),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -128,37 +133,59 @@ pub struct InlayHintLabel {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlayHintLabel {
|
impl InlayHintLabel {
|
||||||
pub fn as_simple_str(&self) -> Option<&str> {
|
pub fn simple(
|
||||||
match &*self.parts {
|
s: impl Into<String>,
|
||||||
[part] => part.as_simple_str(),
|
tooltip: Option<InlayTooltip>,
|
||||||
_ => None,
|
linked_location: Option<FileRange>,
|
||||||
|
) -> InlayHintLabel {
|
||||||
|
InlayHintLabel {
|
||||||
|
parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location, tooltip }],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepend_str(&mut self, s: &str) {
|
pub fn prepend_str(&mut self, s: &str) {
|
||||||
match &mut *self.parts {
|
match &mut *self.parts {
|
||||||
[part, ..] if part.as_simple_str().is_some() => part.text = format!("{s}{}", part.text),
|
[InlayHintLabelPart { text, linked_location: None, tooltip: None }, ..] => {
|
||||||
_ => self.parts.insert(0, InlayHintLabelPart { text: s.into(), linked_location: None }),
|
text.insert_str(0, s)
|
||||||
|
}
|
||||||
|
_ => self.parts.insert(
|
||||||
|
0,
|
||||||
|
InlayHintLabelPart { text: s.into(), linked_location: None, tooltip: None },
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_str(&mut self, s: &str) {
|
pub fn append_str(&mut self, s: &str) {
|
||||||
match &mut *self.parts {
|
match &mut *self.parts {
|
||||||
[.., part] if part.as_simple_str().is_some() => part.text.push_str(s),
|
[.., InlayHintLabelPart { text, linked_location: None, tooltip: None }] => {
|
||||||
_ => self.parts.push(InlayHintLabelPart { text: s.into(), linked_location: None }),
|
text.push_str(s)
|
||||||
|
}
|
||||||
|
_ => self.parts.push(InlayHintLabelPart {
|
||||||
|
text: s.into(),
|
||||||
|
linked_location: None,
|
||||||
|
tooltip: None,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for InlayHintLabel {
|
impl From<String> for InlayHintLabel {
|
||||||
fn from(s: String) -> Self {
|
fn from(s: String) -> Self {
|
||||||
Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None }] }
|
Self {
|
||||||
|
parts: smallvec![InlayHintLabelPart { text: s, linked_location: None, tooltip: None }],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for InlayHintLabel {
|
impl From<&str> for InlayHintLabel {
|
||||||
fn from(s: &str) -> Self {
|
fn from(s: &str) -> Self {
|
||||||
Self { parts: smallvec![InlayHintLabelPart { text: s.into(), linked_location: None }] }
|
Self {
|
||||||
|
parts: smallvec![InlayHintLabelPart {
|
||||||
|
text: s.into(),
|
||||||
|
linked_location: None,
|
||||||
|
tooltip: None
|
||||||
|
}],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,25 +209,25 @@ pub struct InlayHintLabelPart {
|
||||||
/// When setting this, no tooltip must be set on the containing hint, or VS Code will display
|
/// When setting this, no tooltip must be set on the containing hint, or VS Code will display
|
||||||
/// them both.
|
/// them both.
|
||||||
pub linked_location: Option<FileRange>,
|
pub linked_location: Option<FileRange>,
|
||||||
}
|
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
|
||||||
|
/// hover requests to show.
|
||||||
impl InlayHintLabelPart {
|
pub tooltip: Option<InlayTooltip>,
|
||||||
pub fn as_simple_str(&self) -> Option<&str> {
|
|
||||||
match self {
|
|
||||||
Self { text, linked_location: None } => Some(text),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for InlayHintLabelPart {
|
impl fmt::Debug for InlayHintLabelPart {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self.as_simple_str() {
|
match self {
|
||||||
Some(string) => string.fmt(f),
|
Self { text, linked_location: None, tooltip: None } => text.fmt(f),
|
||||||
None => f
|
Self { text, linked_location, tooltip } => f
|
||||||
.debug_struct("InlayHintLabelPart")
|
.debug_struct("InlayHintLabelPart")
|
||||||
.field("text", &self.text)
|
.field("text", text)
|
||||||
.field("linked_location", &self.linked_location)
|
.field("linked_location", linked_location)
|
||||||
|
.field(
|
||||||
|
"tooltip",
|
||||||
|
&tooltip.as_ref().map_or("", |it| match it {
|
||||||
|
InlayTooltip::String(it) | InlayTooltip::Markdown(it) => it,
|
||||||
|
}),
|
||||||
|
)
|
||||||
.finish(),
|
.finish(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,6 +276,7 @@ impl InlayHintLabelBuilder<'_> {
|
||||||
self.result.parts.push(InlayHintLabelPart {
|
self.result.parts.push(InlayHintLabelPart {
|
||||||
text: take(&mut self.last_part),
|
text: take(&mut self.last_part),
|
||||||
linked_location: self.location.take(),
|
linked_location: self.location.take(),
|
||||||
|
tooltip: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,27 +44,12 @@ pub(super) fn hints(
|
||||||
mode_and_needs_parens_for_adjustment_hints(expr, config.adjustment_hints_mode);
|
mode_and_needs_parens_for_adjustment_hints(expr, config.adjustment_hints_mode);
|
||||||
|
|
||||||
if needs_outer_parens {
|
if needs_outer_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
|
||||||
range: expr.syntax().text_range(),
|
|
||||||
kind: InlayKind::OpeningParenthesis,
|
|
||||||
label: "(".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if postfix && needs_inner_parens {
|
if postfix && needs_inner_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
|
||||||
range: expr.syntax().text_range(),
|
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
|
||||||
kind: InlayKind::OpeningParenthesis,
|
|
||||||
label: "(".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
acc.push(InlayHint {
|
|
||||||
range: expr.syntax().text_range(),
|
|
||||||
kind: InlayKind::ClosingParenthesis,
|
|
||||||
label: ")".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut tmp0, mut tmp1);
|
let (mut tmp0, mut tmp1);
|
||||||
|
@ -118,30 +103,14 @@ pub(super) fn hints(
|
||||||
InlayKind::AdjustmentHint
|
InlayKind::AdjustmentHint
|
||||||
},
|
},
|
||||||
label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() },
|
label: if postfix { format!(".{}", text.trim_end()).into() } else { text.into() },
|
||||||
tooltip: None,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if !postfix && needs_inner_parens {
|
if !postfix && needs_inner_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint::opening_paren(expr.syntax().text_range()));
|
||||||
range: expr.syntax().text_range(),
|
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
|
||||||
kind: InlayKind::OpeningParenthesis,
|
|
||||||
label: "(".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
acc.push(InlayHint {
|
|
||||||
range: expr.syntax().text_range(),
|
|
||||||
kind: InlayKind::ClosingParenthesis,
|
|
||||||
label: ")".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if needs_outer_parens {
|
if needs_outer_parens {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint::closing_paren(expr.syntax().text_range()));
|
||||||
range: expr.syntax().text_range(),
|
|
||||||
kind: InlayKind::ClosingParenthesis,
|
|
||||||
label: ")".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,7 @@ use syntax::{
|
||||||
match_ast,
|
match_ast,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind};
|
||||||
inlay_hints::closure_has_block_body, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::label_of_ty;
|
use super::label_of_ty;
|
||||||
|
|
||||||
|
@ -22,7 +20,7 @@ pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
_file_id: FileId,
|
||||||
pat: &ast::IdentPat,
|
pat: &ast::IdentPat,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if !config.type_hints {
|
if !config.type_hints {
|
||||||
|
@ -52,10 +50,6 @@ pub(super) fn hints(
|
||||||
},
|
},
|
||||||
kind: InlayKind::TypeHint,
|
kind: InlayKind::TypeHint,
|
||||||
label,
|
label,
|
||||||
tooltip: pat
|
|
||||||
.name()
|
|
||||||
.map(|it| it.syntax().text_range())
|
|
||||||
.map(|it| InlayTooltip::HoverRanged(file_id, it)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
|
@ -326,14 +320,6 @@ fn main(a: SliceIter<'_, Container>) {
|
||||||
label: [
|
label: [
|
||||||
"impl Iterator<Item = impl Iterator<Item = &&str>>",
|
"impl Iterator<Item = impl Iterator<Item = &&str>>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
484..554,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 484..485,
|
range: 484..485,
|
||||||
|
@ -350,6 +336,7 @@ fn main(a: SliceIter<'_, Container>) {
|
||||||
range: 289..298,
|
range: 289..298,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"<",
|
"<",
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
|
@ -362,17 +349,10 @@ fn main(a: SliceIter<'_, Container>) {
|
||||||
range: 238..247,
|
range: 238..247,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
">",
|
">",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
484..485,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
@ -7,7 +7,7 @@ use ide_db::RootDatabase;
|
||||||
|
|
||||||
use syntax::ast::{self, AstNode};
|
use syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
|
use crate::{InlayHint, InlayHintsConfig, InlayKind};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -44,7 +44,6 @@ pub(super) fn hints(
|
||||||
range,
|
range,
|
||||||
kind: InlayKind::BindingModeHint,
|
kind: InlayKind::BindingModeHint,
|
||||||
label: r.to_string().into(),
|
label: r.to_string().into(),
|
||||||
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
match pat {
|
match pat {
|
||||||
|
@ -59,22 +58,11 @@ pub(super) fn hints(
|
||||||
range: pat.syntax().text_range(),
|
range: pat.syntax().text_range(),
|
||||||
kind: InlayKind::BindingModeHint,
|
kind: InlayKind::BindingModeHint,
|
||||||
label: bm.to_string().into(),
|
label: bm.to_string().into(),
|
||||||
tooltip: Some(InlayTooltip::String("Inferred binding mode".into())),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
|
ast::Pat::OrPat(pat) if !pattern_adjustments.is_empty() && outer_paren_pat.is_none() => {
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint::opening_paren(pat.syntax().text_range()));
|
||||||
range: pat.syntax().text_range(),
|
acc.push(InlayHint::closing_paren(pat.syntax().text_range()));
|
||||||
kind: InlayKind::OpeningParenthesis,
|
|
||||||
label: "(".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
acc.push(InlayHint {
|
|
||||||
range: pat.syntax().text_range(),
|
|
||||||
kind: InlayKind::ClosingParenthesis,
|
|
||||||
label: ")".into(),
|
|
||||||
tooltip: None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use syntax::{
|
||||||
Direction, NodeOrToken, SyntaxKind, T,
|
Direction, NodeOrToken, SyntaxKind, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{FileId, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
|
use crate::{FileId, InlayHint, InlayHintsConfig, InlayKind};
|
||||||
|
|
||||||
use super::label_of_ty;
|
use super::label_of_ty;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
_file_id: FileId,
|
||||||
expr: &ast::Expr,
|
expr: &ast::Expr,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if !config.chaining_hints {
|
if !config.chaining_hints {
|
||||||
|
@ -61,7 +61,6 @@ pub(super) fn hints(
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::ChainingHint,
|
kind: InlayKind::ChainingHint,
|
||||||
label: label_of_ty(famous_defs, config, ty)?,
|
label: label_of_ty(famous_defs, config, ty)?,
|
||||||
tooltip: Some(InlayTooltip::HoverRanged(file_id, expr.syntax().text_range())),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,17 +123,10 @@ fn main() {
|
||||||
range: 63..64,
|
range: 63..64,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
147..172,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 147..154,
|
range: 147..154,
|
||||||
|
@ -151,17 +143,10 @@ fn main() {
|
||||||
range: 7..8,
|
range: 7..8,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
147..154,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -214,14 +199,6 @@ fn main() {
|
||||||
label: [
|
label: [
|
||||||
"C",
|
"C",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
143..190,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 143..179,
|
range: 143..179,
|
||||||
|
@ -229,14 +206,6 @@ fn main() {
|
||||||
label: [
|
label: [
|
||||||
"B",
|
"B",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
143..179,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -282,17 +251,10 @@ fn main() {
|
||||||
range: 51..52,
|
range: 51..52,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
143..190,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 143..179,
|
range: 143..179,
|
||||||
|
@ -309,17 +271,10 @@ fn main() {
|
||||||
range: 29..30,
|
range: 29..30,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
143..179,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -366,6 +321,7 @@ fn main() {
|
||||||
range: 23..24,
|
range: 23..24,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"<",
|
"<",
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
|
@ -378,17 +334,10 @@ fn main() {
|
||||||
range: 55..56,
|
range: 55..56,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"<i32, bool>>",
|
"<i32, bool>>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
246..283,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 246..265,
|
range: 246..265,
|
||||||
|
@ -405,6 +354,7 @@ fn main() {
|
||||||
range: 7..8,
|
range: 7..8,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"<",
|
"<",
|
||||||
InlayHintLabelPart {
|
InlayHintLabelPart {
|
||||||
|
@ -417,17 +367,10 @@ fn main() {
|
||||||
range: 55..56,
|
range: 55..56,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"<i32, bool>>",
|
"<i32, bool>>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
246..265,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -467,14 +410,6 @@ fn main() {
|
||||||
label: [
|
label: [
|
||||||
"impl Iterator<Item = ()>",
|
"impl Iterator<Item = ()>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
174..241,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..224,
|
range: 174..224,
|
||||||
|
@ -482,14 +417,6 @@ fn main() {
|
||||||
label: [
|
label: [
|
||||||
"impl Iterator<Item = ()>",
|
"impl Iterator<Item = ()>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
174..224,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..206,
|
range: 174..206,
|
||||||
|
@ -497,14 +424,6 @@ fn main() {
|
||||||
label: [
|
label: [
|
||||||
"impl Iterator<Item = ()>",
|
"impl Iterator<Item = ()>",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
174..206,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 174..189,
|
range: 174..189,
|
||||||
|
@ -521,17 +440,10 @@ fn main() {
|
||||||
range: 24..30,
|
range: 24..30,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
174..189,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -577,17 +489,10 @@ fn main() {
|
||||||
range: 7..13,
|
range: 7..13,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
124..130,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 145..185,
|
range: 145..185,
|
||||||
|
@ -604,17 +509,10 @@ fn main() {
|
||||||
range: 7..13,
|
range: 7..13,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
145..185,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 145..168,
|
range: 145..168,
|
||||||
|
@ -631,32 +529,28 @@ fn main() {
|
||||||
range: 7..13,
|
range: 7..13,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
],
|
],
|
||||||
tooltip: Some(
|
|
||||||
HoverRanged(
|
|
||||||
FileId(
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
145..168,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range: 222..228,
|
range: 222..228,
|
||||||
kind: ParameterHint,
|
kind: ParameterHint,
|
||||||
label: [
|
label: [
|
||||||
"self",
|
InlayHintLabelPart {
|
||||||
],
|
text: "self",
|
||||||
tooltip: Some(
|
linked_location: Some(
|
||||||
HoverOffset(
|
FileRange {
|
||||||
FileId(
|
file_id: FileId(
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
42,
|
range: 42..46,
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
|
tooltip: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
//! ```
|
//! ```
|
||||||
use hir::{HirDisplay, Semantics};
|
use hir::{HirDisplay, Semantics};
|
||||||
use ide_db::{base_db::FileRange, RootDatabase};
|
use ide_db::{base_db::FileRange, RootDatabase};
|
||||||
use smallvec::smallvec;
|
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, HasName},
|
ast::{self, AstNode, HasName},
|
||||||
match_ast, SyntaxKind, SyntaxNode, T,
|
match_ast, SyntaxKind, SyntaxNode, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{FileId, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind};
|
||||||
inlay_hints::InlayHintLabelPart, FileId, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -117,10 +114,7 @@ pub(super) fn hints(
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: closing_token.text_range(),
|
range: closing_token.text_range(),
|
||||||
kind: InlayKind::ClosingBraceHint,
|
kind: InlayKind::ClosingBraceHint,
|
||||||
label: InlayHintLabel {
|
label: InlayHintLabel::simple(label, None, linked_location),
|
||||||
parts: smallvec![InlayHintLabelPart { text: label, linked_location }],
|
|
||||||
},
|
|
||||||
tooltip: None, // provided by label part location
|
|
||||||
});
|
});
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
|
@ -4,7 +4,7 @@ use syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
inlay_hints::closure_has_block_body, ClosureReturnTypeHints, InlayHint, InlayHintsConfig,
|
inlay_hints::closure_has_block_body, ClosureReturnTypeHints, InlayHint, InlayHintsConfig,
|
||||||
InlayKind, InlayTooltip,
|
InlayKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::label_of_ty;
|
use super::label_of_ty;
|
||||||
|
@ -13,7 +13,7 @@ pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
_file_id: FileId,
|
||||||
closure: ast::ClosureExpr,
|
closure: ast::ClosureExpr,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if config.closure_return_type_hints == ClosureReturnTypeHints::Never {
|
if config.closure_return_type_hints == ClosureReturnTypeHints::Never {
|
||||||
|
@ -43,7 +43,6 @@ pub(super) fn hints(
|
||||||
range: param_list.syntax().text_range(),
|
range: param_list.syntax().text_range(),
|
||||||
kind: InlayKind::ClosureReturnTypeHint,
|
kind: InlayKind::ClosureReturnTypeHint,
|
||||||
label: label_of_ty(famous_defs, config, ty)?,
|
label: label_of_ty(famous_defs, config, ty)?,
|
||||||
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
|
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
|
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
|
||||||
use syntax::ast::{self, AstNode, HasName};
|
use syntax::ast::{self, AstNode, HasName};
|
||||||
|
|
||||||
use crate::{DiscriminantHints, InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
|
use crate::{
|
||||||
|
DiscriminantHints, InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind, InlayTooltip,
|
||||||
|
};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -42,14 +44,17 @@ pub(super) fn hints(
|
||||||
None => name.syntax().text_range(),
|
None => name.syntax().text_range(),
|
||||||
},
|
},
|
||||||
kind: InlayKind::DiscriminantHint,
|
kind: InlayKind::DiscriminantHint,
|
||||||
label: match &d {
|
label: InlayHintLabel::simple(
|
||||||
Ok(v) => format!("{}", v).into(),
|
match &d {
|
||||||
|
Ok(v) => format!("{}", v),
|
||||||
Err(_) => "?".into(),
|
Err(_) => "?".into(),
|
||||||
},
|
},
|
||||||
tooltip: Some(InlayTooltip::String(match &d {
|
Some(InlayTooltip::String(match &d {
|
||||||
Ok(_) => "enum variant discriminant".into(),
|
Ok(_) => "enum variant discriminant".into(),
|
||||||
Err(e) => format!("{e:?}").into(),
|
Err(e) => format!("{e:?}").into(),
|
||||||
})),
|
})),
|
||||||
|
None,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
|
|
|
@ -10,7 +10,7 @@ use syntax::{
|
||||||
SyntaxToken,
|
SyntaxToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints};
|
use crate::{InlayHint, InlayHintsConfig, InlayKind, LifetimeElisionHints};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -25,7 +25,6 @@ pub(super) fn hints(
|
||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::LifetimeHint,
|
kind: InlayKind::LifetimeHint,
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
tooltip: Some(InlayTooltip::String("Elided lifetime".into())),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let param_list = func.param_list()?;
|
let param_list = func.param_list()?;
|
||||||
|
@ -190,14 +189,12 @@ pub(super) fn hints(
|
||||||
if is_empty { "" } else { ", " }
|
if is_empty { "" } else { ", " }
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
tooltip: Some(InlayTooltip::String("Elided lifetimes".into())),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
(None, allocated_lifetimes) => acc.push(InlayHint {
|
(None, allocated_lifetimes) => acc.push(InlayHint {
|
||||||
range: func.name()?.syntax().text_range(),
|
range: func.name()?.syntax().text_range(),
|
||||||
kind: InlayKind::GenericParamListHint,
|
kind: InlayKind::GenericParamListHint,
|
||||||
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
|
label: format!("<{}>", allocated_lifetimes.iter().format(", "),).into(),
|
||||||
tooltip: Some(InlayTooltip::String("Elided lifetimes".into())),
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
|
|
|
@ -8,7 +8,7 @@ use syntax::{
|
||||||
SyntaxKind,
|
SyntaxKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints};
|
use crate::{InlayHint, InlayHintsConfig, InlayKind, LifetimeElisionHints};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -34,7 +34,6 @@ pub(super) fn hints(
|
||||||
range: t.text_range(),
|
range: t.text_range(),
|
||||||
kind: InlayKind::LifetimeHint,
|
kind: InlayKind::LifetimeHint,
|
||||||
label: "'static".to_owned().into(),
|
label: "'static".to_owned().into(),
|
||||||
tooltip: Some(InlayTooltip::String("Elided static lifetime".into())),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use ide_db::{base_db::FileRange, RootDatabase};
|
||||||
use stdx::to_lower_snake_case;
|
use stdx::to_lower_snake_case;
|
||||||
use syntax::ast::{self, AstNode, HasArgList, HasName, UnaryOp};
|
use syntax::ast::{self, AstNode, HasArgList, HasName, UnaryOp};
|
||||||
|
|
||||||
use crate::{InlayHint, InlayHintsConfig, InlayKind, InlayTooltip};
|
use crate::{InlayHint, InlayHintLabel, InlayHintsConfig, InlayKind};
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
|
@ -43,12 +43,12 @@ pub(super) fn hints(
|
||||||
!should_hide_param_name_hint(sema, &callable, param_name, arg)
|
!should_hide_param_name_hint(sema, &callable, param_name, arg)
|
||||||
})
|
})
|
||||||
.map(|(param, param_name, _, FileRange { range, .. })| {
|
.map(|(param, param_name, _, FileRange { range, .. })| {
|
||||||
let mut tooltip = None;
|
let mut linked_location = None;
|
||||||
if let Some(name) = param {
|
if let Some(name) = param {
|
||||||
if let hir::CallableKind::Function(f) = callable.kind() {
|
if let hir::CallableKind::Function(f) = callable.kind() {
|
||||||
// assert the file is cached so we can map out of macros
|
// assert the file is cached so we can map out of macros
|
||||||
if let Some(_) = sema.source(f) {
|
if let Some(_) = sema.source(f) {
|
||||||
tooltip = sema.original_range_opt(name.syntax());
|
linked_location = sema.original_range_opt(name.syntax());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,7 @@ pub(super) fn hints(
|
||||||
InlayHint {
|
InlayHint {
|
||||||
range,
|
range,
|
||||||
kind: InlayKind::ParameterHint,
|
kind: InlayKind::ParameterHint,
|
||||||
label: param_name.into(),
|
label: InlayHintLabel::simple(param_name, None, linked_location),
|
||||||
tooltip: tooltip.map(|it| InlayTooltip::HoverOffset(it.file_id, it.range.start())),
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ pub use crate::{
|
||||||
hover::{HoverAction, HoverConfig, HoverDocFormat, HoverGotoTypeData, HoverResult},
|
hover::{HoverAction, HoverConfig, HoverDocFormat, HoverGotoTypeData, HoverResult},
|
||||||
inlay_hints::{
|
inlay_hints::{
|
||||||
AdjustmentHints, AdjustmentHintsMode, ClosureReturnTypeHints, DiscriminantHints, InlayHint,
|
AdjustmentHints, AdjustmentHintsMode, ClosureReturnTypeHints, DiscriminantHints, InlayHint,
|
||||||
InlayHintLabel, InlayHintsConfig, InlayKind, InlayTooltip, LifetimeElisionHints,
|
InlayHintLabel, InlayHintLabelPart, InlayHintsConfig, InlayKind, InlayTooltip,
|
||||||
|
LifetimeElisionHints,
|
||||||
},
|
},
|
||||||
join_lines::JoinLinesConfig,
|
join_lines::JoinLinesConfig,
|
||||||
markup::Markup,
|
markup::Markup,
|
||||||
|
|
|
@ -29,7 +29,6 @@ use project_model::{ManifestPath, ProjectWorkspace, TargetKind};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use stdx::{format_to, never};
|
use stdx::{format_to, never};
|
||||||
use syntax::{algo, ast, AstNode, TextRange, TextSize};
|
use syntax::{algo, ast, AstNode, TextRange, TextSize};
|
||||||
use tracing::error;
|
|
||||||
use vfs::AbsPathBuf;
|
use vfs::AbsPathBuf;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -1360,55 +1359,10 @@ pub(crate) fn handle_inlay_hints(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_inlay_hints_resolve(
|
pub(crate) fn handle_inlay_hints_resolve(
|
||||||
snap: GlobalStateSnapshot,
|
_snap: GlobalStateSnapshot,
|
||||||
mut hint: InlayHint,
|
hint: InlayHint,
|
||||||
) -> Result<InlayHint> {
|
) -> Result<InlayHint> {
|
||||||
let _p = profile::span("handle_inlay_hints_resolve");
|
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)
|
Ok(hint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
|
|
||||||
use lsp_types::request::Request;
|
use lsp_types::request::Request;
|
||||||
|
use lsp_types::PositionEncodingKind;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams,
|
notification::Notification, CodeActionKind, DocumentOnTypeFormattingParams,
|
||||||
PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams,
|
PartialResultParams, Position, Range, TextDocumentIdentifier, WorkDoneProgressParams,
|
||||||
};
|
};
|
||||||
use lsp_types::{PositionEncodingKind, VersionedTextDocumentIdentifier};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub enum AnalyzerStatus {}
|
pub enum AnalyzerStatus {}
|
||||||
|
@ -568,10 +568,7 @@ pub struct CompletionResolveData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct InlayHintResolveData {
|
pub struct InlayHintResolveData {}
|
||||||
pub text_document: VersionedTextDocumentIdentifier,
|
|
||||||
pub position: PositionOrRange,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct CompletionImport {
|
pub struct CompletionImport {
|
||||||
|
|
|
@ -9,9 +9,9 @@ use ide::{
|
||||||
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionItem,
|
Annotation, AnnotationKind, Assist, AssistKind, Cancellable, CompletionItem,
|
||||||
CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit,
|
CompletionItemKind, CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit,
|
||||||
Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint,
|
Fold, FoldKind, Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint,
|
||||||
InlayHintLabel, InlayKind, Markup, NavigationTarget, ReferenceCategory, RenameError, Runnable,
|
InlayHintLabel, InlayHintLabelPart, InlayKind, Markup, NavigationTarget, ReferenceCategory,
|
||||||
Severity, SignatureHelp, SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange,
|
RenameError, Runnable, Severity, SignatureHelp, SourceChange, StructureNodeKind, SymbolKind,
|
||||||
TextSize,
|
TextEdit, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde_json::to_value;
|
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 {
|
Ok(lsp_types::InlayHint {
|
||||||
position: match inlay_hint.kind {
|
position: match inlay_hint.kind {
|
||||||
// before annotated thing
|
// before annotated thing
|
||||||
|
@ -481,7 +483,9 @@ pub(crate) fn inlay_hint(
|
||||||
| InlayKind::TypeHint
|
| InlayKind::TypeHint
|
||||||
| InlayKind::DiscriminantHint
|
| InlayKind::DiscriminantHint
|
||||||
| InlayKind::ClosingBraceHint => false,
|
| 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,
|
InlayKind::ParameterHint | InlayKind::LifetimeHint => true,
|
||||||
}),
|
}),
|
||||||
kind: match inlay_hint.kind {
|
kind: match inlay_hint.kind {
|
||||||
|
@ -500,68 +504,67 @@ pub(crate) fn inlay_hint(
|
||||||
| InlayKind::ClosingBraceHint => None,
|
| InlayKind::ClosingBraceHint => None,
|
||||||
},
|
},
|
||||||
text_edits: None,
|
text_edits: None,
|
||||||
data: (|| match inlay_hint.tooltip {
|
data: None,
|
||||||
Some(ide::InlayTooltip::HoverOffset(file_id, offset)) => {
|
tooltip,
|
||||||
let uri = url(snap, file_id);
|
label,
|
||||||
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)?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inlay_hint_label(
|
fn inlay_hint_label(
|
||||||
snap: &GlobalStateSnapshot,
|
snap: &GlobalStateSnapshot,
|
||||||
label: InlayHintLabel,
|
mut label: InlayHintLabel,
|
||||||
) -> Cancellable<lsp_types::InlayHintLabel> {
|
) -> Cancellable<(lsp_types::InlayHintLabel, Option<lsp_types::InlayHintTooltip>)> {
|
||||||
Ok(match label.as_simple_str() {
|
let res = match &*label.parts {
|
||||||
Some(s) => lsp_types::InlayHintLabel::String(s.into()),
|
[InlayHintLabelPart { linked_location: None, .. }] => {
|
||||||
None => lsp_types::InlayHintLabel::LabelParts(
|
let InlayHintLabelPart { text, tooltip, .. } = label.parts.pop().unwrap();
|
||||||
label
|
(
|
||||||
|
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
|
.parts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|part| {
|
.map(|part| {
|
||||||
Ok(lsp_types::InlayHintLabelPart {
|
part.linked_location.map(|range| location(snap, range)).transpose().map(
|
||||||
|
|location| lsp_types::InlayHintLabelPart {
|
||||||
value: part.text,
|
value: part.text,
|
||||||
tooltip: None,
|
tooltip: match part.tooltip {
|
||||||
location: part
|
Some(ide::InlayTooltip::String(s)) => {
|
||||||
.linked_location
|
Some(lsp_types::InlayHintLabelPartTooltip::String(s))
|
||||||
.map(|range| location(snap, range))
|
}
|
||||||
.transpose()?,
|
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,
|
command: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
.collect::<Cancellable<_>>()?;
|
||||||
.collect::<Cancellable<Vec<_>>>()?,
|
(lsp_types::InlayHintLabel::LabelParts(parts), None)
|
||||||
),
|
}
|
||||||
})
|
};
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
|
static TOKEN_RESULT_COUNTER: AtomicU32 = AtomicU32::new(1);
|
||||||
|
|
Loading…
Reference in a new issue