Skip to content

Commit 20fc1ad

Browse files
committed
feat: redesign configuration mechanism
1 parent 55b8c95 commit 20fc1ad

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/lsp_client/capability/notification/did_change_configuration.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ async def _notify_change_configuration(
4545
lsp_type.DidChangeConfigurationNotification(params=params)
4646
)
4747

48-
def get_default_settings(self) -> Any:
49-
return {}
48+
async def notify_change_configuration(self, settings: Any | None = None) -> None:
49+
"""
50+
Notify the server that the configuration has changed.
51+
52+
For most clients, the `settings` parameter is often set to `None`, indicating that the server should fetch the updated configuration itself.
53+
"""
5054

51-
async def notify_change_configuration(self, settings: Any | None) -> None:
5255
return await self._notify_change_configuration(
5356
lsp_type.DidChangeConfigurationParams(settings=settings)
5457
)

src/lsp_client/capability/server_request/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from typing import Final
44

5+
from .configuration import WithRespondConfigurationRequest
56
from .inlay_hint_refresh import WithRespondInlayHintRefresh
67
from .show_document_request import WithRespondShowDocumentRequest
78
from .show_message_request import WithRespondShowMessageRequest
8-
from .workspace_configuration import WithRespondConfigurationRequest
99
from .workspace_folders import WithRespondWorkspaceFoldersRequest
1010

1111
capabilities: Final = (

src/lsp_client/capability/server_request/workspace_configuration.py renamed to src/lsp_client/capability/server_request/configuration.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from abc import abstractmethod
34
from collections.abc import Iterator
45
from typing import Any, Protocol, override, runtime_checkable
56

@@ -45,14 +46,26 @@ def register_workspace_capability(
4546
def check_server_capability(cls, cap: lsp_type.ServerCapabilities) -> None:
4647
super().check_server_capability(cap)
4748

49+
@abstractmethod
50+
def get_configuration(self, scope_uri: str | None, section: str | None) -> Any:
51+
"""
52+
Get the configuration value for the given scope URI and section.
53+
54+
If a client supports this capability, it's the user's responsibility to implement this method to return the appropriate configuration value.
55+
56+
:param scope_uri: The scope URI for which to get the configuration.
57+
:param section: The section of the configuration to get.
58+
:return: The configuration value.
59+
"""
60+
4861
async def _respond_configuration(
4962
self, params: lsp_type.ConfigurationParams
5063
) -> list[Any]:
5164
logger.debug("Responding to configuration request")
52-
53-
# TODO add reasonable default behavior
54-
55-
return [None for _ in params.items]
65+
return [
66+
self.get_configuration(item.scope_uri, item.section)
67+
for item in params.items
68+
]
5669

5770
async def respond_configuration_request(
5871
self, req: lsp_type.ConfigurationRequest

src/lsp_client/client/abc.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
build_server_request_hooks,
1919
)
2020
from lsp_client.capability.notification import WithNotifyTextDocumentSynchronize
21-
from lsp_client.capability.notification.did_change_configuration import (
22-
WithNotifyDidChangeConfiguration,
23-
)
2421
from lsp_client.client.buffer import LSPFileBuffer
2522
from lsp_client.jsonrpc.convert import (
2623
notification_serialize,
@@ -294,10 +291,6 @@ async def __asynccontextmanager__(self) -> AsyncGenerator[Self]:
294291
)
295292
)
296293

297-
# send initial configuration if supported
298-
if isinstance(self, WithNotifyDidChangeConfiguration):
299-
await self.notify_change_configuration(self.get_default_settings())
300-
301294
try:
302295
yield self
303296
finally:

0 commit comments

Comments
 (0)