Skip to content

Commit 8e377a9

Browse files
committed
fix(vscode): duplicate returned diagnostics
1 parent b7f3a2b commit 8e377a9

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

examples/sushi/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"invalidselectstarexpansion",
4848
"noselectstar",
4949
"nomissingaudits",
50+
"nomissingowner",
5051
],
5152
),
5253
)

sqlmesh/lsp/main.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,25 @@ def _diagnostic_to_lsp_diagnostic(
421421
def _diagnostics_to_lsp_diagnostics(
422422
diagnostics: t.List[AnnotatedRuleViolation],
423423
) -> t.List[types.Diagnostic]:
424-
lsp_diagnostics: t.List[types.Diagnostic] = []
424+
"""
425+
Converts a list of AnnotatedRuleViolations to a list of LSP diagnostics. It will remove duplicates based on the message and range.
426+
"""
427+
# Use a set to track unique diagnostics based on their message and range
428+
lsp_diagnostics = {}
425429
for diagnostic in diagnostics:
426430
lsp_diagnostic = SQLMeshLanguageServer._diagnostic_to_lsp_diagnostic(diagnostic)
427431
if lsp_diagnostic is not None:
428-
lsp_diagnostics.append(lsp_diagnostic)
429-
return lsp_diagnostics
432+
# Create a unique key combining message and range
433+
diagnostic_key = (
434+
lsp_diagnostic.message,
435+
lsp_diagnostic.range.start.line,
436+
lsp_diagnostic.range.start.character,
437+
lsp_diagnostic.range.end.line,
438+
lsp_diagnostic.range.end.character,
439+
)
440+
if diagnostic_key not in lsp_diagnostics:
441+
lsp_diagnostics[diagnostic_key] = lsp_diagnostic
442+
return list(lsp_diagnostics.values())
430443

431444
@staticmethod
432445
def _uri_to_path(uri: str) -> Path:

0 commit comments

Comments
 (0)