Bases: LSPServerInfo
Mypy with JSON diagnostic parsing.
Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
| @dataclass
class MypyServer(LSPServerInfo):
"""Mypy with JSON diagnostic parsing."""
def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
"""Parse mypy JSON output (one JSON object per line)."""
import anyenv
diagnostics: list[Diagnostic] = []
for line in output.strip().splitlines():
line = line.strip()
if not line or not line.startswith("{"):
continue
try:
data = anyenv.load_json(line, return_type=dict)
diagnostics.append(
Diagnostic(
file=data.get("file", ""),
line=data.get("line", 1),
column=data.get("column", 1),
severity=severity_from_string(data.get("severity", "error")),
message=data.get("message", ""),
code=data.get("code"),
source=self.id,
)
)
except anyenv.JsonLoadError:
continue
return diagnostics
|