@@ -306,11 +306,20 @@ impl DisplayMap {
let new_inlays = to_insert
.into_iter()
.map(|(inlay_id, hint_anchor, hint)| {
+ let mut text = hint.text();
+ // TODO kb styling instead?
+ if hint.padding_right {
+ text.push(' ');
+ }
+ if hint.padding_left {
+ text.insert(0, ' ');
+ }
+
(
inlay_id,
InlayProperties {
position: hint_anchor.bias_left(&buffer_snapshot),
- text: hint.text(),
+ text,
},
)
})
@@ -1,5 +1,5 @@
use crate::{
- DocumentHighlight, Hover, HoverBlock, HoverBlockKind, InlayHint, InlayHintLabel,
+ DocumentHighlight, Hover, HoverBlock, HoverBlockKind, InlayHint, InlayHintKind, InlayHintLabel,
InlayHintLabelPart, InlayHintLabelPartTooltip, InlayHintTooltip, Location, LocationLink,
MarkupContent, Project, ProjectTransaction,
};
@@ -1839,6 +1839,8 @@ impl LspCommand for InlayHints {
origin_buffer
.clip_point_utf16(point_from_lsp(lsp_hint.position), Bias::Left),
),
+ padding_left: lsp_hint.padding_left.unwrap_or(false),
+ padding_right: lsp_hint.padding_right.unwrap_or(false),
label: match lsp_hint.label {
lsp::InlayHintLabel::String(s) => InlayHintLabel::String(s),
lsp::InlayHintLabel::LabelParts(lsp_parts) => InlayHintLabel::LabelParts(
@@ -1878,7 +1880,11 @@ impl LspCommand for InlayHints {
.collect(),
),
},
- kind: lsp_hint.kind.map(|kind| format!("{kind:?}")),
+ kind: lsp_hint.kind.and_then(|kind| match kind {
+ lsp::InlayHintKind::TYPE => Some(InlayHintKind::Type),
+ lsp::InlayHintKind::PARAMETER => Some(InlayHintKind::Parameter),
+ _ => None,
+ }),
tooltip: lsp_hint.tooltip.map(|tooltip| match tooltip {
lsp::InlayHintTooltip::String(s) => InlayHintTooltip::String(s),
lsp::InlayHintTooltip::MarkupContent(markup_content) => {
@@ -1938,6 +1944,8 @@ impl LspCommand for InlayHints {
.into_iter()
.map(|response_hint| proto::InlayHint {
position: Some(language::proto::serialize_anchor(&response_hint.position)),
+ padding_left: response_hint.padding_left,
+ padding_right: response_hint.padding_right,
label: Some(proto::InlayHintLabel {
label: Some(match response_hint.label {
InlayHintLabel::String(s) => proto::inlay_hint_label::Label::Value(s),
@@ -1965,7 +1973,7 @@ impl LspCommand for InlayHints {
}
}),
}),
- kind: response_hint.kind,
+ kind: response_hint.kind.map(|kind| kind.name().to_string()),
tooltip: response_hint.tooltip.map(|response_tooltip| {
let proto_tooltip = match response_tooltip {
InlayHintTooltip::String(s) => {
@@ -2061,7 +2069,12 @@ impl LspCommand for InlayHints {
InlayHintLabel::LabelParts(label_parts)
}
},
- kind: message_hint.kind,
+ padding_left: message_hint.padding_left,
+ padding_right: message_hint.padding_right,
+ kind: message_hint
+ .kind
+ .as_deref()
+ .and_then(InlayHintKind::from_name),
tooltip: message_hint.tooltip.and_then(|tooltip| {
Some(match tooltip.content? {
proto::inlay_hint_tooltip::Content::Value(s) => InlayHintTooltip::String(s),
@@ -332,10 +332,35 @@ pub struct InlayHint {
pub buffer_id: u64,
pub position: Anchor,
pub label: InlayHintLabel,
- pub kind: Option<String>,
+ pub kind: Option<InlayHintKind>,
+ pub padding_left: bool,
+ pub padding_right: bool,
pub tooltip: Option<InlayHintTooltip>,
}
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum InlayHintKind {
+ Type,
+ Parameter,
+}
+
+impl InlayHintKind {
+ pub fn from_name(name: &str) -> Option<Self> {
+ match name {
+ "type" => Some(InlayHintKind::Type),
+ "parameter" => Some(InlayHintKind::Parameter),
+ _ => None,
+ }
+ }
+
+ pub fn name(&self) -> &'static str {
+ match self {
+ InlayHintKind::Type => "type",
+ InlayHintKind::Parameter => "parameter",
+ }
+ }
+}
+
impl InlayHint {
pub fn text(&self) -> String {
match &self.label {