Skip to content

Commit a0c184a

Browse files
committed
fix: document highlight should only highlight real references not text references
1 parent 1518f71 commit a0c184a

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/document_highlight.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,61 @@ def collect(self, sender: Any, document: TextDocument, position: Position) -> Op
3535
for var, var_refs in all_variable_refs.items():
3636
check_current_task_canceled()
3737

38-
for r in var_refs:
39-
if (var.source == namespace.source and position in var.name_range) or position in r.range:
38+
if var_refs:
39+
for r in var_refs:
40+
if (var.source == namespace.source and position in var.name_range) or position in r.range:
41+
return [
42+
*(
43+
[
44+
DocumentHighlight(
45+
var.name_range,
46+
DocumentHighlightKind.WRITE,
47+
)
48+
]
49+
if var.source == namespace.source
50+
else []
51+
),
52+
*(DocumentHighlight(e.range, DocumentHighlightKind.READ) for e in var_refs),
53+
]
54+
else:
55+
if var.source == namespace.source and position in var.name_range:
4056
return [
4157
*(
4258
[
4359
DocumentHighlight(
4460
var.name_range,
45-
DocumentHighlightKind.TEXT,
61+
DocumentHighlightKind.WRITE,
4662
)
4763
]
4864
if var.source == namespace.source
4965
else []
50-
),
51-
*(DocumentHighlight(e.range, DocumentHighlightKind.TEXT) for e in var_refs),
66+
)
5267
]
5368

5469
all_kw_refs = namespace.get_keyword_references()
5570
if all_kw_refs:
5671
for kw, kw_refs in all_kw_refs.items():
5772
check_current_task_canceled()
5873

59-
for r in kw_refs:
60-
if (kw.source == namespace.source and position in kw.range) or position in r.range:
74+
if kw_refs:
75+
for r in kw_refs:
76+
if (kw.source == namespace.source and position in kw.range) or position in r.range:
77+
return [
78+
*(
79+
[DocumentHighlight(kw.range, DocumentHighlightKind.TEXT)]
80+
if kw.source == namespace.source
81+
else []
82+
),
83+
*(DocumentHighlight(e.range, DocumentHighlightKind.TEXT) for e in kw_refs),
84+
]
85+
else:
86+
if kw.source == namespace.source and position in kw.range:
6187
return [
6288
*(
6389
[DocumentHighlight(kw.range, DocumentHighlightKind.TEXT)]
6490
if kw.source == namespace.source
6591
else []
66-
),
67-
*(DocumentHighlight(e.range, DocumentHighlightKind.TEXT) for e in kw_refs),
92+
)
6893
]
6994

7095
all_namespace_refs = namespace.get_namespace_references()
@@ -98,4 +123,5 @@ def collect(self, sender: Any, document: TextDocument, position: Position) -> Op
98123
),
99124
*(DocumentHighlight(e.range, DocumentHighlightKind.TEXT) for e in ns_refs),
100125
]
101-
return None
126+
127+
return [DocumentHighlight(Range(position, position), DocumentHighlightKind.TEXT)]

0 commit comments

Comments
 (0)