Skip to content

Commit

Permalink
only include valid codes in diag
Browse files Browse the repository at this point in the history
  • Loading branch information
Richardk2n committed Jan 25, 2025
1 parent 2274633 commit b097f81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,21 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
log.warning(f"invalid error severity '{severity}'")
errno = 1 if severity == "error" else 3

return {
diag = {
"source": "mypy",
"range": {
"start": {"line": lineno, "character": offset},
"end": {"line": end_lineno, "character": end_offset},
},
"message": result["message"],
"severity": errno,
"code": result["code"],
}

if result["code"]:
diag["code"] = result["code"]

return diag


def apply_overrides(args: List[str], overrides: List[Any]) -> List[str]:
"""Replace or combine default command-line options with overrides."""
Expand Down Expand Up @@ -604,7 +608,7 @@ def pylsp_code_actions(
for diagnostic in context.get("diagnostics", []):
if diagnostic["source"] != "mypy":
continue
if diagnostic.get("code") is None:
if "code" not in diagnostic:
continue
code = diagnostic["code"]
lineNumberEnd = diagnostic["range"]["end"]["line"]
Expand Down
2 changes: 1 addition & 1 deletion test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_parse_note_line(workspace):
assert diag["range"]["start"] == {"line": 123, "character": 0}
assert diag["range"]["end"] == {"line": 128, "character": 77}
assert diag["severity"] == 3
assert diag["code"] is None
assert "code" not in diag


def test_multiple_workspaces(tmpdir, last_diagnostics_monkeypatch):
Expand Down

0 comments on commit b097f81

Please sign in to comment.