blob: dc0a60ab654eb112929adf6280c1924b31939419 (
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
32
33
34
35
36
37
|
use base_db::{semantics::tex::LabelKind, Document};
use lsp_types::DocumentHighlight;
use rowan::TextSize;
use crate::util::line_index_ext::LineIndexExt;
pub fn find_highlights(
document: &Document,
offset: TextSize,
) -> Option<Vec<lsp_types::DocumentHighlight>> {
let data = document.data.as_tex()?;
let cursor = data
.semantics
.labels
.iter()
.find(|label| label.name.range.contains(offset))?;
let mut highlights = Vec::new();
let line_index = &document.line_index;
for label in data
.semantics
.labels
.iter()
.filter(|label| label.name.text == cursor.name.text)
{
let range = line_index.line_col_lsp_range(label.name.range);
let kind = Some(match label.kind {
LabelKind::Definition => lsp_types::DocumentHighlightKind::WRITE,
LabelKind::Reference => lsp_types::DocumentHighlightKind::READ,
LabelKind::ReferenceRange => lsp_types::DocumentHighlightKind::READ,
});
highlights.push(DocumentHighlight { range, kind });
}
Some(highlights)
}
|