summaryrefslogtreecommitdiff
path: root/support/texlab/crates/highlights/src/label.rs
blob: ee606c175b319eddc1790ba521974950f62fe847 (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 base_db::semantics::tex::LabelKind;

use crate::{Highlight, HighlightKind, HighlightParams};

pub fn find_highlights(params: &HighlightParams, results: &mut Vec<Highlight>) -> Option<()> {
    let data = params.feature.document.data.as_tex()?;
    let labels = &data.semantics.labels;
    let cursor = labels
        .iter()
        .find(|label| label.name.range.contains(params.offset))?;

    for label in labels
        .iter()
        .filter(|label| label.name.text == cursor.name.text)
    {
        let range = label.name.range;
        let kind = match label.kind {
            LabelKind::Definition => HighlightKind::Write,
            LabelKind::Reference | LabelKind::ReferenceRange => HighlightKind::Read,
        };

        results.push(Highlight { range, kind });
    }

    Some(())
}