Skip to content

Commit 0308624

Browse files
Copilotobserverw
andcommitted
Add default configuration_map for all clients with extra features enabled
Co-authored-by: observerw <[email protected]>
1 parent 44782bd commit 0308624

File tree

8 files changed

+320
-0
lines changed

8 files changed

+320
-0
lines changed

src/lsp_client/client/abc.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from lsp_client.server import DefaultServers, Server, ServerRuntimeError
3535
from lsp_client.server.types import ServerRequest
3636
from lsp_client.utils.channel import Receiver, channel
37+
from lsp_client.utils.config import ConfigurationMap
3738
from lsp_client.utils.types import AnyPath, Notification, Request, Response, lsp_type
3839
from lsp_client.utils.workspace import (
3940
DEFAULT_WORKSPACE_DIR,
@@ -109,6 +110,18 @@ def create_default_servers(self) -> DefaultServers:
109110
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
110111
"""Check if the available server capabilities are compatible with the client."""
111112

113+
def create_default_configuration_map(self) -> ConfigurationMap | None:
114+
"""
115+
Create default configuration map for this client.
116+
117+
This method can be overridden by subclasses to provide default configurations
118+
that enable extra features like inlay hints, diagnostics, etc.
119+
120+
Returns:
121+
ConfigurationMap with default settings, or None if no defaults are needed.
122+
"""
123+
return None
124+
112125
@override
113126
@asynccontextmanager
114127
async def open_files(self, *file_paths: AnyPath) -> AsyncGenerator[None]:
@@ -246,6 +259,18 @@ async def _run_server(
246259
async def __asynccontextmanager__(self) -> AsyncGenerator[Self]:
247260
self._workspace = format_workspace(self._workspace_arg)
248261

262+
# Initialize default configuration map if the client supports configuration
263+
# and no configuration map has been set yet
264+
from lsp_client.capability.server_request import WithRespondConfigurationRequest
265+
266+
if (
267+
isinstance(self, WithRespondConfigurationRequest)
268+
and self.configuration_map is None
269+
):
270+
default_config = self.create_default_configuration_map()
271+
if default_config is not None:
272+
self.configuration_map = default_config
273+
249274
async with (
250275
asyncer.create_task_group() as tg,
251276
self._run_server() as (server, receiver), # ty: ignore[invalid-argument-type]

src/lsp_client/clients/deno/client.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from lsp_client.server import DefaultServers, ServerInstallationError
4545
from lsp_client.server.container import ContainerServer
4646
from lsp_client.server.local import LocalServer
47+
from lsp_client.utils.config import ConfigurationMap
4748
from lsp_client.utils.types import lsp_type
4849

4950
from .extension import (
@@ -155,3 +156,52 @@ def create_default_servers(self) -> DefaultServers:
155156
@override
156157
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
157158
return
159+
160+
@override
161+
def create_default_configuration_map(self) -> ConfigurationMap | None:
162+
"""Create default configuration for deno with all features enabled."""
163+
config_map = ConfigurationMap()
164+
config_map.update_global(
165+
{
166+
"deno": {
167+
# Enable deno
168+
"enable": True,
169+
# Enable inlay hints
170+
"inlayHints": {
171+
"parameterNames": {"enabled": "all"},
172+
"parameterTypes": {"enabled": True},
173+
"variableTypes": {"enabled": True},
174+
"propertyDeclarationTypes": {"enabled": True},
175+
"functionLikeReturnTypes": {"enabled": True},
176+
"enumMemberValues": {"enabled": True},
177+
},
178+
# Enable linting
179+
"lint": True,
180+
# Enable unstable features
181+
"unstable": True,
182+
# Enable code lens
183+
"codeLens": {
184+
"implementations": True,
185+
"references": True,
186+
"referencesAllFunctions": True,
187+
"test": True,
188+
"testArgs": ["--allow-all"],
189+
},
190+
# Enable suggestions
191+
"suggest": {
192+
"autoImports": True,
193+
"completeFunctionCalls": True,
194+
"names": True,
195+
"paths": True,
196+
"imports": {
197+
"autoDiscover": True,
198+
"hosts": {
199+
"https://deno.land": True,
200+
"https://esm.sh": True,
201+
},
202+
},
203+
},
204+
}
205+
}
206+
)
207+
return config_map

src/lsp_client/clients/gopls.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from lsp_client.server import DefaultServers, ServerInstallationError
4242
from lsp_client.server.container import ContainerServer
4343
from lsp_client.server.local import LocalServer
44+
from lsp_client.utils.config import ConfigurationMap
4445
from lsp_client.utils.types import lsp_type
4546

4647
GoplsContainerServer = partial(ContainerServer, image="ghcr.io/lsp-client/gopls:latest")
@@ -115,3 +116,52 @@ def create_default_servers(self) -> DefaultServers:
115116
@override
116117
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
117118
return
119+
120+
@override
121+
def create_default_configuration_map(self) -> ConfigurationMap | None:
122+
"""Create default configuration for gopls with all features enabled."""
123+
config_map = ConfigurationMap()
124+
config_map.update_global(
125+
{
126+
"gopls": {
127+
# Enable inlay hints
128+
"hints": {
129+
"assignVariableTypes": True,
130+
"compositeLiteralFields": True,
131+
"compositeLiteralTypes": True,
132+
"constantValues": True,
133+
"functionTypeParameters": True,
134+
"parameterNames": True,
135+
"rangeVariableTypes": True,
136+
},
137+
# Enable code lenses
138+
"codelenses": {
139+
"gc_details": True,
140+
"generate": True,
141+
"regenerate_cgo": True,
142+
"run_govulncheck": True,
143+
"test": True,
144+
"tidy": True,
145+
"upgrade_dependency": True,
146+
"vendor": True,
147+
},
148+
# Enable diagnostics
149+
"diagnosticsDelay": "250ms",
150+
"analyses": {
151+
"fieldalignment": True,
152+
"nilness": True,
153+
"unusedparams": True,
154+
"unusedwrite": True,
155+
"useany": True,
156+
},
157+
# Enable completion features
158+
"completionDocumentation": True,
159+
"deepCompletion": True,
160+
"matcher": "Fuzzy",
161+
"usePlaceholders": True,
162+
# Enable semantic tokens
163+
"semanticTokens": True,
164+
}
165+
}
166+
)
167+
return config_map

src/lsp_client/clients/pyrefly.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from lsp_client.server import DefaultServers, ServerInstallationError
4444
from lsp_client.server.container import ContainerServer
4545
from lsp_client.server.local import LocalServer
46+
from lsp_client.utils.config import ConfigurationMap
4647
from lsp_client.utils.types import lsp_type
4748

4849
PyreflyContainerServer = partial(
@@ -122,3 +123,29 @@ def create_default_servers(self) -> DefaultServers:
122123
@override
123124
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
124125
return
126+
127+
@override
128+
def create_default_configuration_map(self) -> ConfigurationMap | None:
129+
"""Create default configuration for pyrefly with all features enabled."""
130+
config_map = ConfigurationMap()
131+
config_map.update_global(
132+
{
133+
"pyrefly": {
134+
# Enable inlay hints
135+
"inlayHints": {
136+
"variableTypes": True,
137+
"functionReturnTypes": True,
138+
"parameterTypes": True,
139+
},
140+
# Enable diagnostics
141+
"diagnostics": {
142+
"enable": True,
143+
},
144+
# Enable auto-imports
145+
"completion": {
146+
"autoImports": True,
147+
},
148+
}
149+
}
150+
)
151+
return config_map

src/lsp_client/clients/pyright.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from lsp_client.server import DefaultServers, ServerInstallationError
4242
from lsp_client.server.container import ContainerServer
4343
from lsp_client.server.local import LocalServer
44+
from lsp_client.utils.config import ConfigurationMap
4445
from lsp_client.utils.types import lsp_type
4546

4647
PyrightContainerServer = partial(
@@ -115,3 +116,38 @@ def create_default_servers(self) -> DefaultServers:
115116
@override
116117
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
117118
return
119+
120+
@override
121+
def create_default_configuration_map(self) -> ConfigurationMap | None:
122+
"""Create default configuration for pyright with all features enabled."""
123+
config_map = ConfigurationMap()
124+
config_map.update_global(
125+
{
126+
"python": {
127+
"analysis": {
128+
# Enable inlay hints
129+
"inlayHints": {
130+
"variableTypes": True,
131+
"functionReturnTypes": True,
132+
"callArgumentNames": True,
133+
"pytestParameters": True,
134+
},
135+
# Enable auto-import completions
136+
"autoImportCompletions": True,
137+
# Enable type checking (default: basic)
138+
"typeCheckingMode": "basic",
139+
# Enable diagnostics
140+
"diagnosticMode": "openFilesOnly",
141+
# Enable auto-search paths
142+
"autoSearchPaths": True,
143+
# Enable indexing
144+
"indexing": True,
145+
# Enable diagnostics for shadowed imports
146+
"diagnosticSeverityOverrides": {
147+
"reportGeneralTypeIssues": "warning",
148+
},
149+
}
150+
}
151+
}
152+
)
153+
return config_map

src/lsp_client/clients/rust_analyzer.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from lsp_client.server import DefaultServers, ServerInstallationError
4545
from lsp_client.server.container import ContainerServer
4646
from lsp_client.server.local import LocalServer
47+
from lsp_client.utils.config import ConfigurationMap
4748
from lsp_client.utils.types import lsp_type
4849

4950
RustAnalyzerContainerServer = partial(
@@ -120,3 +121,54 @@ def create_default_servers(self) -> DefaultServers:
120121
@override
121122
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
122123
return
124+
125+
@override
126+
def create_default_configuration_map(self) -> ConfigurationMap | None:
127+
"""Create default configuration for rust-analyzer with all features enabled."""
128+
config_map = ConfigurationMap()
129+
config_map.update_global(
130+
{
131+
"rust-analyzer": {
132+
# Enable inlay hints for all types
133+
"inlayHints": {
134+
"enable": True,
135+
"chainingHints": {"enable": True},
136+
"closureReturnTypeHints": {"enable": "always"},
137+
"lifetimeElisionHints": {"enable": "always"},
138+
"parameterHints": {"enable": True},
139+
"reborrowHints": {"enable": "always"},
140+
"renderColons": True,
141+
"typeHints": {"enable": True},
142+
},
143+
# Enable diagnostics
144+
"diagnostics": {
145+
"enable": True,
146+
"experimental": {"enable": True},
147+
},
148+
# Enable completion features
149+
"completion": {
150+
"autoimport": {"enable": True},
151+
"autoself": {"enable": True},
152+
"callable": {"snippets": "fill_arguments"},
153+
"postfix": {"enable": True},
154+
"privateEditable": {"enable": True},
155+
},
156+
# Enable checkOnSave with cargo check
157+
"checkOnSave": {"enable": True},
158+
# Enable code lens
159+
"lens": {
160+
"enable": True,
161+
"run": {"enable": True},
162+
"debug": {"enable": True},
163+
"implementations": {"enable": True},
164+
"references": {
165+
"adt": {"enable": True},
166+
"enumVariant": {"enable": True},
167+
"method": {"enable": True},
168+
"trait": {"enable": True},
169+
},
170+
},
171+
}
172+
}
173+
)
174+
return config_map

src/lsp_client/clients/ty.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from lsp_client.server import DefaultServers, ServerInstallationError
4141
from lsp_client.server.container import ContainerServer
4242
from lsp_client.server.local import LocalServer
43+
from lsp_client.utils.config import ConfigurationMap
4344
from lsp_client.utils.types import lsp_type
4445

4546
TyContainerServer = partial(ContainerServer, image="ghcr.io/lsp-client/ty:latest")
@@ -110,3 +111,23 @@ def create_default_servers(self) -> DefaultServers:
110111
@override
111112
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
112113
return
114+
115+
@override
116+
def create_default_configuration_map(self) -> ConfigurationMap | None:
117+
"""Create default configuration for ty with all features enabled."""
118+
config_map = ConfigurationMap()
119+
config_map.update_global(
120+
{
121+
"ty": {
122+
# Enable diagnostics
123+
"diagnostics": {
124+
"enable": True,
125+
},
126+
# Enable completion features
127+
"completion": {
128+
"autoImports": True,
129+
},
130+
}
131+
}
132+
)
133+
return config_map

0 commit comments

Comments
 (0)