typst_analyzer_analysis/completion/
generic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use tower_lsp::lsp_types::{CompletionItem, CompletionItemKind, InsertTextFormat};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypCmpItem<'a> {
    pub label: String,
    pub label_details: &'a str,
    pub kind: CompletionItemKind,
    pub documentation: &'a str,
    pub insert_text: String,
}

impl TypCmpItem<'_> {
    pub fn get_cmp(items: Vec<TypCmpItem>) -> Vec<CompletionItem> {
        let mut cmpitem: Vec<CompletionItem> = Vec::new();
        for item in items {
            let cmp: CompletionItem = CompletionItem {
                label: item.label.to_owned(),
                label_details: Some(tower_lsp::lsp_types::CompletionItemLabelDetails {
                    detail: Some(item.label_details.to_owned()),
                    description: None,
                }),
                kind: Some(item.kind),
                documentation: Some(tower_lsp::lsp_types::Documentation::String(
                    item.documentation.to_owned(),
                )),
                insert_text: Some(item.insert_text),
                insert_text_format: Some(InsertTextFormat::SNIPPET),
                ..CompletionItem::default()
            };
            cmpitem.push(cmp);
        }
        cmpitem
    }
}