Skip to content

TyServer

Base classes

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

⋔ Inheritance diagram

graph TD
  1658232253["python_lsps.TyServer"]
  514706066["_base.LSPServerInfo"]
  2751680898["builtins.object"]
  514706066 --> 1658232253
  2751680898 --> 514706066

🛈 DocStrings

Bases: LSPServerInfo

Ty (Astral) type checker with GitLab JSON diagnostic parsing.

Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
@dataclass
class TyServer(LSPServerInfo):
    """Ty (Astral) type checker with GitLab JSON diagnostic parsing."""

    def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
        """Parse ty GitLab JSON output."""
        import anyenv

        diagnostics: list[Diagnostic] = []

        try:
            data = anyenv.load_json(output, return_type=list)
            for item in data:
                location = item.get("location", {})
                positions = location.get("positions", {})
                begin = positions.get("begin", {})
                end = positions.get("end", {})

                # Map GitLab severity to our severity
                gitlab_severity = item.get("severity", "major")
                if gitlab_severity in ("blocker", "critical", "major"):
                    severity = "error"
                elif gitlab_severity == "minor":
                    severity = "warning"
                else:
                    severity = "information"

                diagnostics.append(
                    Diagnostic(
                        file=location.get("path", ""),
                        line=begin.get("line", 1),
                        column=begin.get("column", 1),
                        end_line=end.get("line", begin.get("line", 1)),
                        end_column=end.get("column", begin.get("column", 1)),
                        severity=severity_from_string(severity),
                        message=item.get("description", ""),
                        code=item.get("check_name"),
                        source=self.id,
                    )
                )
        except anyenv.JsonLoadError:
            pass

        return diagnostics

:fa-brands-github: Show source on GitHub