diff options
Diffstat (limited to 'support/texlab/src/completion/latex/tikz.rs')
-rw-r--r-- | support/texlab/src/completion/latex/tikz.rs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/support/texlab/src/completion/latex/tikz.rs b/support/texlab/src/completion/latex/tikz.rs new file mode 100644 index 0000000000..2d6740e1a8 --- /dev/null +++ b/support/texlab/src/completion/latex/tikz.rs @@ -0,0 +1,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()); + } +} |