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

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

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

pub fn complete_component_commands<'a>(
    context: &'a CursorContext<CompletionParams>,
    items: &mut Vec<InternalCompletionItem<'a>>,
) -> Option<()> {
    let range = context.cursor.command_range(context.offset)?;

    for component in COMPONENT_DATABASE.linked_components(&context.request.workspace) {
        for command in &component.commands {
            items.push(InternalCompletionItem::new(
                range,
                InternalCompletionItemData::ComponentCommand {
                    name: &command.name,
                    image: command.image.as_deref(),
                    glyph: command.glyph.as_deref(),
                    file_names: &component.file_names,
                },
            ));
        }
    }

    Some(())
}