This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-9p/tools/_lib/lsp/adapters/__init__.py

23 lines
550 B
Python

"""Adapter registry: detect language from file path, return appropriate adapter."""
import os
from .gopls import Gopls
from .clangd import Clangd
from .intelephense import Intelephense
_ADAPTERS = [Gopls, Clangd, Intelephense]
_EXT_MAP: dict[str, type] = {}
for _a in _ADAPTERS:
for _ext in _a.extensions:
_EXT_MAP[_ext] = _a
def detect(filepath: str):
"""Return an adapter class for the given file, or None."""
ext = os.path.splitext(filepath)[1]
cls = _EXT_MAP.get(ext)
if cls:
return cls()
return None