@dataclass
class BiomeServer(LSPServerInfo):
"""Biome linter/formatter with JSON diagnostic parsing."""
def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
"""Parse biome JSON output."""
import anyenv
diagnostics: list[Diagnostic] = []
try:
# Find JSON in output (biome may print extra text)
json_start = output.find("{")
if json_start == -1:
return diagnostics
data = anyenv.load_json(output[json_start:], return_type=dict)
for diag in data.get("diagnostics", []):
location = diag.get("location", {})
span = location.get("span", [0, 0])
# Biome uses byte offsets, not line/column directly
# For now, use offset as approximation (would need source to convert)
path_info = location.get("path", {})
file_path = path_info.get("file", "") if isinstance(path_info, dict) else ""
diagnostics.append(
Diagnostic(
file=file_path,
line=1, # Would need source text to calculate
column=span[0] if span else 1,
severity=severity_from_string(diag.get("severity", "error")),
message=diag.get("description", ""),
code=diag.get("category"),
source=self.id,
)
)
except anyenv.JsonLoadError:
pass
return diagnostics