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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
use super::combinators::{self, Parameter};
use crate::completion::factory;
use crate::syntax::LANGUAGE_DATA;
use crate::workspace::*;
use futures_boxed::boxed;
use lsp_types::{CompletionItem, CompletionParams, TextEdit};
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct LatexPgfLibraryCompletionProvider;
impl FeatureProvider for LatexPgfLibraryCompletionProvider {
type Params = CompletionParams;
type Output = Vec<CompletionItem>;
#[boxed]
async fn execute<'a>(&'a self, request: &'a FeatureRequest<Self::Params>) -> Self::Output {
let parameter = Parameter::new("\\usepgflibrary", 0);
combinators::argument(request, std::iter::once(parameter), |context| {
async move {
let mut items = Vec::new();
for name in &LANGUAGE_DATA.pgf_libraries {
let text_edit = TextEdit::new(context.range, name.into());
let item = factory::pgf_library(request, name, text_edit);
items.push(item);
}
items
}
})
.await
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct LatexTikzLibraryCompletionProvider;
impl FeatureProvider for LatexTikzLibraryCompletionProvider {
type Params = CompletionParams;
type Output = Vec<CompletionItem>;
#[boxed]
async fn execute<'a>(&'a self, request: &'a FeatureRequest<Self::Params>) -> Self::Output {
let parameter = Parameter::new("\\usetikzlibrary", 0);
combinators::argument(request, std::iter::once(parameter), |context| {
async move {
let mut items = Vec::new();
for name in &LANGUAGE_DATA.tikz_libraries {
let text_edit = TextEdit::new(context.range, name.into());
let item = factory::tikz_library(request, name, text_edit);
items.push(item);
}
items
}
})
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
use lsp_types::Position;
#[test]
fn test_pgf_library() {
let items = test_feature(
LatexPgfLibraryCompletionProvider,
FeatureSpec {
files: vec![FeatureSpec::file("foo.tex", "\\usepgflibrary{}")],
main_file: "foo.tex",
position: Position::new(0, 15),
..FeatureSpec::default()
},
);
assert!(!items.is_empty());
}
#[test]
fn test_tikz_library() {
let items = test_feature(
LatexTikzLibraryCompletionProvider,
FeatureSpec {
files: vec![FeatureSpec::file("foo.tex", "\\usetikzlibrary{}")],
main_file: "foo.tex",
position: Position::new(0, 16),
..FeatureSpec::default()
},
);
assert!(!items.is_empty());
}
}
|