use Default::default; use lsp_types::{InlayHint, InlayHintLabel, Location}; use serde_derive::{Deserialize, Serialize}; use crate::text::{RopeExt, TextArea}; pub type Inlay = Marking)]>>; #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct Marking { /// in characters pub position: u32, pub data: D, } impl Marking { pub fn idx(x: u32) -> Self { Self { position: x, ..default() } } } impl Ord for Marking { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.position.cmp(&other.position) } } impl PartialOrd for Marking { fn partial_cmp(&self, other: &Self) -> Option { self.position.partial_cmp(&other.position) } } impl Eq for Marking {} impl PartialEq for Marking { fn eq(&self, other: &Self) -> bool { self.position == other.position } } impl TextArea { #[implicit_fn::implicit_fn] pub fn set_inlay(&mut self, inlay: &[InlayHint]) { self.inlays = inlay .iter() .map(|i| { let mut label = match &i.label { InlayHintLabel::String(x) => x.chars().map(|x| (x, None)).collect::>(), InlayHintLabel::LabelParts(v) => v .iter() .flat_map(|x| { x.value .chars() .map(|y| (y, x.location.clone())) }) .collect(), }; if i.padding_left == Some(true) { label.insert(0, (' ', None)); } if i.padding_right == Some(true) { label.push((' ', None)); } let position = self.l_position(i.position).unwrap() as _; Marking { position, data: label.into() } }) .collect(); } }