use std::borrow::Cow;
#[derive(Clone, Debug)]
pub struct CompletionItem {
pub value: Cow<'static, str>,
pub description: Option<Cow<'static, str>>,
}
impl CompletionItem {
#[must_use]
pub fn new(value: impl Into<Cow<'static, str>>) -> Self {
Self {
value: value.into(),
description: None,
}
}
#[must_use]
pub fn with_description(
value: impl Into<Cow<'static, str>>,
desc: impl Into<Cow<'static, str>>,
) -> Self {
Self {
value: value.into(),
description: Some(desc.into()),
}
}
#[must_use]
pub fn description_or_empty(&self) -> &str {
self.description.as_deref().unwrap_or("")
}
}
impl From<&'static str> for CompletionItem {
fn from(value: &'static str) -> Self {
Self::new(value)
}
}
impl From<String> for CompletionItem {
fn from(value: String) -> Self {
Self::new(value)
}
}
impl From<(&'static str, &'static str)> for CompletionItem {
fn from((value, desc): (&'static str, &'static str)) -> Self {
Self::with_description(value, desc)
}
}