mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 20:15:20 +00:00
Merge pull request #1644 from oraios/ts-subclass-init-params
F'up InitializeParams: Update remaining LS, force impl via @abstractmethod
This commit is contained in:
6 files changed
+18
-47
No files matched your search
@@ -70,7 +70,7 @@ from solidlsp.language_servers.typescript_language_server import (
|
||||
from solidlsp.language_servers.vscode_html_language_server import VsCodeHtmlLanguageServer
|
||||
from solidlsp.ls import LanguageServerDependencyProvider, LSPFileBuffer, SolidLanguageServer
|
||||
from solidlsp.ls_config import FilenameMatcher, Language, LanguageServerConfig
|
||||
from solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, InitializeParams, SymbolInformation
|
||||
from solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, SymbolInformation
|
||||
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
||||
from solidlsp.settings import SolidLSPSettings
|
||||
|
||||
@@ -502,8 +502,7 @@ class AngularLanguageServer(SolidLanguageServer):
|
||||
else:
|
||||
log.debug("Found @angular/core at %s", found)
|
||||
|
||||
def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:
|
||||
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
||||
def _create_base_initialize_params(self) -> dict:
|
||||
params: dict = {
|
||||
"locale": "en",
|
||||
"capabilities": {
|
||||
@@ -531,17 +530,8 @@ class AngularLanguageServer(SolidLanguageServer):
|
||||
"tsProbeLocations": [os.path.join(self._install_dir, "node_modules")],
|
||||
"forceStrictTemplates": False,
|
||||
},
|
||||
"processId": os.getpid(),
|
||||
"rootPath": repository_absolute_path,
|
||||
"rootUri": root_uri,
|
||||
"workspaceFolders": [
|
||||
{
|
||||
"uri": root_uri,
|
||||
"name": os.path.basename(repository_absolute_path),
|
||||
}
|
||||
],
|
||||
}
|
||||
return params # type: ignore[return-value]
|
||||
return params
|
||||
|
||||
@override
|
||||
def _start_server(self) -> None:
|
||||
@@ -580,7 +570,7 @@ class AngularLanguageServer(SolidLanguageServer):
|
||||
try:
|
||||
log.info("Starting Angular language server (ngserver)")
|
||||
self.server.start()
|
||||
init_params = self._get_initialize_params(self.repository_root_path)
|
||||
init_params = self._create_initialize_params()
|
||||
init_response = self.server.send.initialize(init_params)
|
||||
log.debug("Angular LS initialize response: %s", init_response)
|
||||
self.server.notify.initialized({})
|
||||
|
||||
@@ -28,7 +28,6 @@ from solidlsp.ls import (
|
||||
SolidLanguageServer,
|
||||
)
|
||||
from solidlsp.ls_config import FilenameMatcher, Language, LanguageServerConfig
|
||||
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
||||
from solidlsp.settings import SolidLSPSettings
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -440,7 +439,7 @@ class SvelteLanguageServer(SolidLanguageServer):
|
||||
|
||||
self.server.notify.send_notification = send_notification_wrapped
|
||||
|
||||
def _get_initialize_params(self) -> InitializeParams:
|
||||
def _create_base_initialize_params(self) -> dict:
|
||||
"""
|
||||
Returns the initialize params for the Svelte Language Server.
|
||||
|
||||
@@ -451,8 +450,6 @@ class SvelteLanguageServer(SolidLanguageServer):
|
||||
The resulting dict is also stored as :attr:`_lsp_configuration` so
|
||||
``workspace/configuration`` requests can be answered with real values.
|
||||
"""
|
||||
root_uri = pathlib.Path(self.repo_path).as_uri()
|
||||
|
||||
# base configuration mirroring all plugin-sections from svelte-vscode initializationOptions
|
||||
lsp_config: dict[str, Any] = {
|
||||
"svelte": {},
|
||||
@@ -514,17 +511,8 @@ class SvelteLanguageServer(SolidLanguageServer):
|
||||
"dontFilterIncompleteCompletions": True,
|
||||
"configuration": lsp_config,
|
||||
},
|
||||
"processId": os.getpid(),
|
||||
"rootPath": self.repo_path,
|
||||
"rootUri": root_uri,
|
||||
"workspaceFolders": [
|
||||
{
|
||||
"uri": root_uri,
|
||||
"name": os.path.basename(self.repo_path),
|
||||
}
|
||||
],
|
||||
}
|
||||
return cast(InitializeParams, initialize_params)
|
||||
return initialize_params
|
||||
|
||||
def _start_server(self) -> None:
|
||||
def window_log_message(msg: dict) -> None:
|
||||
@@ -562,7 +550,7 @@ class SvelteLanguageServer(SolidLanguageServer):
|
||||
self._wrap_notify_send_for_ts_js_mirror()
|
||||
self.server.start()
|
||||
|
||||
init_params = self._get_initialize_params()
|
||||
init_params = self._create_initialize_params()
|
||||
init_response = self.server.send.initialize(init_params)
|
||||
|
||||
assert "documentSymbolProvider" in init_response["capabilities"], "Svelte LSP did not advertise documentSymbolProvider"
|
||||
|
||||
@@ -27,7 +27,7 @@ from solidlsp.ls_exceptions import SolidLSPException
|
||||
from solidlsp.ls_types import Location
|
||||
from solidlsp.ls_utils import PathUtils
|
||||
from solidlsp.lsp_protocol_handler import lsp_types
|
||||
from solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, ExecuteCommandParams, InitializeParams, SymbolInformation
|
||||
from solidlsp.lsp_protocol_handler.lsp_types import DocumentSymbol, ExecuteCommandParams, SymbolInformation
|
||||
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
||||
from solidlsp.settings import SolidLSPSettings
|
||||
|
||||
@@ -617,8 +617,7 @@ class VueLanguageServer(SolidLanguageServer):
|
||||
|
||||
return [vue_executable_path, "--stdio"], tsdk_path, ts_ls_executable_path
|
||||
|
||||
def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:
|
||||
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
||||
def _create_base_initialize_params(self) -> dict:
|
||||
initialize_params = {
|
||||
"locale": "en",
|
||||
"capabilities": {
|
||||
@@ -644,15 +643,6 @@ class VueLanguageServer(SolidLanguageServer):
|
||||
"symbol": {"dynamicRegistration": True},
|
||||
},
|
||||
},
|
||||
"processId": os.getpid(),
|
||||
"rootPath": repository_absolute_path,
|
||||
"rootUri": root_uri,
|
||||
"workspaceFolders": [
|
||||
{
|
||||
"uri": root_uri,
|
||||
"name": os.path.basename(repository_absolute_path),
|
||||
}
|
||||
],
|
||||
"initializationOptions": {
|
||||
"vue": {
|
||||
"hybridMode": True,
|
||||
@@ -662,7 +652,7 @@ class VueLanguageServer(SolidLanguageServer):
|
||||
},
|
||||
},
|
||||
}
|
||||
return initialize_params # type: ignore
|
||||
return initialize_params
|
||||
|
||||
def _start_typescript_server(self) -> None:
|
||||
try:
|
||||
@@ -811,7 +801,7 @@ class VueLanguageServer(SolidLanguageServer):
|
||||
|
||||
log.info("Starting Vue server process")
|
||||
self.server.start()
|
||||
initialize_params = self._get_initialize_params(self.repository_root_path)
|
||||
initialize_params = self._create_initialize_params()
|
||||
|
||||
log.info("Sending initialize request from LSP client to LSP server and awaiting response")
|
||||
init_response = self.server.send.initialize(initialize_params)
|
||||
|
||||
+1
-1
@@ -3321,6 +3321,7 @@ class SolidLanguageServer(ABC):
|
||||
def _create_initialize_params_builder(self) -> InitializeParamsBuilder:
|
||||
return DefaultInitializeParamsBuilder(self)
|
||||
|
||||
@abstractmethod
|
||||
def _create_base_initialize_params(self) -> dict | InitializeParams:
|
||||
"""
|
||||
Subclasses should override this method to provide server-specific InitializeParams settings,
|
||||
@@ -3340,7 +3341,6 @@ class SolidLanguageServer(ABC):
|
||||
|
||||
:return: the base InitializeParams settings
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def _create_initialize_params(self) -> InitializeParams:
|
||||
"""
|
||||
|
||||
@@ -335,10 +335,10 @@ class TestAngularStartupCleanup:
|
||||
def boom(*_args: object, **_kwargs: object) -> dict:
|
||||
raise RuntimeError("simulated ngserver init failure")
|
||||
|
||||
# _get_initialize_params runs after both companions and ngserver have
|
||||
# been spawned — exactly the failure window the cleanup wrapper
|
||||
# _create_base_initialize_params runs after both companions and ngserver
|
||||
# have been spawned — exactly the failure window the cleanup wrapper
|
||||
# protects against.
|
||||
monkeypatch.setattr(ls, "_get_initialize_params", boom)
|
||||
monkeypatch.setattr(ls, "_create_base_initialize_params", boom)
|
||||
|
||||
try:
|
||||
with pytest.raises(RuntimeError, match="simulated ngserver init"):
|
||||
|
||||
@@ -7,6 +7,9 @@ class DummyLanguageServer(SolidLanguageServer):
|
||||
def _start_server(self) -> None:
|
||||
raise AssertionError("Not used in this test")
|
||||
|
||||
def _create_base_initialize_params(self) -> dict:
|
||||
return {}
|
||||
|
||||
|
||||
def test_request_rename_symbol_edit_opens_file_before_rename(tmp_path) -> None:
|
||||
(tmp_path / "index.ts").write_text("export const x = 1;\n", encoding="utf-8")
|
||||
|
||||
Reference in new issue
Block a user