typst_analyzer_analysis/completion/
handle.rs1use tower_lsp::lsp_types::*;
2use typst_syntax::SyntaxKind;
3
4use super::{code, markup};
5
6pub fn generate_completions(context: Vec<SyntaxKind>) -> Vec<CompletionItem> {
7 let mut completions: Vec<CompletionItem> = vec![];
9 for kind in context {
10 if kind == SyntaxKind::FuncCall {
12 completions.append(&mut markup::items());
13 }
14
15 if kind == SyntaxKind::LineComment {
16 completions.append(&mut typ_comments_cmp());
17 }
18
19 if kind == SyntaxKind::BlockComment {
20 completions.append(&mut typ_comments_cmp());
21 }
22
23 if kind == SyntaxKind::Markup {
24 completions.append(&mut markup::items());
25 completions.append(&mut markup::constructors());
26 completions.append(&mut markup::typ_image_cmp().expect(""));
27 completions.append(&mut code::constructors());
28 }
29
30 if kind == SyntaxKind::Equation {
31 completions.append(&mut markup::items());
32 }
33 }
34 completions
35}
36fn typ_comments_cmp() -> Vec<CompletionItem> {
38 let mut items = Vec::new();
39
40 let comment_ctx = vec![
41 ("TODO: ", "todo", "Task comment"),
42 ("NOTE: ", "note", "Task comment"),
43 ("FIX: ", "fix", "Task comment"),
44 ("BUG: ", "bug", "Task comment"),
45 ("TEST: ", "test", "Task comment"),
46 ];
47 for (insert_text, label, detail) in comment_ctx {
49 items.push(CompletionItem {
50 label: label.to_owned(),
51 kind: Some(CompletionItemKind::TEXT),
52 detail: Some(detail.to_owned()),
53 insert_text: Some(insert_text.to_owned()),
54 ..Default::default()
55 });
56 }
57 items
58}