diff options
author | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
commit | b8d4bb76703bcb15578e2b23c5d256532180b894 (patch) | |
tree | bedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/completion/latex/glossary.rs | |
parent | 02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff) |
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/completion/latex/glossary.rs')
-rw-r--r-- | support/texlab/src/completion/latex/glossary.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/support/texlab/src/completion/latex/glossary.rs b/support/texlab/src/completion/latex/glossary.rs new file mode 100644 index 0000000000..ca6600b690 --- /dev/null +++ b/support/texlab/src/completion/latex/glossary.rs @@ -0,0 +1,53 @@ +use super::combinators::{self, Parameter}; +use crate::completion::factory; +use crate::syntax::LatexGlossaryEntryKind::*; +use crate::syntax::*; +use crate::workspace::*; +use futures_boxed::boxed; +use lsp_types::{CompletionItem, CompletionParams, TextEdit}; + +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +pub struct LatexGlossaryCompletionProvider; + +impl FeatureProvider for LatexGlossaryCompletionProvider { + type Params = CompletionParams; + type Output = Vec<CompletionItem>; + + #[boxed] + async fn execute<'a>(&'a self, request: &'a FeatureRequest<Self::Params>) -> Self::Output { + let parameters = LANGUAGE_DATA + .glossary_entry_reference_commands + .iter() + .map(|cmd| Parameter::new(&cmd.name, cmd.index)); + + combinators::argument(request, parameters, |context| { + async move { + let cmd_kind = LANGUAGE_DATA + .glossary_entry_reference_commands + .iter() + .find(|cmd| cmd.name == context.parameter.name) + .unwrap() + .kind; + + let mut items = Vec::new(); + for document in request.related_documents() { + if let SyntaxTree::Latex(tree) = &document.tree { + for entry in &tree.glossary.entries { + match (cmd_kind, entry.kind) { + (Acronym, Acronym) | (General, General) | (General, Acronym) => { + let label = entry.label().text().to_owned(); + let text_edit = TextEdit::new(context.range, label.clone()); + let item = factory::glossary_entry(request, label, text_edit); + items.push(item); + } + (Acronym, General) => {} + } + } + } + } + items + } + }) + .await + } +} |