summaryrefslogtreecommitdiff
path: root/support/texlab/crates/highlights/src/label.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/crates/highlights/src/label.rs')
-rw-r--r--support/texlab/crates/highlights/src/label.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/support/texlab/crates/highlights/src/label.rs b/support/texlab/crates/highlights/src/label.rs
new file mode 100644
index 0000000000..ee606c175b
--- /dev/null
+++ b/support/texlab/crates/highlights/src/label.rs
@@ -0,0 +1,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(())
+}