Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't offer a code action for a diagnostic with no diagnostic "code" #100

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 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,6 +608,8 @@ def pylsp_code_actions(
for diagnostic in context.get("diagnostics", []):
if diagnostic["source"] != "mypy":
continue
if "code" not in diagnostic:
continue
code = diagnostic["code"]
lineNumberEnd = diagnostic["range"]["end"]["line"]
line = document.lines[lineNumberEnd]
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
Loading