You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/language-configuration.md
+36-9Lines changed: 36 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,17 @@ In the `lsp-client` SDK, language-specific configurations are primarily defined
13
13
-**project_files (`list[str]`)**:
14
14
A list of "marker" files used to identify the project root directory (e.g., `["pyproject.toml", "Cargo.toml", "package.json"]`). When the client attempts to determine the root directory for a file, it searches upwards recursively for directories containing these files.
15
15
-**exclude_files (`list[str]`)**:
16
-
A list of marker files indicating that a directory should _not_ be considered a project root.
16
+
A list of marker files indicating that a directory should _not_ be considered a project root. For example, `["venv", ".venv"]` can be used to prevent the client from treating a virtual environment as a project root.
17
17
18
18
## Project Root Discovery
19
19
20
20
The client determines the project root by searching upwards from the given file path until a valid project root is found or the system root is reached. This discovery is based on the `project_files` and `exclude_files` defined in the `LanguageConfig`.
21
21
22
-
The `LanguageConfig` class provides a `find_project_root(path: Path)` method that combines `suffixes`, `project_files`, and `exclude_files` for precise detection.
22
+
The `LanguageConfig` class provides a `find_project_root(path: Path)` method:
23
+
1. If the path is a file, it first checks if the file suffix matches. If not, it returns `None`.
24
+
2. It then searches upwards for `exclude_files`. If found, it stops and returns `None`.
25
+
3. It searches upwards for `project_files`. If found, it returns the containing directory.
26
+
4. If no markers are found, it returns the original directory (or the file's parent).
23
27
24
28
## Client Language Attributes
25
29
@@ -31,26 +35,49 @@ The `Client` base class includes several general configurations related to langu
31
35
Custom options passed to the server during the `initialize` request. Most Language Servers require specific configurations here to function correctly.
32
36
-**`request_timeout` (float, default `5.0`)**:
33
37
The timeout in seconds for LSP requests.
38
+
-**`create_default_config()`**:
39
+
An optional method to provide default LSP configuration (settings) for the client. These settings are typically used to configure the Language Server's behavior (e.g., enabling/disabling specific analysis features).
34
40
35
41
## Example: Defining a Custom Language Client
36
42
37
-
To support a new language, you typically inherit from `Client`(or a base class like `PythonClientBase`) and implement the `get_language_config` method:
43
+
To support a new language, you typically inherit from `Client` and implement the required abstract methods:
38
44
39
45
```python
40
-
from pathlib import Path
41
-
from typing import override
46
+
from typing import Any, override
42
47
from lsp_client.client.abc import Client
43
48
from lsp_client.client.lang import LanguageConfig
49
+
from lsp_client.server import DefaultServers
44
50
from lsp_client.utils.types import lsp_type
45
51
46
52
classMyNewLanguageClient(Client):
53
+
@classmethod
47
54
@override
48
-
defget_language_config(self) -> LanguageConfig:
55
+
defget_language_config(cls) -> LanguageConfig:
49
56
return LanguageConfig(
50
-
kind=lsp_type.LanguageKind.PlainText,# Replace with actual language kind
57
+
kind=lsp_type.LanguageKind.PlainText,
51
58
suffixes=[".mylang"],
52
-
project_files=["my_project.config"]
59
+
project_files=["my_project.config"],
60
+
exclude_files=[".ignore_me"]
53
61
)
54
62
55
-
# Other abstract methods like create_default_servers must also be implemented
0 commit comments