Skip to content

Commit 1c0ca6f

Browse files
committed
refactor: remove initialization options
1 parent f599a16 commit 1c0ca6f

File tree

8 files changed

+14
-269
lines changed

8 files changed

+14
-269
lines changed

src/lsp_client/client/abc.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import AsyncGenerator
66
from contextlib import asynccontextmanager, suppress
77
from pathlib import Path
8-
from typing import Any, Literal, Self, override
8+
from typing import Literal, Self, override
99

1010
import anyio
1111
import asyncer
@@ -60,6 +60,7 @@ class Client(
6060

6161
sync_file: bool = True
6262
request_timeout: float = 5.0
63+
initialization_options: dict = field(factory=dict)
6364

6465
_server: Server = field(init=False)
6566
_workspace: Workspace = field(init=False)
@@ -118,16 +119,6 @@ def get_language_id(self) -> lsp_type.LanguageKind:
118119
def create_default_servers(self) -> DefaultServers:
119120
"""Create default servers for this client."""
120121

121-
@abstractmethod
122-
def create_initialization_options(self) -> dict[str, Any]:
123-
"""
124-
Create initialization options for the `initialize` request.
125-
126-
Override this to provide server-specific initialization options.
127-
"""
128-
129-
return {}
130-
131122
@abstractmethod
132123
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
133124
"""Check if the available server capabilities are compatible with the client."""
@@ -297,7 +288,7 @@ async def __asynccontextmanager__(self) -> AsyncGenerator[Self]:
297288
# set both `root_path` and `root_uri` for compatibility
298289
root_path=root_path,
299290
root_uri=root_uri,
300-
initialization_options=self.create_initialization_options(),
291+
initialization_options=self.initialization_options,
301292
trace=lsp_type.TraceValue.Verbose,
302293
workspace_folders=self._workspace.to_folders(),
303294
)

src/lsp_client/clients/deno/client.py

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from functools import partial
55
from pathlib import Path
66
from subprocess import CalledProcessError
7-
from typing import Any, override
7+
from typing import override
88

99
import anyio
10-
from attrs import Factory, define
10+
from attrs import define
1111
from loguru import logger
1212

