Skip to main content

typst_analyzer_analysis/completion/
generic.rs

1use tower_lsp::lsp_types::{
2    CompletionItem, CompletionItemKind, CompletionItemLabelDetails, Documentation,
3    InsertTextFormat, MarkupContent, MarkupKind,
4};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct TypCmpItem<'a> {
8    pub label: String,
9    pub label_details: &'a str,
10    pub kind: CompletionItemKind,
11    pub documentation: &'a str,
12    pub insert_text: String,
13}
14
15impl TypCmpItem<'_> {
16    pub fn get_cmp(items: Vec<TypCmpItem>) -> Vec<CompletionItem> {
17        let mut cmpitem: Vec<CompletionItem> = Vec::new();
18        for item in items {
19            let cmp: CompletionItem = CompletionItem {
20                label: item.label.to_owned(),
21                label_details: Some(CompletionItemLabelDetails {
22                    detail: Some(item.label_details.to_owned()),
23                    description: None,
24                }),
25                kind: Some(item.kind),
26                documentation: Some(Documentation::MarkupContent(MarkupContent {
27                    kind: MarkupKind::Markdown,
28                    value: item.documentation.to_owned(),
29                })),
30                insert_text: Some(item.insert_text),
31                insert_text_format: Some(InsertTextFormat::SNIPPET),
32                ..CompletionItem::default()
33            };
34            cmpitem.push(cmp);
35        }
36        cmpitem
37    }
38}