summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/completion/user_command.rs
blob: 14c22227013a4bba13fff349322ab7b4d3661152 (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
use crate::util::cursor::CursorContext;

use super::builder::CompletionBuilder;

pub fn complete<'db>(
    context: &'db CursorContext,
    builder: &mut CompletionBuilder<'db>,
) -> Option<()> {
    let range = context.cursor.command_range(context.offset)?;
    let token = context.cursor.as_tex()?;

    let db = context.db;
    for document in context.related() {
        if let Some(data) = document.parse(db).as_tex() {
            let text = document.text(db);
            for name in data
                .analyze(db)
                .command_name_ranges(db)
                .iter()
                .copied()
                .filter(|range| *range != token.text_range())
                .map(|range| &text[std::ops::Range::<usize>::from(range)])
            {
                builder.user_command(range, name);
            }
        }
    }

    Some(())
}