Skip to content

PyreflyServer

Base classes

Name Children Inherits
LSPServerInfo
anyenv.lsp_servers._base
Static configuration for an LSP server.

⋔ Inheritance diagram

graph TD
  788229482["python_lsps.PyreflyServer"]
  514706066["_base.LSPServerInfo"]
  2751680898["builtins.object"]
  514706066 --> 788229482
  2751680898 --> 514706066

🛈 DocStrings

Bases: LSPServerInfo

Pyrefly (Meta) type checker with JSON diagnostic parsing.

Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
@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

:fa-brands-github: Show source on GitHub