Skip to content

lsp_servers

Class info

Classes

Name Children Inherits
AstroServer
anyenv.lsp_servers._servers.js_ts_lsps
Astro language server with TypeScript SDK detection.
    BiomeServer
    anyenv.lsp_servers._servers.js_ts_lsps
    Biome linter/formatter with JSON diagnostic parsing.
      CLIDiagnosticConfig
      anyenv.lsp_servers._base
      CLI configuration for running diagnostics without full LSP.
        CargoInstall
        anyenv.lsp_servers._base
        Install via cargo install.
          CommandExecutor
          anyenv.lsp_servers._runner
          Protocol for command execution.
            CommandResult
            anyenv.lsp_servers._runner
            Protocol for command execution results.
              Diagnostic
              anyenv.lsp_servers._base
              A single diagnostic message from a tool.
                DiagnosticRunner
                anyenv.lsp_servers._runner
                Run diagnostics using CLI tools.
                  DiagnosticsResult
                  anyenv.lsp_servers._base
                  Result of running diagnostics.
                    DotnetInstall
                    anyenv.lsp_servers._base
                    Install via dotnet tool install.
                      GemInstall
                      anyenv.lsp_servers._base
                      Install via gem install.
                        GitHubRelease
                        anyenv.lsp_servers._base
                        Download binary from GitHub releases.
                          GoInstall
                          anyenv.lsp_servers._base
                          Install via go install.
                            GoplsServer
                            anyenv.lsp_servers._servers.go_lsps
                            Go language server with go.work priority.
                              LSPServerInfo
                              anyenv.lsp_servers._base
                              Static configuration for an LSP server.
                              LSPServerRegistry
                              anyenv.lsp_servers._registry
                              Registry for managing LSP server configurations.
                                MypyServer
                                anyenv.lsp_servers._servers.python_lsps
                                Mypy with JSON diagnostic parsing.
                                  NpmInstall
                                  anyenv.lsp_servers._base
                                  Install via npm/bun/pnpm.
                                    OxlintServer
                                    anyenv.lsp_servers._servers.js_ts_lsps
                                    Oxlint (oxc) linter with JSON diagnostic parsing.
                                      PyreflyServer
                                      anyenv.lsp_servers._servers.python_lsps
                                      Pyrefly (Meta) type checker with JSON diagnostic parsing.
                                        PyrightServer
                                        anyenv.lsp_servers._servers.python_lsps
                                        Pyright with virtualenv detection and JSON diagnostic parsing.
                                          RootDetection
                                          anyenv.lsp_servers._base
                                          How to detect project root for LSP.
                                            RustAnalyzerServer
                                            anyenv.lsp_servers._servers.rust_lsps
                                            Rust analyzer with workspace detection.
                                              SimpleCommandResult
                                              anyenv.lsp_servers._runner
                                              Simple implementation of CommandResult.
                                                TyServer
                                                anyenv.lsp_servers._servers.python_lsps
                                                Ty (Astral) type checker with GitLab JSON diagnostic parsing.
                                                  TypeScriptServer
                                                  anyenv.lsp_servers._servers.js_ts_lsps
                                                  TypeScript language server with tsserver path detection.
                                                    ZubanServer
                                                    anyenv.lsp_servers._servers.python_lsps
                                                    Zuban type checker with mypy-compatible text output parsing.

                                                      🛈 DocStrings

                                                      LSP server configurations for various programming languages.

                                                      AstroServer dataclass

                                                      Bases: LSPServerInfo

                                                      Astro language server with TypeScript SDK detection.

                                                      Source code in src/anyenv/lsp_servers/_servers/js_ts_lsps.py
                                                      @dataclass
                                                      class AstroServer(LSPServerInfo):
                                                          """Astro language server with TypeScript SDK detection."""
                                                      
                                                          async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                              """Detect TypeScript SDK path for Astro."""
                                                              init = await super().resolve_initialization(root, fs)
                                                              tsserver = posixpath.join(root, "node_modules", "typescript", "lib", "tsserver.js")
                                                              try:
                                                                  if await fs._exists(tsserver):  # noqa: SLF001
                                                                      init["typescript"] = {"tsdk": posixpath.dirname(tsserver)}
                                                              except Exception:  # noqa: BLE001
                                                                  pass
                                                      
                                                              return init
                                                      

                                                      resolve_initialization async

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

                                                      Detect TypeScript SDK path for Astro.

                                                      Source code in src/anyenv/lsp_servers/_servers/js_ts_lsps.py
                                                      async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                          """Detect TypeScript SDK path for Astro."""
                                                          init = await super().resolve_initialization(root, fs)
                                                          tsserver = posixpath.join(root, "node_modules", "typescript", "lib", "tsserver.js")
                                                          try:
                                                              if await fs._exists(tsserver):  # noqa: SLF001
                                                                  init["typescript"] = {"tsdk": posixpath.dirname(tsserver)}
                                                          except Exception:  # noqa: BLE001
                                                              pass
                                                      
                                                          return init
                                                      

                                                      CLIDiagnosticConfig dataclass

                                                      CLI configuration for running diagnostics without full LSP.

                                                      Parameters:

                                                      Name Type Description Default
                                                      command str

                                                      Command to run (may differ from LSP command)

                                                      required
                                                      args list[str]

                                                      Arguments with {files} placeholder for file paths

                                                      required
                                                      output_format Literal['json', 'text']

                                                      Expected output format

                                                      'json'
                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class CLIDiagnosticConfig:
                                                          """CLI configuration for running diagnostics without full LSP.
                                                      
                                                          Args:
                                                              command: Command to run (may differ from LSP command)
                                                              args: Arguments with {files} placeholder for file paths
                                                              output_format: Expected output format
                                                          """
                                                      
                                                          command: str
                                                          args: list[str]
                                                          output_format: Literal["json", "text"] = "json"
                                                      

                                                      CargoInstall dataclass

                                                      Install via cargo install.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class CargoInstall:
                                                          """Install via cargo install."""
                                                      
                                                          package: str
                                                      

                                                      CommandExecutor

                                                      Bases: Protocol

                                                      Protocol for command execution.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      class CommandExecutor(Protocol):
                                                          """Protocol for command execution."""
                                                      
                                                          async def __call__(self, command: str) -> CommandResult:
                                                              """Execute a command and return the result."""
                                                              ...
                                                      

                                                      __call__ async

                                                      __call__(command: str) -> CommandResult
                                                      

                                                      Execute a command and return the result.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      async def __call__(self, command: str) -> CommandResult:
                                                          """Execute a command and return the result."""
                                                          ...
                                                      

                                                      CommandResult

                                                      Bases: Protocol

                                                      Protocol for command execution results.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      class CommandResult(Protocol):
                                                          """Protocol for command execution results."""
                                                      
                                                          @property
                                                          def stdout(self) -> str | None: ...
                                                      
                                                          @property
                                                          def stderr(self) -> str | None: ...
                                                      
                                                          @property
                                                          def exit_code(self) -> int | None: ...
                                                      
                                                          @property
                                                          def duration(self) -> float: ...
                                                      

                                                      Diagnostic dataclass

                                                      A single diagnostic message from a tool.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class Diagnostic:
                                                          """A single diagnostic message from a tool."""
                                                      
                                                          file: str
                                                          line: int
                                                          column: int
                                                          severity: Literal["error", "warning", "info", "hint"]
                                                          message: str
                                                          source: str
                                                          code: str | None = None
                                                          end_line: int | None = None
                                                          end_column: int | None = None
                                                      

                                                      DiagnosticRunner

                                                      Run diagnostics using CLI tools.

                                                      Works with any command executor (local subprocess, Docker, SSH, etc.) to run CLI diagnostic tools and parse their output.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      class DiagnosticRunner:
                                                          """Run diagnostics using CLI tools.
                                                      
                                                          Works with any command executor (local subprocess, Docker, SSH, etc.) to run
                                                          CLI diagnostic tools and parse their output.
                                                          """
                                                      
                                                          def __init__(self, executor: CommandExecutor | None = None) -> None:
                                                              """Initialize with an optional command executor.
                                                      
                                                              Args:
                                                                  executor: Callable to execute commands. Defaults to local subprocess.
                                                              """
                                                              self._executor = executor or _default_executor
                                                              self._servers: list[LSPServerInfo] = []
                                                      
                                                          def register(self, server: LSPServerInfo) -> None:
                                                              """Register an LSP server for diagnostics."""
                                                              if server.has_cli_diagnostics:
                                                                  self._servers.append(server)
                                                      
                                                          def register_defaults(self) -> None:
                                                              """Register all default servers with CLI diagnostic support."""
                                                              from anyenv.lsp_servers._servers import ALL_SERVERS
                                                      
                                                              for server in ALL_SERVERS:
                                                                  if server.has_cli_diagnostics:
                                                                      self.register(server)
                                                      
                                                          def get_server(self, server_id: str) -> LSPServerInfo | None:
                                                              """Get a server by ID."""
                                                              return next((s for s in self._servers if s.id == server_id), None)
                                                      
                                                          def get_servers_for_file(self, path: str) -> list[LSPServerInfo]:
                                                              """Get all servers that can handle a file."""
                                                              ext = posixpath.splitext(path)[1]
                                                              return [s for s in self._servers if s.can_handle(ext)]
                                                      
                                                          async def run(self, server: LSPServerInfo | str, files: list[str]) -> DiagnosticsResult:
                                                              """Run diagnostics using a specific server.
                                                      
                                                              Args:
                                                                  server: Server instance or server ID
                                                                  files: File paths to check
                                                      
                                                              Returns:
                                                                  DiagnosticsResult with parsed diagnostics
                                                              """
                                                              if isinstance(server, str):
                                                                  srv = self.get_server(server)
                                                                  if srv is None:
                                                                      msg = f"Server {server!r} not found"
                                                                      return DiagnosticsResult(diagnostics=[], success=False, duration=0.0, error=msg)
                                                                  server = srv
                                                      
                                                              if not server.has_cli_diagnostics:
                                                                  msg = f"Server {server.id!r} has no CLI diagnostic support"
                                                                  return DiagnosticsResult(diagnostics=[], success=False, duration=0.0, error=msg)
                                                      
                                                              command = server.build_diagnostic_command(files)
                                                              result = await self._executor(command)
                                                              diagnostics = server.parse_diagnostics(result.stdout or "", result.stderr or "")
                                                              # Parsing succeeded, even if there are errors
                                                              return DiagnosticsResult(diagnostics=diagnostics, success=True, duration=result.duration)
                                                      
                                                          async def run_all(
                                                              self, files: list[str], *, concurrency: int = 1
                                                          ) -> dict[str, DiagnosticsResult]:
                                                              """Run all applicable servers on the given files.
                                                      
                                                              Args:
                                                                  files: File paths to check
                                                                  concurrency: How many servers may run at once. The default runs them one
                                                                      after another (safe for remote executors and slow machines).
                                                      
                                                              Returns:
                                                                  Dict mapping server ID to DiagnosticsResult, in registration order
                                                              """
                                                              if concurrency < 1:
                                                                  msg = f"concurrency must be at least 1, got {concurrency}"
                                                                  raise ValueError(msg)
                                                              # Each applicable server gets all the files it handles, whatever the extension.
                                                              files_by_server: dict[str, tuple[LSPServerInfo, list[str]]] = {}
                                                              for server in self._servers:
                                                                  server_files = [f for f in files if server.can_handle(posixpath.splitext(f)[1])]
                                                                  if server_files and server.id not in files_by_server:
                                                                      files_by_server[server.id] = (server, server_files)
                                                      
                                                              semaphore = asyncio.Semaphore(concurrency)
                                                      
                                                              async def run_one(server: LSPServerInfo, server_files: list[str]) -> DiagnosticsResult:
                                                                  async with semaphore:
                                                                      return await self.run(server, server_files)
                                                      
                                                              results = await asyncio.gather(*(run_one(s, f) for s, f in files_by_server.values()))
                                                              return dict(zip(files_by_server, results, strict=True))
                                                      
                                                          async def run_for_file(self, path: str) -> list[Diagnostic]:
                                                              """Run all applicable servers on a single file.
                                                      
                                                              Args:
                                                                  path: File path to check
                                                      
                                                              Returns:
                                                                  Combined list of diagnostics from all applicable servers
                                                              """
                                                              all_diagnostics: list[Diagnostic] = []
                                                              for server in self.get_servers_for_file(path):
                                                                  result = await self.run(server, [path])
                                                                  all_diagnostics.extend(result.diagnostics)
                                                      
                                                              return all_diagnostics
                                                      

                                                      __init__

                                                      __init__(executor: CommandExecutor | None = None) -> None
                                                      

                                                      Initialize with an optional command executor.

                                                      Parameters:

                                                      Name Type Description Default
                                                      executor CommandExecutor | None

                                                      Callable to execute commands. Defaults to local subprocess.

                                                      None
                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      def __init__(self, executor: CommandExecutor | None = None) -> None:
                                                          """Initialize with an optional command executor.
                                                      
                                                          Args:
                                                              executor: Callable to execute commands. Defaults to local subprocess.
                                                          """
                                                          self._executor = executor or _default_executor
                                                          self._servers: list[LSPServerInfo] = []
                                                      

                                                      get_server

                                                      get_server(server_id: str) -> LSPServerInfo | None
                                                      

                                                      Get a server by ID.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      def get_server(self, server_id: str) -> LSPServerInfo | None:
                                                          """Get a server by ID."""
                                                          return next((s for s in self._servers if s.id == server_id), None)
                                                      

                                                      get_servers_for_file

                                                      get_servers_for_file(path: str) -> list[LSPServerInfo]
                                                      

                                                      Get all servers that can handle a file.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      def get_servers_for_file(self, path: str) -> list[LSPServerInfo]:
                                                          """Get all servers that can handle a file."""
                                                          ext = posixpath.splitext(path)[1]
                                                          return [s for s in self._servers if s.can_handle(ext)]
                                                      

                                                      register

                                                      register(server: LSPServerInfo) -> None
                                                      

                                                      Register an LSP server for diagnostics.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      def register(self, server: LSPServerInfo) -> None:
                                                          """Register an LSP server for diagnostics."""
                                                          if server.has_cli_diagnostics:
                                                              self._servers.append(server)
                                                      

                                                      register_defaults

                                                      register_defaults() -> None
                                                      

                                                      Register all default servers with CLI diagnostic support.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      def register_defaults(self) -> None:
                                                          """Register all default servers with CLI diagnostic support."""
                                                          from anyenv.lsp_servers._servers import ALL_SERVERS
                                                      
                                                          for server in ALL_SERVERS:
                                                              if server.has_cli_diagnostics:
                                                                  self.register(server)
                                                      

                                                      run async

                                                      run(server: LSPServerInfo | str, files: list[str]) -> DiagnosticsResult
                                                      

                                                      Run diagnostics using a specific server.

                                                      Parameters:

                                                      Name Type Description Default
                                                      server LSPServerInfo | str

                                                      Server instance or server ID

                                                      required
                                                      files list[str]

                                                      File paths to check

                                                      required

                                                      Returns:

                                                      Type Description
                                                      DiagnosticsResult

                                                      DiagnosticsResult with parsed diagnostics

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      async def run(self, server: LSPServerInfo | str, files: list[str]) -> DiagnosticsResult:
                                                          """Run diagnostics using a specific server.
                                                      
                                                          Args:
                                                              server: Server instance or server ID
                                                              files: File paths to check
                                                      
                                                          Returns:
                                                              DiagnosticsResult with parsed diagnostics
                                                          """
                                                          if isinstance(server, str):
                                                              srv = self.get_server(server)
                                                              if srv is None:
                                                                  msg = f"Server {server!r} not found"
                                                                  return DiagnosticsResult(diagnostics=[], success=False, duration=0.0, error=msg)
                                                              server = srv
                                                      
                                                          if not server.has_cli_diagnostics:
                                                              msg = f"Server {server.id!r} has no CLI diagnostic support"
                                                              return DiagnosticsResult(diagnostics=[], success=False, duration=0.0, error=msg)
                                                      
                                                          command = server.build_diagnostic_command(files)
                                                          result = await self._executor(command)
                                                          diagnostics = server.parse_diagnostics(result.stdout or "", result.stderr or "")
                                                          # Parsing succeeded, even if there are errors
                                                          return DiagnosticsResult(diagnostics=diagnostics, success=True, duration=result.duration)
                                                      

                                                      run_all async

                                                      run_all(files: list[str], *, concurrency: int = 1) -> dict[str, DiagnosticsResult]
                                                      

                                                      Run all applicable servers on the given files.

                                                      Parameters:

                                                      Name Type Description Default
                                                      files list[str]

                                                      File paths to check

                                                      required
                                                      concurrency int

                                                      How many servers may run at once. The default runs them one after another (safe for remote executors and slow machines).

                                                      1

                                                      Returns:

                                                      Type Description
                                                      dict[str, DiagnosticsResult]

                                                      Dict mapping server ID to DiagnosticsResult, in registration order

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      async def run_all(
                                                          self, files: list[str], *, concurrency: int = 1
                                                      ) -> dict[str, DiagnosticsResult]:
                                                          """Run all applicable servers on the given files.
                                                      
                                                          Args:
                                                              files: File paths to check
                                                              concurrency: How many servers may run at once. The default runs them one
                                                                  after another (safe for remote executors and slow machines).
                                                      
                                                          Returns:
                                                              Dict mapping server ID to DiagnosticsResult, in registration order
                                                          """
                                                          if concurrency < 1:
                                                              msg = f"concurrency must be at least 1, got {concurrency}"
                                                              raise ValueError(msg)
                                                          # Each applicable server gets all the files it handles, whatever the extension.
                                                          files_by_server: dict[str, tuple[LSPServerInfo, list[str]]] = {}
                                                          for server in self._servers:
                                                              server_files = [f for f in files if server.can_handle(posixpath.splitext(f)[1])]
                                                              if server_files and server.id not in files_by_server:
                                                                  files_by_server[server.id] = (server, server_files)
                                                      
                                                          semaphore = asyncio.Semaphore(concurrency)
                                                      
                                                          async def run_one(server: LSPServerInfo, server_files: list[str]) -> DiagnosticsResult:
                                                              async with semaphore:
                                                                  return await self.run(server, server_files)
                                                      
                                                          results = await asyncio.gather(*(run_one(s, f) for s, f in files_by_server.values()))
                                                          return dict(zip(files_by_server, results, strict=True))
                                                      

                                                      run_for_file async

                                                      run_for_file(path: str) -> list[Diagnostic]
                                                      

                                                      Run all applicable servers on a single file.

                                                      Parameters:

                                                      Name Type Description Default
                                                      path str

                                                      File path to check

                                                      required

                                                      Returns:

                                                      Type Description
                                                      list[Diagnostic]

                                                      Combined list of diagnostics from all applicable servers

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      async def run_for_file(self, path: str) -> list[Diagnostic]:
                                                          """Run all applicable servers on a single file.
                                                      
                                                          Args:
                                                              path: File path to check
                                                      
                                                          Returns:
                                                              Combined list of diagnostics from all applicable servers
                                                          """
                                                          all_diagnostics: list[Diagnostic] = []
                                                          for server in self.get_servers_for_file(path):
                                                              result = await self.run(server, [path])
                                                              all_diagnostics.extend(result.diagnostics)
                                                      
                                                          return all_diagnostics
                                                      

                                                      DiagnosticsResult dataclass

                                                      Result of running diagnostics.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class DiagnosticsResult:
                                                          """Result of running diagnostics."""
                                                      
                                                          diagnostics: list[Diagnostic]
                                                          success: bool
                                                          duration: float
                                                          error: str | None = None
                                                      

                                                      DotnetInstall dataclass

                                                      Install via dotnet tool install.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class DotnetInstall:
                                                          """Install via dotnet tool install."""
                                                      
                                                          package: str
                                                      

                                                      GemInstall dataclass

                                                      Install via gem install.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class GemInstall:
                                                          """Install via gem install."""
                                                      
                                                          package: str
                                                      

                                                      GitHubRelease dataclass

                                                      Download binary from GitHub releases.

                                                      Parameters:

                                                      Name Type Description Default
                                                      repo str

                                                      Repository in "owner/repo" format

                                                      required
                                                      asset_pattern str

                                                      Pattern with placeholders: {version}, {arch}, {platform}, {ext}

                                                      required
                                                      binary_name str

                                                      Name of the binary after extraction

                                                      required
                                                      extract_subdir str | None

                                                      Subdirectory within archive containing the binary

                                                      None
                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class GitHubRelease:
                                                          """Download binary from GitHub releases.
                                                      
                                                          Args:
                                                              repo: Repository in "owner/repo" format
                                                              asset_pattern: Pattern with placeholders: {version}, {arch}, {platform}, {ext}
                                                              binary_name: Name of the binary after extraction
                                                              extract_subdir: Subdirectory within archive containing the binary
                                                          """
                                                      
                                                          repo: str
                                                          asset_pattern: str
                                                          binary_name: str
                                                          extract_subdir: str | None = None
                                                      

                                                      GoInstall dataclass

                                                      Install via go install.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class GoInstall:
                                                          """Install via go install."""
                                                      
                                                          package: str  # e.g., "golang.org/x/tools/gopls@latest"
                                                      

                                                      GoplsServer dataclass

                                                      Bases: LSPServerInfo

                                                      Go language server with go.work priority.

                                                      Source code in src/anyenv/lsp_servers/_servers/go_lsps.py
                                                      @dataclass
                                                      class GoplsServer(LSPServerInfo):
                                                          """Go language server with go.work priority."""
                                                      
                                                          async def resolve_root(
                                                              self,
                                                              file_path: str,
                                                              project_root: str,
                                                              fs: AsyncFileSystem,
                                                          ) -> str | None:
                                                              """Prefer go.work over go.mod for workspace support."""
                                                              # First check for go.work
                                                              work_root = await self._find_nearest(
                                                                  posixpath.dirname(file_path),
                                                                  ["go.work"],
                                                                  project_root,
                                                                  fs,
                                                              )
                                                              if work_root:
                                                                  return posixpath.dirname(work_root)
                                                      
                                                              # Fall back to go.mod
                                                              mod_root = await self._find_nearest(
                                                                  posixpath.dirname(file_path),
                                                                  ["go.mod", "go.sum"],
                                                                  project_root,
                                                                  fs,
                                                              )
                                                              return posixpath.dirname(mod_root) if mod_root else project_root
                                                      

                                                      resolve_root async

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

                                                      Prefer go.work over go.mod for workspace support.

                                                      Source code in src/anyenv/lsp_servers/_servers/go_lsps.py
                                                      async def resolve_root(
                                                          self,
                                                          file_path: str,
                                                          project_root: str,
                                                          fs: AsyncFileSystem,
                                                      ) -> str | None:
                                                          """Prefer go.work over go.mod for workspace support."""
                                                          # First check for go.work
                                                          work_root = await self._find_nearest(
                                                              posixpath.dirname(file_path),
                                                              ["go.work"],
                                                              project_root,
                                                              fs,
                                                          )
                                                          if work_root:
                                                              return posixpath.dirname(work_root)
                                                      
                                                          # Fall back to go.mod
                                                          mod_root = await self._find_nearest(
                                                              posixpath.dirname(file_path),
                                                              ["go.mod", "go.sum"],
                                                              project_root,
                                                              fs,
                                                          )
                                                          return posixpath.dirname(mod_root) if mod_root else project_root
                                                      

                                                      LSPServerInfo dataclass

                                                      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
                                                      

                                                      LSPServerRegistry

                                                      Registry for managing LSP server configurations.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      class LSPServerRegistry:
                                                          """Registry for managing LSP server configurations."""
                                                      
                                                          def __init__(self) -> None:
                                                              self._servers: list[LSPServerInfo] = []
                                                      
                                                          def register(self, server: LSPServerInfo) -> None:
                                                              """Register an LSP server."""
                                                              self._servers.append(server)
                                                      
                                                          def register_defaults(self) -> None:
                                                              """Register all default LSP servers."""
                                                              from anyenv.lsp_servers._servers import ALL_SERVERS
                                                      
                                                              for server in ALL_SERVERS:
                                                                  self.register(server)
                                                      
                                                          def get_by_id(self, server_id: str) -> LSPServerInfo | None:
                                                              """Get server by ID."""
                                                              return next((s for s in self._servers if s.id == server_id), None)
                                                      
                                                          def get_by_extension(self, extension: str) -> list[LSPServerInfo]:
                                                              """Get all servers that handle a given file extension."""
                                                              return [s for s in self._servers if s.can_handle(extension)]
                                                      
                                                          def get_for_file(self, path: Path) -> list[LSPServerInfo]:
                                                              """Get all servers that can handle a given file."""
                                                              return self.get_by_extension(path.suffix)
                                                      
                                                          def get_by_command(self, command: str) -> LSPServerInfo | None:
                                                              """Get server by command name."""
                                                              return next((s for s in self._servers if s.command == command), None)
                                                      
                                                          def get_installable(self) -> list[LSPServerInfo]:
                                                              """Get all servers that can be auto-installed."""
                                                              return [s for s in self._servers if s.has_auto_install]
                                                      
                                                          @property
                                                          def all_servers(self) -> list[LSPServerInfo]:
                                                              """Get all registered servers."""
                                                              return list(self._servers)
                                                      
                                                          def get_supported_extensions(self) -> set[str]:
                                                              """Get all supported file extensions."""
                                                              return {ext for server in self._servers for ext in server.extensions}
                                                      

                                                      all_servers property

                                                      all_servers: list[LSPServerInfo]
                                                      

                                                      Get all registered servers.

                                                      get_by_command

                                                      get_by_command(command: str) -> LSPServerInfo | None
                                                      

                                                      Get server by command name.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_by_command(self, command: str) -> LSPServerInfo | None:
                                                          """Get server by command name."""
                                                          return next((s for s in self._servers if s.command == command), None)
                                                      

                                                      get_by_extension

                                                      get_by_extension(extension: str) -> list[LSPServerInfo]
                                                      

                                                      Get all servers that handle a given file extension.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_by_extension(self, extension: str) -> list[LSPServerInfo]:
                                                          """Get all servers that handle a given file extension."""
                                                          return [s for s in self._servers if s.can_handle(extension)]
                                                      

                                                      get_by_id

                                                      get_by_id(server_id: str) -> LSPServerInfo | None
                                                      

                                                      Get server by ID.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_by_id(self, server_id: str) -> LSPServerInfo | None:
                                                          """Get server by ID."""
                                                          return next((s for s in self._servers if s.id == server_id), None)
                                                      

                                                      get_for_file

                                                      get_for_file(path: Path) -> list[LSPServerInfo]
                                                      

                                                      Get all servers that can handle a given file.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_for_file(self, path: Path) -> list[LSPServerInfo]:
                                                          """Get all servers that can handle a given file."""
                                                          return self.get_by_extension(path.suffix)
                                                      

                                                      get_installable

                                                      get_installable() -> list[LSPServerInfo]
                                                      

                                                      Get all servers that can be auto-installed.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_installable(self) -> list[LSPServerInfo]:
                                                          """Get all servers that can be auto-installed."""
                                                          return [s for s in self._servers if s.has_auto_install]
                                                      

                                                      get_supported_extensions

                                                      get_supported_extensions() -> set[str]
                                                      

                                                      Get all supported file extensions.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def get_supported_extensions(self) -> set[str]:
                                                          """Get all supported file extensions."""
                                                          return {ext for server in self._servers for ext in server.extensions}
                                                      

                                                      register

                                                      register(server: LSPServerInfo) -> None
                                                      

                                                      Register an LSP server.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def register(self, server: LSPServerInfo) -> None:
                                                          """Register an LSP server."""
                                                          self._servers.append(server)
                                                      

                                                      register_defaults

                                                      register_defaults() -> None
                                                      

                                                      Register all default LSP servers.

                                                      Source code in src/anyenv/lsp_servers/_registry.py
                                                      def register_defaults(self) -> None:
                                                          """Register all default LSP servers."""
                                                          from anyenv.lsp_servers._servers import ALL_SERVERS
                                                      
                                                          for server in ALL_SERVERS:
                                                              self.register(server)
                                                      

                                                      MypyServer dataclass

                                                      Bases: LSPServerInfo

                                                      Mypy with JSON diagnostic parsing.

                                                      Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
                                                      @dataclass
                                                      class MypyServer(LSPServerInfo):
                                                          """Mypy with JSON diagnostic parsing."""
                                                      
                                                          def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
                                                              """Parse mypy JSON output (one JSON object per line)."""
                                                              import anyenv
                                                      
                                                              diagnostics: list[Diagnostic] = []
                                                              for line in output.strip().splitlines():
                                                                  line = line.strip()
                                                                  if not line or not line.startswith("{"):
                                                                      continue
                                                                  try:
                                                                      data = anyenv.load_json(line, return_type=dict)
                                                                      diagnostics.append(
                                                                          Diagnostic(
                                                                              file=data.get("file", ""),
                                                                              line=data.get("line", 1),
                                                                              column=data.get("column", 1),
                                                                              severity=severity_from_string(data.get("severity", "error")),
                                                                              message=data.get("message", ""),
                                                                              code=data.get("code"),
                                                                              source=self.id,
                                                                          )
                                                                      )
                                                                  except anyenv.JsonLoadError:
                                                                      continue
                                                      
                                                              return diagnostics
                                                      

                                                      NpmInstall dataclass

                                                      Install via npm/bun/pnpm.

                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class NpmInstall:
                                                          """Install via npm/bun/pnpm."""
                                                      
                                                          package: str
                                                          entry_path: str  # relative path from node_modules, e.g., "pyright/dist/pyright-langserver.js"
                                                      

                                                      PyrightServer dataclass

                                                      Bases: LSPServerInfo

                                                      Pyright with virtualenv detection and JSON diagnostic parsing.

                                                      Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
                                                      @dataclass
                                                      class PyrightServer(LSPServerInfo):
                                                          """Pyright with virtualenv detection and JSON diagnostic parsing."""
                                                      
                                                          async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                              """Detect virtualenv and set pythonPath."""
                                                              init = await super().resolve_initialization(root, fs)
                                                      
                                                              for venv_path in get_python_venv_candidates(root):
                                                                  if os.name == "nt":
                                                                      python = posixpath.join(venv_path, "Scripts", "python.exe")
                                                                  else:
                                                                      python = posixpath.join(venv_path, "bin", "python")
                                                                  try:
                                                                      if await fs._exists(python):  # noqa: SLF001
                                                                          init["pythonPath"] = python
                                                                          break
                                                                  except Exception:  # noqa: BLE001
                                                                      pass
                                                      
                                                              return init
                                                      
                                                          def _parse_json_diagnostics(self, output: str) -> list[Diagnostic]:
                                                              """Parse pyright JSON output."""
                                                              import anyenv
                                                      
                                                              diagnostics: list[Diagnostic] = []
                                                      
                                                              try:
                                                                  # Find JSON object in output (may have warnings before it)
                                                                  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("generalDiagnostics", []):
                                                                      range_info = diag.get("range", {})
                                                                      start = range_info.get("start", {})
                                                                      end = range_info.get("end", {})
                                                      
                                                                      diagnostics.append(
                                                                          Diagnostic(
                                                                              file=diag.get("file", ""),
                                                                              line=start.get("line", 0) + 1,  # pyright uses 0-indexed
                                                                              column=start.get("character", 0) + 1,
                                                                              end_line=end.get("line", start.get("line", 0)) + 1,
                                                                              end_column=end.get("character", start.get("character", 0)) + 1,
                                                                              severity=severity_from_string(diag.get("severity", "error")),
                                                                              message=diag.get("message", ""),
                                                                              code=diag.get("rule"),
                                                                              source=self.id,
                                                                          )
                                                                      )
                                                              except anyenv.JsonLoadError:
                                                                  pass
                                                      
                                                              return diagnostics
                                                      

                                                      resolve_initialization async

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

                                                      Detect virtualenv and set pythonPath.

                                                      Source code in src/anyenv/lsp_servers/_servers/python_lsps.py
                                                      async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                          """Detect virtualenv and set pythonPath."""
                                                          init = await super().resolve_initialization(root, fs)
                                                      
                                                          for venv_path in get_python_venv_candidates(root):
                                                              if os.name == "nt":
                                                                  python = posixpath.join(venv_path, "Scripts", "python.exe")
                                                              else:
                                                                  python = posixpath.join(venv_path, "bin", "python")
                                                              try:
                                                                  if await fs._exists(python):  # noqa: SLF001
                                                                      init["pythonPath"] = python
                                                                      break
                                                              except Exception:  # noqa: BLE001
                                                                  pass
                                                      
                                                          return init
                                                      

                                                      RootDetection dataclass

                                                      How to detect project root for LSP.

                                                      Parameters:

                                                      Name Type Description Default
                                                      include_patterns list[str]

                                                      File patterns that indicate project root (e.g., ["pyproject.toml"])

                                                      required
                                                      exclude_patterns list[str] | None

                                                      If these are found, skip this LSP (e.g., ["deno.json"] for typescript)

                                                      None
                                                      workspace_marker str | None

                                                      Content marker for workspace detection (e.g., "[workspace]" in Cargo.toml)

                                                      None
                                                      Source code in src/anyenv/lsp_servers/_base.py
                                                      @dataclass
                                                      class RootDetection:
                                                          """How to detect project root for LSP.
                                                      
                                                          Args:
                                                              include_patterns: File patterns that indicate project root (e.g., ["pyproject.toml"])
                                                              exclude_patterns: If these are found, skip this LSP (e.g., ["deno.json"] for typescript)
                                                              workspace_marker: Content marker for workspace detection (e.g., "[workspace]" in Cargo.toml)
                                                          """
                                                      
                                                          include_patterns: list[str]
                                                          exclude_patterns: list[str] | None = None
                                                          workspace_marker: str | None = None
                                                      

                                                      RustAnalyzerServer dataclass

                                                      Bases: LSPServerInfo

                                                      Rust analyzer with workspace detection.

                                                      Source code in src/anyenv/lsp_servers/_servers/rust_lsps.py
                                                      @dataclass
                                                      class RustAnalyzerServer(LSPServerInfo):
                                                          """Rust analyzer with workspace detection."""
                                                      
                                                          async def resolve_root(
                                                              self,
                                                              file_path: str,
                                                              project_root: str,
                                                              fs: AsyncFileSystem,
                                                          ) -> str | None:
                                                              """Walk up to find workspace root containing [workspace] in Cargo.toml."""
                                                              crate_root = await super().resolve_root(file_path, project_root, fs)
                                                              if crate_root is None:
                                                                  return None
                                                      
                                                              # Walk up looking for workspace
                                                              current = crate_root.rstrip("/")
                                                              project_root = project_root.rstrip("/")
                                                      
                                                              while True:
                                                                  cargo_toml = posixpath.join(current, "Cargo.toml")
                                                                  try:
                                                                      if await fs._exists(cargo_toml):  # noqa: SLF001
                                                                          content = (await fs._cat_file(cargo_toml)).decode()  # noqa: SLF001
                                                                          if "[workspace]" in content:
                                                                              return current
                                                                  except Exception:  # noqa: BLE001
                                                                      pass
                                                      
                                                                  if current == project_root:
                                                                      break
                                                                  parent = posixpath.dirname(current)
                                                                  if current in (parent, fs.root_marker):
                                                                      break
                                                                  current = parent
                                                      
                                                              return crate_root
                                                      

                                                      resolve_root async

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

                                                      Walk up to find workspace root containing [workspace] in Cargo.toml.

                                                      Source code in src/anyenv/lsp_servers/_servers/rust_lsps.py
                                                      async def resolve_root(
                                                          self,
                                                          file_path: str,
                                                          project_root: str,
                                                          fs: AsyncFileSystem,
                                                      ) -> str | None:
                                                          """Walk up to find workspace root containing [workspace] in Cargo.toml."""
                                                          crate_root = await super().resolve_root(file_path, project_root, fs)
                                                          if crate_root is None:
                                                              return None
                                                      
                                                          # Walk up looking for workspace
                                                          current = crate_root.rstrip("/")
                                                          project_root = project_root.rstrip("/")
                                                      
                                                          while True:
                                                              cargo_toml = posixpath.join(current, "Cargo.toml")
                                                              try:
                                                                  if await fs._exists(cargo_toml):  # noqa: SLF001
                                                                      content = (await fs._cat_file(cargo_toml)).decode()  # noqa: SLF001
                                                                      if "[workspace]" in content:
                                                                          return current
                                                              except Exception:  # noqa: BLE001
                                                                  pass
                                                      
                                                              if current == project_root:
                                                                  break
                                                              parent = posixpath.dirname(current)
                                                              if current in (parent, fs.root_marker):
                                                                  break
                                                              current = parent
                                                      
                                                          return crate_root
                                                      

                                                      SimpleCommandResult dataclass

                                                      Simple implementation of CommandResult.

                                                      Source code in src/anyenv/lsp_servers/_runner.py
                                                      @dataclass
                                                      class SimpleCommandResult:
                                                          """Simple implementation of CommandResult."""
                                                      
                                                          stdout: str | None
                                                          stderr: str | None
                                                          exit_code: int | None
                                                          duration: float
                                                      

                                                      TypeScriptServer dataclass

                                                      Bases: LSPServerInfo

                                                      TypeScript language server with tsserver path detection.

                                                      Source code in src/anyenv/lsp_servers/_servers/js_ts_lsps.py
                                                      @dataclass
                                                      class TypeScriptServer(LSPServerInfo):
                                                          """TypeScript language server with tsserver path detection."""
                                                      
                                                          async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                              """Detect tsserver.js path."""
                                                              init = await super().resolve_initialization(root, fs)
                                                              tsserver = posixpath.join(root, "node_modules", "typescript", "lib", "tsserver.js")
                                                              try:
                                                                  if await fs._exists(tsserver):  # noqa: SLF001
                                                                      init["tsserver"] = {"path": tsserver}
                                                              except Exception:  # noqa: BLE001
                                                                  pass
                                                      
                                                              return init
                                                      

                                                      resolve_initialization async

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

                                                      Detect tsserver.js path.

                                                      Source code in src/anyenv/lsp_servers/_servers/js_ts_lsps.py
                                                      async def resolve_initialization(self, root: str, fs: AsyncFileSystem) -> dict[str, Any]:
                                                          """Detect tsserver.js path."""
                                                          init = await super().resolve_initialization(root, fs)
                                                          tsserver = posixpath.join(root, "node_modules", "typescript", "lib", "tsserver.js")
                                                          try:
                                                              if await fs._exists(tsserver):  # noqa: SLF001
                                                                  init["tsserver"] = {"path": tsserver}
                                                          except Exception:  # noqa: BLE001
                                                              pass
                                                      
                                                          return init