Skip to content

LSPServerInfo

Sub classes

Name Children Inherits
TypeScriptServer
anyenv.lsp_servers._servers.js_ts_lsps
TypeScript language server with tsserver path detection.
    AstroServer
    anyenv.lsp_servers._servers.js_ts_lsps
    Astro language server with TypeScript SDK detection.
      OxlintServer
      anyenv.lsp_servers._servers.js_ts_lsps
      Oxlint (oxc) linter with JSON diagnostic parsing.
        BiomeServer
        anyenv.lsp_servers._servers.js_ts_lsps
        Biome linter/formatter with JSON diagnostic parsing.
          PyrightServer
          anyenv.lsp_servers._servers.python_lsps
          Pyright with virtualenv detection and JSON diagnostic parsing.
            ZubanServer
            anyenv.lsp_servers._servers.python_lsps
            Zuban type checker with mypy-compatible text output parsing.
              TyServer
              anyenv.lsp_servers._servers.python_lsps
              Ty (Astral) type checker with GitLab JSON diagnostic parsing.
                PyreflyServer
                anyenv.lsp_servers._servers.python_lsps
                Pyrefly (Meta) type checker with JSON diagnostic parsing.
                  MypyServer
                  anyenv.lsp_servers._servers.python_lsps
                  Mypy with JSON diagnostic parsing.
                    RustAnalyzerServer
                    anyenv.lsp_servers._servers.rust_lsps
                    Rust analyzer with workspace detection.
                      GoplsServer
                      anyenv.lsp_servers._servers.go_lsps
                      Go language server with go.work priority.

                        🛈 DocStrings

                        Static configuration for an LSP server.

                        Subclass and override resolve_root and/or resolve_initialization for servers that need custom behavior beyond the declarative configuration.

                        Parameters:

                        Name Type Description Default
                        id str

                        Unique identifier for this server

                        required
                        extensions list[str]

                        File extensions this server handles (e.g., [".py", ".pyi"])

                        required
                        root_detection RootDetection

                        Configuration for finding project root

                        required
                        command str

                        Primary command to run the server

                        required
                        args list[str]

                        Additional command-line arguments

                        list()
                        npm_install NpmInstall | None

                        npm installation config

                        None
                        go_install GoInstall | None

                        Go installation config

                        None
                        cargo_install CargoInstall | None

                        Cargo installation config

                        None
                        dotnet_install DotnetInstall | None

                        .NET tool installation config

                        None
                        gem_install GemInstall | None

                        Ruby gem installation config

                        None
                        github_release GitHubRelease | None

                        GitHub release download config

                        None
                        initialization dict[str, Any]

                        LSP initialization options sent to server

                        dict()
                        env dict[str, str]

                        Environment variables for the server process

                        dict()
                        global_server bool

                        If True, use single global instance instead of per-project

                        False
                        cli_diagnostics CLIDiagnosticConfig | None

                        CLI fallback for diagnostics

                        None
                        Source code in src/anyenv/lsp_servers/_base.py
                        @dataclass
                        class LSPServerInfo:
                            """Static configuration for an LSP server.
                        
                            Subclass and override `resolve_root` and/or `resolve_initialization` for
                            servers that need custom behavior beyond the declarative configuration.
                        
                            Args:
                                id: Unique identifier for this server
                                extensions: File extensions this server handles (e.g., [".py", ".pyi"])
                                root_detection: Configuration for finding project root
                                command: Primary command to run the server
                                args: Additional command-line arguments
                                npm_install: npm installation config
                                go_install: Go installation config
                                cargo_install: Cargo installation config
                                dotnet_install: .NET tool installation config
                                gem_install: Ruby gem installation config
                                github_release: GitHub release download config
                                initialization: LSP initialization options sent to server
                                env: Environment variables for the server process
                                global_server: If True, use single global instance instead of per-project
                                cli_diagnostics: CLI fallback for diagnostics
                            """
                        
                            id: str
                            extensions: list[str]
                            root_detection: RootDetection
                            command: str
                            args: list[str] = field(default_factory=list)
                        
                            # Installation options (None = must be pre-installed)
                            npm_install: NpmInstall | None = None
                            go_install: GoInstall | None = None
                            cargo_install: CargoInstall | None = None
                            dotnet_install: DotnetInstall | None = None
                            gem_install: GemInstall | None = None
                            github_release: GitHubRelease | None = None
                            # LSP initialization settings (static)
                            initialization: dict[str, Any] = field(default_factory=dict)
                            # Environment variables
                            env: dict[str, str] = field(default_factory=dict)
                            # If True, single global instance (not per-project)
                            global_server: bool = False
                            # CLI diagnostic fallback
                            cli_diagnostics: CLIDiagnosticConfig | None = None
                        
                            def can_handle(self, extension: str) -> bool:
                                """Check if this server handles the given file extension."""
                                ext = extension if extension.startswith(".") else f".{extension}"
                                return ext.lower() in [e.lower() for e in self.extensions]
                        
                            @property
                            def has_auto_install(self) -> bool:
                                """Check if this server can be auto-installed."""
                                return any([
                                    self.npm_install,
                                    self.go_install,
                                    self.cargo_install,
                                    self.dotnet_install,
                                    self.gem_install,
                                    self.github_release,
                                ])
                        
                            @property
                            def has_cli_diagnostics(self) -> bool:
                                """Check if this server supports CLI diagnostics."""
                                return self.cli_diagnostics is not None
                        
                            async def resolve_root(
                                self,
                                file_path: str,
                                project_root: str,
                                fs: AsyncFileSystem,
                            ) -> str | None:
                                """Resolve the LSP root directory for a given file.
                        
                                Default implementation searches upward from file_path for include_patterns,
                                respecting exclude_patterns. Override for custom behavior (e.g., workspace detection).
                        
                                Args:
                                    file_path: The file being edited
                                    project_root: The overall project/workspace root (stop boundary)
                                    fs: Filesystem to use for file operations
                        
                                Returns:
                                    The resolved root directory, or None if this LSP shouldn't be used
                                """
                                if self.root_detection.exclude_patterns:
                                    excluded = await self._find_nearest(
                                        posixpath.dirname(file_path),
                                        self.root_detection.exclude_patterns,
                                        project_root,
                                        fs,
                                    )
                                    if excluded:
                                        return None
                        
                                found = await self._find_nearest(
                                    posixpath.dirname(file_path),
                                    self.root_detection.include_patterns,
                                    project_root,
                                    fs,
                                )
                                return posixpath.dirname(found) if found else project_root
                        
                            async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                """Resolve dynamic LSP initialization options.
                        
                                Default implementation returns the static `initialization` dict.
                                Override for dynamic behavior (e.g., detecting virtualenv, tsdk path).
                        
                                Args:
                                    root: The resolved LSP root directory
                                    fs: Filesystem to use for file operations
                                """
                                return dict(self.initialization)
                        
                            async def resolve_env(self, root: str, fs: AsyncFileSystem) -> dict[str, str]:
                                """Resolve environment variables for the server process.
                        
                                Default implementation returns the static `env` dict.
                                Override for dynamic behavior.
                        
                                Args:
                                    root: The resolved LSP root directory
                                    fs: Filesystem to use for file operations
                                """
                                return dict(self.env)
                        
                            async def _find_nearest(
                                self,
                                start: str,
                                patterns: list[str],
                                stop: str,
                                fs: AsyncFileSystem,
                            ) -> str | None:
                                """Find the nearest file matching any pattern, searching upward.
                        
                                Args:
                                    start: Directory to start searching from
                                    patterns: Glob patterns to match
                                    stop: Directory to stop searching at (inclusive)
                                    fs: Filesystem to use for file operations
                                """
                                import posixpath
                        
                                current = start.rstrip("/")
                                stop = stop.rstrip("/")
                        
                                while True:
                                    for pattern in patterns:
                                        full_pattern = posixpath.join(current, pattern)
                                        try:
                                            if matches := await fs._glob(full_pattern):  # noqa: SLF001
                                                return matches[0]  # type: ignore[no-any-return] # pyright: ignore[reportArgumentType]
                                        except Exception:  # noqa: BLE001
                                            # Filesystem might not support glob, try exists
                                            try:
                                                path = posixpath.join(current, pattern)
                                                if await fs._exists(path):  # noqa: SLF001
                                                    return path
                                            except Exception:  # noqa: BLE001
                                                pass
                        
                                    parent = posixpath.dirname(current)
                                    if current in (stop, parent) or current == fs.root_marker:
                                        break
                                    current = parent
                        
                                return None
                        
                            def get_full_command(self) -> list[str]:
                                """Get the full command with arguments."""
                                return [self.command, *self.args]
                        
                            def get_env(self, base_env: dict[str, str] | os._Environ[str] | None = None) -> dict[str, str]:
                                """Get environment variables, merged with optional base environment."""
                                if base_env is None:
                                    return dict(self.env)
                                result = dict(base_env)
                                result.update(self.env)
                                return result
                        
                            def build_diagnostic_command(self, files: list[str]) -> str:
                                """Build the CLI command for running diagnostics.
                        
                                Args:
                                    files: List of file paths to check
                        
                                Returns:
                                    The command string to execute
                                """
                                if not self.cli_diagnostics:
                                    msg = f"No CLI diagnostics configured for {self.id}"
                                    raise ValueError(msg)
                        
                                argv = [self.cli_diagnostics.command]
                                for arg in self.cli_diagnostics.args:
                                    if arg == "{files}":
                                        argv.extend(files)
                                    else:
                                        argv.append(arg.replace("{files}", " ".join(files)))
                                return shlex.join(argv)
                        
                            def parse_diagnostics(self, stdout: str, stderr: str) -> list[Diagnostic]:
                                """Parse CLI output into diagnostics.
                        
                                Override for custom output formats. Default handles common JSON formats.
                        
                                Args:
                                    stdout: Standard output from the command
                                    stderr: Standard error from the command
                                """
                                diagnostics: list[Diagnostic] = []
                        
                                if not self.cli_diagnostics:
                                    return diagnostics
                        
                                if self.cli_diagnostics.output_format == "json":
                                    diagnostics = self._parse_json_diagnostics(stdout)
                        
                                return diagnostics
                        
                            def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
                                """Parse JSON diagnostic output. Override for tool-specific formats."""
                                return []
                        

                        has_auto_install property

                        has_auto_install: bool
                        

                        Check if this server can be auto-installed.

                        has_cli_diagnostics property

                        has_cli_diagnostics: bool
                        

                        Check if this server supports CLI diagnostics.

                        build_diagnostic_command

                        build_diagnostic_command(files: list[str]) -> str
                        

                        Build the CLI command for running diagnostics.

                        Parameters:

                        Name Type Description Default
                        files list[str]

                        List of file paths to check

                        required

                        Returns:

                        Type Description
                        str

                        The command string to execute

                        Source code in src/anyenv/lsp_servers/_base.py
                        def build_diagnostic_command(self, files: list[str]) -> str:
                            """Build the CLI command for running diagnostics.
                        
                            Args:
                                files: List of file paths to check
                        
                            Returns:
                                The command string to execute
                            """
                            if not self.cli_diagnostics:
                                msg = f"No CLI diagnostics configured for {self.id}"
                                raise ValueError(msg)
                        
                            argv = [self.cli_diagnostics.command]
                            for arg in self.cli_diagnostics.args:
                                if arg == "{files}":
                                    argv.extend(files)
                                else:
                                    argv.append(arg.replace("{files}", " ".join(files)))
                            return shlex.join(argv)
                        

                        can_handle

                        can_handle(extension: str) -> bool
                        

                        Check if this server handles the given file extension.

                        Source code in src/anyenv/lsp_servers/_base.py
                        def can_handle(self, extension: str) -> bool:
                            """Check if this server handles the given file extension."""
                            ext = extension if extension.startswith(".") else f".{extension}"
                            return ext.lower() in [e.lower() for e in self.extensions]
                        

                        get_env

                        get_env(base_env: dict[str, str] | _Environ[str] | None = None) -> dict[str, str]
                        

                        Get environment variables, merged with optional base environment.

                        Source code in src/anyenv/lsp_servers/_base.py
                        def get_env(self, base_env: dict[str, str] | os._Environ[str] | None = None) -> dict[str, str]:
                            """Get environment variables, merged with optional base environment."""
                            if base_env is None:
                                return dict(self.env)
                            result = dict(base_env)
                            result.update(self.env)
                            return result
                        

                        get_full_command

                        get_full_command() -> list[str]
                        

                        Get the full command with arguments.

                        Source code in src/anyenv/lsp_servers/_base.py
                        def get_full_command(self) -> list[str]:
                            """Get the full command with arguments."""
                            return [self.command, *self.args]
                        

                        parse_diagnostics

                        parse_diagnostics(stdout: str, stderr: str) -> list[Diagnostic]
                        

                        Parse CLI output into diagnostics.

                        Override for custom output formats. Default handles common JSON formats.

                        Parameters:

                        Name Type Description Default
                        stdout str

                        Standard output from the command

                        required
                        stderr str

                        Standard error from the command

                        required
                        Source code in src/anyenv/lsp_servers/_base.py
                        def parse_diagnostics(self, stdout: str, stderr: str) -> list[Diagnostic]:
                            """Parse CLI output into diagnostics.
                        
                            Override for custom output formats. Default handles common JSON formats.
                        
                            Args:
                                stdout: Standard output from the command
                                stderr: Standard error from the command
                            """
                            diagnostics: list[Diagnostic] = []
                        
                            if not self.cli_diagnostics:
                                return diagnostics
                        
                            if self.cli_diagnostics.output_format == "json":
                                diagnostics = self._parse_json_diagnostics(stdout)
                        
                            return diagnostics
                        

                        resolve_env async

                        resolve_env(root: str, fs: AsyncFileSystem) -> dict[str, str]
                        

                        Resolve environment variables for the server process.

                        Default implementation returns the static env dict. Override for dynamic behavior.

                        Parameters:

                        Name Type Description Default
                        root str

                        The resolved LSP root directory

                        required
                        fs AsyncFileSystem

                        Filesystem to use for file operations

                        required
                        Source code in src/anyenv/lsp_servers/_base.py
                        async def resolve_env(self, root: str, fs: AsyncFileSystem) -> dict[str, str]:
                            """Resolve environment variables for the server process.
                        
                            Default implementation returns the static `env` dict.
                            Override for dynamic behavior.
                        
                            Args:
                                root: The resolved LSP root directory
                                fs: Filesystem to use for file operations
                            """
                            return dict(self.env)
                        

                        resolve_initialization async

                        resolve_initialization(root: str, fs: AsyncFileSystem) -> dict[str, Any]
                        

                        Resolve dynamic LSP initialization options.

                        Default implementation returns the static initialization dict. Override for dynamic behavior (e.g., detecting virtualenv, tsdk path).

                        Parameters:

                        Name Type Description Default
                        root str

                        The resolved LSP root directory

                        required
                        fs AsyncFileSystem

                        Filesystem to use for file operations

                        required
                        Source code in src/anyenv/lsp_servers/_base.py
                        async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                            """Resolve dynamic LSP initialization options.
                        
                            Default implementation returns the static `initialization` dict.
                            Override for dynamic behavior (e.g., detecting virtualenv, tsdk path).
                        
                            Args:
                                root: The resolved LSP root directory
                                fs: Filesystem to use for file operations
                            """
                            return dict(self.initialization)
                        

                        resolve_root async

                        resolve_root(file_path: str, project_root: str, fs: AsyncFileSystem) -> str | None
                        

                        Resolve the LSP root directory for a given file.

                        Default implementation searches upward from file_path for include_patterns, respecting exclude_patterns. Override for custom behavior (e.g., workspace detection).

                        Parameters:

                        Name Type Description Default
                        file_path str

                        The file being edited

                        required
                        project_root str

                        The overall project/workspace root (stop boundary)

                        required
                        fs AsyncFileSystem

                        Filesystem to use for file operations

                        required

                        Returns:

                        Type Description
                        str | None

                        The resolved root directory, or None if this LSP shouldn't be used

                        Source code in src/anyenv/lsp_servers/_base.py
                        async def resolve_root(
                            self,
                            file_path: str,
                            project_root: str,
                            fs: AsyncFileSystem,
                        ) -> str | None:
                            """Resolve the LSP root directory for a given file.
                        
                            Default implementation searches upward from file_path for include_patterns,
                            respecting exclude_patterns. Override for custom behavior (e.g., workspace detection).
                        
                            Args:
                                file_path: The file being edited
                                project_root: The overall project/workspace root (stop boundary)
                                fs: Filesystem to use for file operations
                        
                            Returns:
                                The resolved root directory, or None if this LSP shouldn't be used
                            """
                            if self.root_detection.exclude_patterns:
                                excluded = await self._find_nearest(
                                    posixpath.dirname(file_path),
                                    self.root_detection.exclude_patterns,
                                    project_root,
                                    fs,
                                )
                                if excluded:
                                    return None
                        
                            found = await self._find_nearest(
                                posixpath.dirname(file_path),
                                self.root_detection.include_patterns,
                                project_root,
                                fs,
                            )
                            return posixpath.dirname(found) if found else project_root
                        

                        :fa-brands-github: Show source on GitHub