summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/completion/user_environment.rs
blob: 91dd5a9ea282870254622af5e27daf5c35b08647 (plain)
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
use lsp_types::CompletionParams;

use crate::features::cursor::CursorContext;

use super::types::{InternalCompletionItem, InternalCompletionItemData};

pub fn complete_user_environments<'a>(
    context: &'a CursorContext<CompletionParams>,
    items: &mut Vec<InternalCompletionItem<'a>>,
) -> Option<()> {
    let (name, range) = context.find_environment_name()?;

    for document in context.request.workspace.documents_by_uri.values() {
        if let Some(data) = document.data.as_latex() {
            for name in data
                .extras
                .environment_names
                .iter()
                .filter(|n| n.as_str() != name)
                .cloned()
            {
                items.push(InternalCompletionItem::new(
                    range,
                    InternalCompletionItemData::UserEnvironment { name },
                ));
            }
        }
    }

    Some(())
}