summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/completion/component_environment.rs
blob: a9478694bbbe3dea4352deb90affe927b36881b7 (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
use lsp_types::CompletionParams;

use crate::{component_db::COMPONENT_DATABASE, features::cursor::CursorContext};

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

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

    for component in COMPONENT_DATABASE.linked_components(&context.request.workspace) {
        for name in &component.environments {
            items.push(InternalCompletionItem::new(
                range,
                InternalCompletionItemData::ComponentEnvironment {
                    name,
                    file_names: &component.file_names,
                },
            ));
        }
    }

    Some(())
}