Skip to content

Commit 6ab6963

Browse files
authored
fix(vscode): duplicate returned diagnostics (#4553)
1 parent b7f3a2b commit 6ab6963

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,24 @@ 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+
lsp_diagnostics = {}
425428
for diagnostic in diagnostics:
426429
lsp_diagnostic = SQLMeshLanguageServer._diagnostic_to_lsp_diagnostic(diagnostic)
427430
if lsp_diagnostic is not None:
428-
lsp_diagnostics.append(lsp_diagnostic)
429-
return lsp_diagnostics
431+
# Create a unique key combining message and range
432+
diagnostic_key = (
433+
lsp_diagnostic.message,
434+
lsp_diagnostic.range.start.line,
435+
lsp_diagnostic.range.start.character,
436+
lsp_diagnostic.range.end.line,
437+
lsp_diagnostic.range.end.character,
438+
)
439+
if diagnostic_key not in lsp_diagnostics:
440+
lsp_diagnostics[diagnostic_key] = lsp_diagnostic
441+
return list(lsp_diagnostics.values())
430442

431443
@staticmethod
432444
def _uri_to_path(uri: str) -> Path:

0 commit comments

Comments
 (0)