Skip to content

Commit fb27e07

Browse files
committed
doc: update doc
1 parent 114c971 commit fb27e07

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

docs/language-configuration.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ In the `lsp-client` SDK, language-specific configurations are primarily defined
1313
- **project_files (`list[str]`)**:
1414
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.
1515
- **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.
1717

1818
## Project Root Discovery
1919

2020
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`.
2121

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).
2327

2428
## Client Language Attributes
2529

@@ -31,26 +35,49 @@ The `Client` base class includes several general configurations related to langu
3135
Custom options passed to the server during the `initialize` request. Most Language Servers require specific configurations here to function correctly.
3236
- **`request_timeout` (float, default `5.0`)**:
3337
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).
3440

3541
## Example: Defining a Custom Language Client
3642

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:
3844

3945
```python
40-
from pathlib import Path
41-
from typing import override
46+
from typing import Any, override
4247
from lsp_client.client.abc import Client
4348
from lsp_client.client.lang import LanguageConfig
49+
from lsp_client.server import DefaultServers
4450
from lsp_client.utils.types import lsp_type
4551

4652
class MyNewLanguageClient(Client):
53+
@classmethod
4754
@override
48-
def get_language_config(self) -> LanguageConfig:
55+
def get_language_config(cls) -> LanguageConfig:
4956
return LanguageConfig(
50-
kind=lsp_type.LanguageKind.PlainText, # Replace with actual language kind
57+
kind=lsp_type.LanguageKind.PlainText,
5158
suffixes=[".mylang"],
52-
project_files=["my_project.config"]
59+
project_files=["my_project.config"],
60+
exclude_files=[".ignore_me"]
5361
)
5462

55-
# Other abstract methods like create_default_servers must also be implemented
63+
@override
64+
def create_default_servers(self) -> DefaultServers:
65+
# Define how to start the server (local or containerized)
66+
...
67+
68+
@override
69+
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
70+
# Optionally check if the server version/info is compatible
71+
pass
72+
73+
@override
74+
def create_default_config(self) -> dict[str, Any] | None:
75+
# Provide default LSP settings
76+
return {
77+
"mylang": {
78+
"analysis": {
79+
"enableFeatureX": True
80+
}
81+
}
82+
}
5683
```

0 commit comments

Comments
 (0)