1313
from lsp_client.capability.notification import (
@@ -137,28 +137,6 @@ class DenoClient(
137137
- VSCode Extension: https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
138138
"""
139139

140-
enable: bool = True
141-
unstable: bool = False
142-
lint: bool = True
143-
144-
config: str | None = None
145-
import_map: str | None = None
146-
147-
code_lens_implementations: bool = True
148-
code_lens_references: bool = True
149-
code_lens_references_all_functions: bool = True
150-
code_lens_test: bool = True
151-
152-
suggest_complete_function_calls: bool = True
153-
suggest_names: bool = True
154-
suggest_paths: bool = True
155-
suggest_auto_imports: bool = True
156-
suggest_imports_auto_discover: bool = True
157-
suggest_imports_hosts: list[str] = Factory(list)
158-
159-
testing_enable: bool = False
160-
testing_args: list[str] = Factory(list)
161-
162140
@classmethod
163141
def check_project_root(cls, path: Path) -> bool:
164142
return any((path / f).exists() for f in ("deno.json", "deno.jsonc"))
@@ -174,44 +152,6 @@ def create_default_servers(self) -> DefaultServers:
174152
container=DenoContainerServer(),
175153
)
176154

177-
@override
178-
def create_initialization_options(self) -> dict[str, Any]:
179-
options: dict[str, Any] = {
180-
"enable": self.enable,
181-
"unstable": self.unstable,
182-
"lint": self.lint,
183-
"codeLens": {
184-
"implementations": self.code_lens_implementations,
185-
"references": self.code_lens_references,
186-
"referencesAllFunctions": self.code_lens_references_all_functions,
187-
"test": self.code_lens_test,
188-
},
189-
"suggest": {
190-
"completeFunctionCalls": self.suggest_complete_function_calls,
191-
"names": self.suggest_names,
192-
"paths": self.suggest_paths,
193-
"autoImports": self.suggest_auto_imports,
194-
"imports": {
195-
"autoDiscover": self.suggest_imports_auto_discover,
196-
"hosts": list(self.suggest_imports_hosts),
197-
},
198-
},
199-
}
200-
201-
if self.config:
202-
options["config"] = self.config
203-
204-
if self.import_map:
205-
options["importMap"] = self.import_map
206-
207-
if self.testing_enable:
208-
options["testing"] = {
209-
"enable": self.testing_enable,
210-
"args": list(self.testing_args),
211-
}
212-
213-
return options
214-
215155
@override
216156
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
217157
return

src/lsp_client/clients/gopls.py

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import shutil
44
from functools import partial
55
from subprocess import CalledProcessError
6-
from typing import Any, Literal, override
6+
from typing import override
77

88
import anyio
9-
from attrs import define, field
9+
from attrs import define
1010
from loguru import logger
1111

12-
from lsp_client.capability.notification import (
13-
WithNotifyDidChangeConfiguration,
14-
)
12+
from lsp_client.capability.notification import WithNotifyDidChangeConfiguration
1513
from lsp_client.capability.request import (
1614
WithRequestCallHierarchy,
1715
WithRequestCompletion,
@@ -107,103 +105,13 @@ class GoplsClient(
107105
- VSCode Extension: https://marketplace.visualstudio.com/items?itemName=golang.go
108106
"""
109107

110-
all_experiments: bool = False
111-
analyses: dict[str, bool | str] = field(factory=dict)
112-
allow_modfile_mods: bool = False
113-
allow_multi_line_string_literals: bool = False
114-
allow_implicit_variable_assignments: bool = False
115-
build_directory: str | None = None
116-
codelenses: dict[str, bool] = field(factory=dict)
117-
complete_completions: bool = False
118-
complete_unimported: bool = False
119-
completion_budget: str | None = None
120-
diagnostics_delay: str | None = None
121-
documentation_options: dict[str, bool] = field(factory=dict)
122-
experimental_postfix_completions: bool = True
123-
experimental_prefixed_format: bool = True
124-
experimental_template_support: bool = False
125-
experimental_workspace_module: bool = False
126-
gofumpt: bool = False
127-
hover_kind: Literal[
128-
"FullDocumentation", "NoDocumentation", "SingleLine", "Structured"
129-
] = "FullDocumentation"
130-
link_in_hover: bool = True
131-
link_target: str = "pkg.go.dev"
132-
matcher: Literal["Fuzzy", "CaseInsensitive", "CaseSensitive"] = "Fuzzy"
133-
semantic_tokens: bool = True
134-
staticcheck: bool = False
135-
use_placeholders: bool = False
136-
verbose_output: bool = False
137-
138108
@override
139109
def create_default_servers(self) -> DefaultServers:
140110
return DefaultServers(
141111
local=GoplsLocalServer(),
142112
container=GoplsContainerServer(),
143113
)
144114

145-
@override
146-
def create_initialization_options(self) -> dict[str, Any]:
147-
options: dict[str, Any] = {}
148-
149-
if self.all_experiments:
150-
options["allExperiments"] = self.all_experiments
151-
152-
if self.analyses:
153-
options["analyses"] = self.analyses
154-
155-
if self.allow_modfile_mods:
156-
options["allowModfileMods"] = self.allow_modfile_mods
157-
158-
if self.allow_multi_line_string_literals:
159-
options["allowMultiLineStringLiterals"] = (
160-
self.allow_multi_line_string_literals
161-
)
162-
163-
if self.allow_implicit_variable_assignments:
164-
options["allowImplicitVariableAssignments"] = (
165-
self.allow_implicit_variable_assignments
166-
)
167-
168-
if self.build_directory:
169-
options["buildDirectory"] = self.build_directory
170-
171-
if self.codelenses:
172-
options["codelenses"] = self.codelenses
173-
174-
if self.complete_completions:
175-
options["completeCompletions"] = self.complete_completions
176-
177-
if self.complete_unimported:
178-
options["completeUnimported"] = self.complete_unimported
179-
180-
if self.completion_budget:
181-
options["completionBudget"] = self.completion_budget
182-
183-
if self.diagnostics_delay:
184-
options["diagnosticsDelay"] = self.diagnostics_delay
185-
186-
if self.documentation_options:
187-
options["documentationOptions"] = self.documentation_options
188-
189-
options["experimentalPostfixCompletions"] = (
190-
self.experimental_postfix_completions
191-
)
192-
options["experimentalPrefixedFormat"] = self.experimental_prefixed_format
193-
options["experimentalTemplateSupport"] = self.experimental_template_support
194-
options["experimentalWorkspaceModule"] = self.experimental_workspace_module
195-
options["gofumpt"] = self.gofumpt
196-
options["hoverKind"] = self.hover_kind
197-
options["linkInHover"] = self.link_in_hover
198-
options["linkTarget"] = self.link_target
199-
options["matcher"] = self.matcher
200-
options["semanticTokens"] = self.semantic_tokens
201-
options["staticcheck"] = self.staticcheck
202-
options["usePlaceholders"] = self.use_placeholders
203-
options["verboseOutput"] = self.verbose_output
204-
205-
return options
206-
207115
@override
208116
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
209117
return

src/lsp_client/clients/pyrefly.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shutil
44
from functools import partial
55
from subprocess import CalledProcessError
6-
from typing import Any, Literal, override
6+
from typing import override
77

88
import anyio
99
from attrs import define
@@ -112,28 +112,13 @@ class PyreflyClient(
112112
- VSCode Extension: https://github.com/facebook/pyrefly/tree/main/lsp
113113
"""
114114

115-
trace_server: Literal["off", "verbose"] = "off"
116-
"""LSP trace output verbosity"""
117-
118-
diagnostic_mode: Literal["Workspace", "OpenFilesOnly"] = "Workspace"
119-
"""How diagnostics are reported"""
120-
121115
@override
122116
def create_default_servers(self) -> DefaultServers:
123117
return DefaultServers(
124118
local=PyreflyLocalServer(),
125119
container=PyreflyContainerServer(),
126120
)
127121

128-
@override
129-
def create_initialization_options(self) -> dict[str, Any]:
130-
options: dict[str, Any] = {}
131-
132-
options["trace"] = {"server": self.trace_server}
133-
options["diagnostic_mode"] = self.diagnostic_mode
134-
135-
return options
136-
137122
@override
138123
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
139124
return

src/lsp_client/clients/pyright.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shutil
44
from functools import partial
55
from subprocess import CalledProcessError
6-
from typing import Any, Literal, override
6+
from typing import override
77

88
import anyio
99
from attrs import define
@@ -105,23 +105,13 @@ class PyrightClient(
105105
- VSCode Extension: https://github.com/microsoft/pyright/tree/main/packages/vscode-pyright
106106
"""
107107

108-
diagnostic_mode: Literal["openFilesOnly", "workspace"] = "workspace"
109-
disable_pull_diagnostics: bool = False
110-
111108
@override
112109
def create_default_servers(self) -> DefaultServers:
113110
return DefaultServers(
114111
local=PyrightLocalServer(),
115112
container=PyrightContainerServer(),
116113
)
117114

118-
@override
119-
def create_initialization_options(self) -> dict[str, Any]:
120-
return {
121-
"diagnosticMode": self.diagnostic_mode,
122-
"disablePullDiagnostics": self.disable_pull_diagnostics,
123-
}
124-
125115
@override
126116
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
127117
return

src/lsp_client/clients/rust_analyzer.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import shutil
44
from functools import partial
55
from subprocess import CalledProcessError
6-
from typing import Any, Literal, override
6+
from typing import override
77

88
import anyio
9-
from attrs import Factory, define
9+
from attrs import define
1010
from loguru import logger
1111

1212
from lsp_client.capability.notification import (
@@ -110,46 +110,13 @@ class RustAnalyzerClient(
110110
- VSCode Extension: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer
111111
"""
112112

113-
proc_macro_enable: bool = True
114-
cargo_build_scripts_enable: bool = True
115-
116-
check_command: Literal["check", "clippy"] = "check"
117-
check_all_targets: bool = True
118-
check_extra_args: list[str] = Factory(list)
119-
check_extra_env: dict[str, str] = Factory(dict)
120-
121-
diagnostics_enable: bool = True
122-
123-
cargo_features: list[str] = Factory(list)
124-
cargo_extra_args: list[str] = Factory(list)
125-
cargo_extra_env: dict[str, str] = Factory(dict)
126-
127113
@override
128114
def create_default_servers(self) -> DefaultServers:
129115
return DefaultServers(
130116
local=RustAnalyzerLocalServer(),
131117
container=RustAnalyzerContainerServer(),
132118
)
133119

134-
@override
135-
def create_initialization_options(self) -> dict[str, Any]:
136-
return {
137-
"procMacro": {"enable": self.proc_macro_enable},
138-
"cargo": {
139-
"buildScripts": {"enable": self.cargo_build_scripts_enable},
140-
"features": list(self.cargo_features),
141-
"extraArgs": list(self.cargo_extra_args),
142-
"extraEnv": dict(self.cargo_extra_env),
143-
},
144-
"check": {
145-
"command": self.check_command,
146-
"allTargets": self.check_all_targets,
147-
"extraArgs": list(self.check_extra_args),
148-
"extraEnv": dict(self.check_extra_env),
149-
},
150-
"diagnostics": {"enable": self.diagnostics_enable},
151-
}
152-
153120
@override
154121
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
155122
return

0 commit comments

Comments
 (0)