summaryrefslogtreecommitdiff
path: root/support/texlab/src/completion/latex/tikz.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
committerNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
commitb8d4bb76703bcb15578e2b23c5d256532180b894 (patch)
treebedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/completion/latex/tikz.rs
parent02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff)
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/completion/latex/tikz.rs')
-rw-r--r--support/texlab/src/completion/latex/tikz.rs90
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());
+ }
+}