#[derive(Eq, PartialEq)] pub enum Position { After, Before, } pub struct InlayHint { pub pos: Position, pub label: String, } pub struct Tag { pub start: u32, pub end: u32, pub name: String, pub attributes: Option, pub inlay_hint: Option, } impl Tag { fn get_inlay_hint(&self, pos: Position) -> Option { if let Some(h) = self.inlay_hint.as_ref() { if h.pos == pos && !h.label.is_empty() { return Some(format!("{}", h.label)); } } None } pub fn open(&self) -> String { if self.attributes.is_none() { if let Some(inner_html) = self.get_inlay_hint(Position::Before) { return format!("{inner_html}<{}>", &self.name); } return format!("<{}>", &self.name); } if let Some(inner_html) = self.get_inlay_hint(Position::Before) { format!( "{inner_html}<{} {}>", self.name, self.attributes.as_ref().unwrap(), ) } else { format!("<{} {}>", self.name, self.attributes.as_ref().unwrap()) } } pub fn close(&self) -> String { if let Some(inner_html) = self.get_inlay_hint(Position::After) { format!("{inner_html}", &self.name) } else { format!("", &self.name) } } }