@dataclass
class PyreflyServer(LSPServerInfo):
"""Pyrefly (Meta) type checker with JSON diagnostic parsing."""
def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
"""Parse pyrefly JSON output."""
import anyenv
diagnostics: list[Diagnostic] = []
try:
# Find JSON object (may have INFO line after it)
json_start = output.find("{")
json_end = output.rfind("}") + 1
if json_start == -1 or json_end == 0:
return diagnostics
data = anyenv.load_json(output[json_start:json_end], return_type=dict)
for error in data.get("errors", []):
diagnostics.append( # noqa: PERF401
Diagnostic(
file=error.get("path", ""),
line=error.get("line", 1),
column=error.get("column", 1),
end_line=error.get("stop_line", error.get("line", 1)),
end_column=error.get("stop_column", error.get("column", 1)),
severity=severity_from_string(error.get("severity", "error")),
message=error.get("description", ""),
code=error.get("name"),
source=self.id,
)
)
except anyenv.JsonLoadError:
pass
return diagnostics