Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Deserialize more LSP inlay hint information
Kirill Bulatov8acc5cf8f478
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rsindex d8924f96925..11f43bea65a 100644--- a/crates/editor/src/display_map.rs+++ b/crates/editor/src/display_map.rs@@ -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,},)})diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rsindex 5df37223c02..bce9bf0e10f 100644--- a/crates/project/src/lsp_command.rs+++ b/crates/project/src/lsp_command.rs@@ -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),diff --git a/crates/project/src/project.rs b/crates/project/src/project.rsindex bda93a0206d..2f22201ea42 100644--- a/crates/project/src/project.rs+++ b/crates/project/src/project.rs@@ -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 {diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.protoindex 6de98c45958..838a0123c07 100644--- a/crates/rpc/proto/zed.proto+++ b/crates/rpc/proto/zed.proto@@ -725,7 +725,9 @@ message InlayHint {Anchor position = 1;InlayHintLabel label = 2;optional string kind = 3;- InlayHintTooltip tooltip = 4;+ bool padding_left = 4;+ bool padding_right = 5;+ InlayHintTooltip tooltip = 6;}message InlayHintLabel {