Skip to content

Commit 0dfeb84

Browse files
committed
LSP diagnostics ranges can't be empty (fixes #92)
1 parent 07499f8 commit 0dfeb84

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

hdl_checker/lsp.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def checkerDiagToLspDict(diag: CheckerDiagnostic) -> Diagnostic:
114114
start=Position(
115115
line=diag.line_number or 0, character=diag.column_number or 0
116116
),
117-
end=Position(line=diag.line_number or 0, character=diag.column_number or 0),
117+
end=Position(
118+
line=diag.line_number or 0, character=(diag.column_number or 0) + 1
119+
),
118120
),
119121
message=diag.text,
120122
severity=_translateSeverity(diag.severity),
@@ -323,7 +325,7 @@ def references(self, params: ReferenceParams) -> Optional[List[Location]]:
323325
Location(
324326
uri=from_fs_path(str(element.owner)),
325327
range=Range(
326-
start=Position(line, column), end=Position(line, column)
328+
start=Position(line, column), end=Position(line, column + 1)
327329
),
328330
)
329331
]
@@ -334,7 +336,7 @@ def references(self, params: ReferenceParams) -> Optional[List[Location]]:
334336
Location(
335337
uri=from_fs_path(str(reference.owner)),
336338
range=Range(
337-
start=Position(line, column), end=Position(line, column)
339+
start=Position(line, column), end=Position(line, column + 1)
338340
),
339341
)
340342
]
@@ -465,7 +467,7 @@ def hover(self, params: HoverParams) -> Optional[Hover]:
465467
line=params.position.line, character=params.position.character
466468
),
467469
end=Position(
468-
line=params.position.line, character=params.position.character
470+
line=params.position.line, character=params.position.character + 1
469471
),
470472
),
471473
)
@@ -505,7 +507,7 @@ def definitions(
505507
# Included paths are dependencies but they're referred to by path, so
506508
# we return a definition to point to the beginning of the file
507509
if isinstance(dependency, IncludedPath):
508-
return [Location(target_uri, Range(Position(0, 0), Position(0, 0)))]
510+
return [Location(target_uri, Range(Position(0, 0), Position(0, 1)))]
509511

510512
locations: List[Location] = []
511513

hdl_checker/tests/test_lsp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ def test_ReferencesOfAValidElement(self, get_references) -> Any:
891891
self.assertCountEqual(
892892
references,
893893
{
894-
(uris.from_fs_path("some_path"), 1, 2, 1, 2),
895-
(uris.from_fs_path("some_path"), 3, 4, 3, 4),
894+
(uris.from_fs_path("some_path"), 1, 2, 1, 3),
895+
(uris.from_fs_path("some_path"), 3, 4, 3, 5),
896896
},
897897
)
898898

@@ -920,9 +920,9 @@ def test_ReferencesOfAValidElement(self, get_references) -> Any:
920920
self.assertCountEqual(
921921
references,
922922
{
923-
(uris.from_fs_path(path_to_foo), 7, 7, 7, 7),
924-
(uris.from_fs_path("some_path"), 1, 2, 1, 2),
925-
(uris.from_fs_path("some_path"), 3, 4, 3, 4),
923+
(uris.from_fs_path(path_to_foo), 7, 7, 7, 8),
924+
(uris.from_fs_path("some_path"), 1, 2, 1, 3),
925+
(uris.from_fs_path("some_path"), 3, 4, 3, 5),
926926
},
927927
)
928928

hdl_checker/tests/test_lsp_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_convertingDiagnosticType(self, diag_type, severity):
8080
self.assertEqual(
8181
diag.range,
8282
Range(
83-
start=Position(line=0, character=0), end=Position(line=0, character=0),
83+
start=Position(line=0, character=0), end=Position(line=0, character=1),
8484
),
8585
)
8686

0 commit comments

Comments
 (0)