|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from abc import ABC |
| 4 | +from pathlib import Path |
| 5 | +from typing import override |
| 6 | + |
| 7 | +from lsp_client.client.abc import Client |
| 8 | +from lsp_client.utils.types import lsp_type |
| 9 | + |
| 10 | + |
| 11 | +class PythonClientBase(Client, ABC): |
| 12 | + @classmethod |
| 13 | + def check_project_root(cls, path: Path) -> bool: |
| 14 | + return any( |
| 15 | + (path / f).exists() |
| 16 | + for f in ( |
| 17 | + "pyproject.toml", |
| 18 | + "setup.py", |
| 19 | + "setup.cfg", |
| 20 | + "requirements.txt", |
| 21 | + ".python-version", |
| 22 | + ) |
| 23 | + ) |
| 24 | + |
| 25 | + @override |
| 26 | + def get_language_id(self) -> lsp_type.LanguageKind: |
| 27 | + return lsp_type.LanguageKind.Python |
| 28 | + |
| 29 | + |
| 30 | +class RustClientBase(Client, ABC): |
| 31 | + @classmethod |
| 32 | + def check_project_root(cls, path: Path) -> bool: |
| 33 | + return (path / "Cargo.toml").exists() |
| 34 | + |
| 35 | + @override |
| 36 | + def get_language_id(self) -> lsp_type.LanguageKind: |
| 37 | + return lsp_type.LanguageKind.Rust |
| 38 | + |
| 39 | + |
| 40 | +class GoClientBase(Client, ABC): |
| 41 | + @classmethod |
| 42 | + def check_project_root(cls, path: Path) -> bool: |
| 43 | + return (path / "go.mod").exists() |
| 44 | + |
| 45 | + @override |
| 46 | + def get_language_id(self) -> lsp_type.LanguageKind: |
| 47 | + return lsp_type.LanguageKind.Go |
| 48 | + |
| 49 | + |
| 50 | +class TypeScriptClientBase(Client, ABC): |
| 51 | + @classmethod |
| 52 | + def check_project_root(cls, path: Path) -> bool: |
| 53 | + return any( |
| 54 | + (path / f).exists() |
| 55 | + for f in ("package.json", "tsconfig.json", "jsconfig.json") |
| 56 | + ) |
| 57 | + |
| 58 | + @override |
| 59 | + def get_language_id(self) -> lsp_type.LanguageKind: |
| 60 | + return lsp_type.LanguageKind.TypeScript |
0 commit comments