23 lines
550 B
Python
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
|