Add files using upload-large-folder tool
Browse files- projects/ui/serena-new/src/solidlsp/language_servers/intelephense.py +191 -0
- projects/ui/serena-new/src/solidlsp/language_servers/jedi_server.py +198 -0
- projects/ui/serena-new/src/solidlsp/language_servers/kotlin_language_server.py +469 -0
- projects/ui/serena-new/src/solidlsp/language_servers/lua_ls.py +297 -0
- projects/ui/serena-new/src/solidlsp/language_servers/nixd_ls.py +396 -0
- projects/ui/serena-new/src/solidlsp/language_servers/omnisharp.py +380 -0
- projects/ui/serena-new/src/solidlsp/language_servers/pyright_server.py +202 -0
- projects/ui/serena-new/src/solidlsp/language_servers/r_language_server.py +172 -0
- projects/ui/serena-new/src/solidlsp/language_servers/ruby_lsp.py +442 -0
- projects/ui/serena-new/src/solidlsp/language_servers/rust_analyzer.py +639 -0
- projects/ui/serena-new/src/solidlsp/language_servers/solargraph.py +373 -0
- projects/ui/serena-new/src/solidlsp/language_servers/sourcekit_lsp.py +358 -0
- projects/ui/serena-new/src/solidlsp/language_servers/terraform_ls.py +214 -0
- projects/ui/serena-new/src/solidlsp/language_servers/typescript_language_server.py +253 -0
- projects/ui/serena-new/src/solidlsp/language_servers/vts_language_server.py +235 -0
- projects/ui/serena-new/src/solidlsp/language_servers/zls.py +252 -0
- projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_constants.py +69 -0
- projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_requests.py +561 -0
- projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_types.py +0 -0
- projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/server.py +122 -0
projects/ui/serena-new/src/solidlsp/language_servers/intelephense.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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instantiation of the LanguageServer class using Intelephense.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import shutil
|
| 9 |
+
from time import sleep
|
| 10 |
+
|
| 11 |
+
from overrides import override
|
| 12 |
+
|
| 13 |
+
from solidlsp.ls import SolidLanguageServer
|
| 14 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 15 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 16 |
+
from solidlsp.ls_utils import PlatformId, PlatformUtils
|
| 17 |
+
from solidlsp.lsp_protocol_handler.lsp_types import DefinitionParams, InitializeParams
|
| 18 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 19 |
+
from solidlsp.settings import SolidLSPSettings
|
| 20 |
+
|
| 21 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Intelephense(SolidLanguageServer):
|
| 25 |
+
"""
|
| 26 |
+
Provides PHP specific instantiation of the LanguageServer class using Intelephense.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
@override
|
| 30 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 31 |
+
# For PHP projects, we should ignore:
|
| 32 |
+
# - vendor: third-party dependencies managed by Composer
|
| 33 |
+
# - node_modules: if the project has JavaScript components
|
| 34 |
+
# - cache: commonly used for caching
|
| 35 |
+
return super().is_ignored_dirname(dirname) or dirname in ["node_modules", "vendor", "cache"]
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def _setup_runtime_dependencies(
|
| 39 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 40 |
+
) -> str:
|
| 41 |
+
"""
|
| 42 |
+
Setup runtime dependencies for Intelephense and return the command to start the server.
|
| 43 |
+
"""
|
| 44 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 45 |
+
|
| 46 |
+
valid_platforms = [
|
| 47 |
+
PlatformId.LINUX_x64,
|
| 48 |
+
PlatformId.LINUX_arm64,
|
| 49 |
+
PlatformId.OSX,
|
| 50 |
+
PlatformId.OSX_x64,
|
| 51 |
+
PlatformId.OSX_arm64,
|
| 52 |
+
PlatformId.WIN_x64,
|
| 53 |
+
PlatformId.WIN_arm64,
|
| 54 |
+
]
|
| 55 |
+
assert platform_id in valid_platforms, f"Platform {platform_id} is not supported for multilspy PHP at the moment"
|
| 56 |
+
|
| 57 |
+
# Verify both node and npm are installed
|
| 58 |
+
is_node_installed = shutil.which("node") is not None
|
| 59 |
+
assert is_node_installed, "node is not installed or isn't in PATH. Please install NodeJS and try again."
|
| 60 |
+
is_npm_installed = shutil.which("npm") is not None
|
| 61 |
+
assert is_npm_installed, "npm is not installed or isn't in PATH. Please install npm and try again."
|
| 62 |
+
|
| 63 |
+
# Install intelephense if not already installed
|
| 64 |
+
intelephense_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "php-lsp")
|
| 65 |
+
os.makedirs(intelephense_ls_dir, exist_ok=True)
|
| 66 |
+
intelephense_executable_path = os.path.join(intelephense_ls_dir, "node_modules", ".bin", "intelephense")
|
| 67 |
+
if not os.path.exists(intelephense_executable_path):
|
| 68 |
+
deps = RuntimeDependencyCollection(
|
| 69 |
+
[
|
| 70 |
+
RuntimeDependency(
|
| 71 |
+
id="intelephense",
|
| 72 |
+
command="npm install --prefix ./ intelephense@1.14.4",
|
| 73 |
+
platform_id="any",
|
| 74 |
+
)
|
| 75 |
+
]
|
| 76 |
+
)
|
| 77 |
+
deps.install(logger, intelephense_ls_dir)
|
| 78 |
+
|
| 79 |
+
assert os.path.exists(
|
| 80 |
+
intelephense_executable_path
|
| 81 |
+
), f"intelephense executable not found at {intelephense_executable_path}, something went wrong."
|
| 82 |
+
|
| 83 |
+
return f"{intelephense_executable_path} --stdio"
|
| 84 |
+
|
| 85 |
+
def __init__(
|
| 86 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 87 |
+
):
|
| 88 |
+
# Setup runtime dependencies before initializing
|
| 89 |
+
intelephense_cmd = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 90 |
+
|
| 91 |
+
super().__init__(
|
| 92 |
+
config,
|
| 93 |
+
logger,
|
| 94 |
+
repository_root_path,
|
| 95 |
+
ProcessLaunchInfo(cmd=intelephense_cmd, cwd=repository_root_path),
|
| 96 |
+
"php",
|
| 97 |
+
solidlsp_settings,
|
| 98 |
+
)
|
| 99 |
+
self.request_id = 0
|
| 100 |
+
|
| 101 |
+
@staticmethod
|
| 102 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 103 |
+
"""
|
| 104 |
+
Returns the initialize params for the Intelephense Language Server.
|
| 105 |
+
"""
|
| 106 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 107 |
+
initialize_params = {
|
| 108 |
+
"locale": "en",
|
| 109 |
+
"capabilities": {
|
| 110 |
+
"textDocument": {
|
| 111 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 112 |
+
"definition": {"dynamicRegistration": True},
|
| 113 |
+
},
|
| 114 |
+
"workspace": {"workspaceFolders": True, "didChangeConfiguration": {"dynamicRegistration": True}},
|
| 115 |
+
},
|
| 116 |
+
"processId": os.getpid(),
|
| 117 |
+
"rootPath": repository_absolute_path,
|
| 118 |
+
"rootUri": root_uri,
|
| 119 |
+
"workspaceFolders": [
|
| 120 |
+
{
|
| 121 |
+
"uri": root_uri,
|
| 122 |
+
"name": os.path.basename(repository_absolute_path),
|
| 123 |
+
}
|
| 124 |
+
],
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
# Add license key if provided via environment variable
|
| 128 |
+
license_key = os.environ.get("INTELEPHENSE_LICENSE_KEY")
|
| 129 |
+
if license_key:
|
| 130 |
+
initialize_params["initializationOptions"] = {"licenceKey": license_key}
|
| 131 |
+
|
| 132 |
+
return initialize_params
|
| 133 |
+
|
| 134 |
+
def _start_server(self):
|
| 135 |
+
"""Start Intelephense server process"""
|
| 136 |
+
|
| 137 |
+
def register_capability_handler(params):
|
| 138 |
+
return
|
| 139 |
+
|
| 140 |
+
def window_log_message(msg):
|
| 141 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 142 |
+
|
| 143 |
+
def do_nothing(params):
|
| 144 |
+
return
|
| 145 |
+
|
| 146 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 147 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 148 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 149 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 150 |
+
|
| 151 |
+
self.logger.log("Starting Intelephense server process", logging.INFO)
|
| 152 |
+
self.server.start()
|
| 153 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 154 |
+
|
| 155 |
+
self.logger.log(
|
| 156 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 157 |
+
logging.INFO,
|
| 158 |
+
)
|
| 159 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 160 |
+
self.logger.log(
|
| 161 |
+
"After sent initialize params",
|
| 162 |
+
logging.INFO,
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# Verify server capabilities
|
| 166 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 167 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 168 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 169 |
+
|
| 170 |
+
self.server.notify.initialized({})
|
| 171 |
+
self.completions_available.set()
|
| 172 |
+
|
| 173 |
+
# Intelephense server is typically ready immediately after initialization
|
| 174 |
+
# TODO: This is probably incorrect; the server does send an initialized notification, which we could wait for!
|
| 175 |
+
|
| 176 |
+
@override
|
| 177 |
+
# For some reason, the LS may need longer to process this, so we just retry
|
| 178 |
+
def _send_references_request(self, relative_file_path: str, line: int, column: int):
|
| 179 |
+
# TODO: The LS doesn't return references contained in other files if it doesn't sleep. This is
|
| 180 |
+
# despite the LS having processed requests already. I don't know what causes this, but sleeping
|
| 181 |
+
# one second helps. It may be that sleeping only once is enough but that's hard to reliably test.
|
| 182 |
+
# May be related to the time it takes to read the files or something like that.
|
| 183 |
+
# The sleeping doesn't seem to be needed on all systems
|
| 184 |
+
sleep(1)
|
| 185 |
+
return super()._send_references_request(relative_file_path, line, column)
|
| 186 |
+
|
| 187 |
+
@override
|
| 188 |
+
def _send_definition_request(self, definition_params: DefinitionParams):
|
| 189 |
+
# TODO: same as above, also only a problem if the definition is in another file
|
| 190 |
+
sleep(1)
|
| 191 |
+
return super()._send_definition_request(definition_params)
|
projects/ui/serena-new/src/solidlsp/language_servers/jedi_server.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
|
| 9 |
+
from overrides import override
|
| 10 |
+
|
| 11 |
+
from solidlsp.ls import SolidLanguageServer
|
| 12 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 13 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 14 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 15 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 16 |
+
from solidlsp.settings import SolidLSPSettings
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class JediServer(SolidLanguageServer):
|
| 20 |
+
"""
|
| 21 |
+
Provides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
def __init__(
|
| 25 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 26 |
+
):
|
| 27 |
+
"""
|
| 28 |
+
Creates a JediServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 29 |
+
"""
|
| 30 |
+
super().__init__(
|
| 31 |
+
config,
|
| 32 |
+
logger,
|
| 33 |
+
repository_root_path,
|
| 34 |
+
ProcessLaunchInfo(cmd="jedi-language-server", cwd=repository_root_path),
|
| 35 |
+
"python",
|
| 36 |
+
solidlsp_settings,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
@override
|
| 40 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 41 |
+
return super().is_ignored_dirname(dirname) or dirname in ["venv", "__pycache__"]
|
| 42 |
+
|
| 43 |
+
@staticmethod
|
| 44 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 45 |
+
"""
|
| 46 |
+
Returns the initialize params for the Jedi Language Server.
|
| 47 |
+
"""
|
| 48 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 49 |
+
initialize_params = {
|
| 50 |
+
"processId": os.getpid(),
|
| 51 |
+
"clientInfo": {"name": "Serena", "version": "0.1.0"},
|
| 52 |
+
"locale": "en",
|
| 53 |
+
"rootPath": repository_absolute_path,
|
| 54 |
+
"rootUri": root_uri,
|
| 55 |
+
# Note: this is not necessarily the minimal set of capabilities...
|
| 56 |
+
"capabilities": {
|
| 57 |
+
"workspace": {
|
| 58 |
+
"applyEdit": True,
|
| 59 |
+
"workspaceEdit": {
|
| 60 |
+
"documentChanges": True,
|
| 61 |
+
"resourceOperations": ["create", "rename", "delete"],
|
| 62 |
+
"failureHandling": "textOnlyTransactional",
|
| 63 |
+
"normalizesLineEndings": True,
|
| 64 |
+
"changeAnnotationSupport": {"groupsOnLabel": True},
|
| 65 |
+
},
|
| 66 |
+
"configuration": True,
|
| 67 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True, "relativePatternSupport": True},
|
| 68 |
+
"symbol": {
|
| 69 |
+
"dynamicRegistration": True,
|
| 70 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 71 |
+
"tagSupport": {"valueSet": [1]},
|
| 72 |
+
"resolveSupport": {"properties": ["location.range"]},
|
| 73 |
+
},
|
| 74 |
+
"workspaceFolders": True,
|
| 75 |
+
"fileOperations": {
|
| 76 |
+
"dynamicRegistration": True,
|
| 77 |
+
"didCreate": True,
|
| 78 |
+
"didRename": True,
|
| 79 |
+
"didDelete": True,
|
| 80 |
+
"willCreate": True,
|
| 81 |
+
"willRename": True,
|
| 82 |
+
"willDelete": True,
|
| 83 |
+
},
|
| 84 |
+
"inlineValue": {"refreshSupport": True},
|
| 85 |
+
"inlayHint": {"refreshSupport": True},
|
| 86 |
+
"diagnostics": {"refreshSupport": True},
|
| 87 |
+
},
|
| 88 |
+
"textDocument": {
|
| 89 |
+
"publishDiagnostics": {
|
| 90 |
+
"relatedInformation": True,
|
| 91 |
+
"versionSupport": False,
|
| 92 |
+
"tagSupport": {"valueSet": [1, 2]},
|
| 93 |
+
"codeDescriptionSupport": True,
|
| 94 |
+
"dataSupport": True,
|
| 95 |
+
},
|
| 96 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 97 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 98 |
+
"signatureHelp": {
|
| 99 |
+
"dynamicRegistration": True,
|
| 100 |
+
"signatureInformation": {
|
| 101 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 102 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 103 |
+
"activeParameterSupport": True,
|
| 104 |
+
},
|
| 105 |
+
"contextSupport": True,
|
| 106 |
+
},
|
| 107 |
+
"definition": {"dynamicRegistration": True, "linkSupport": True},
|
| 108 |
+
"references": {"dynamicRegistration": True},
|
| 109 |
+
"documentHighlight": {"dynamicRegistration": True},
|
| 110 |
+
"documentSymbol": {
|
| 111 |
+
"dynamicRegistration": True,
|
| 112 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 113 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 114 |
+
"tagSupport": {"valueSet": [1]},
|
| 115 |
+
"labelSupport": True,
|
| 116 |
+
},
|
| 117 |
+
"documentLink": {"dynamicRegistration": True, "tooltipSupport": True},
|
| 118 |
+
"typeDefinition": {"dynamicRegistration": True, "linkSupport": True},
|
| 119 |
+
"implementation": {"dynamicRegistration": True, "linkSupport": True},
|
| 120 |
+
"declaration": {"dynamicRegistration": True, "linkSupport": True},
|
| 121 |
+
"selectionRange": {"dynamicRegistration": True},
|
| 122 |
+
"callHierarchy": {"dynamicRegistration": True},
|
| 123 |
+
"linkedEditingRange": {"dynamicRegistration": True},
|
| 124 |
+
"typeHierarchy": {"dynamicRegistration": True},
|
| 125 |
+
"inlineValue": {"dynamicRegistration": True},
|
| 126 |
+
"inlayHint": {
|
| 127 |
+
"dynamicRegistration": True,
|
| 128 |
+
"resolveSupport": {"properties": ["tooltip", "textEdits", "label.tooltip", "label.location", "label.command"]},
|
| 129 |
+
},
|
| 130 |
+
"diagnostic": {"dynamicRegistration": True, "relatedDocumentSupport": False},
|
| 131 |
+
},
|
| 132 |
+
"notebookDocument": {"synchronization": {"dynamicRegistration": True, "executionSummarySupport": True}},
|
| 133 |
+
"experimental": {
|
| 134 |
+
"serverStatusNotification": True,
|
| 135 |
+
"openServerLogs": True,
|
| 136 |
+
},
|
| 137 |
+
},
|
| 138 |
+
# See https://github.com/pappasam/jedi-language-server?tab=readme-ov-file
|
| 139 |
+
# We use the default options except for maxSymbols, where 0 means no limit
|
| 140 |
+
"initializationOptions": {
|
| 141 |
+
"workspace": {
|
| 142 |
+
"symbols": {"ignoreFolders": [".nox", ".tox", ".venv", "__pycache__", "venv"], "maxSymbols": 0},
|
| 143 |
+
},
|
| 144 |
+
},
|
| 145 |
+
"trace": "verbose",
|
| 146 |
+
"workspaceFolders": [
|
| 147 |
+
{
|
| 148 |
+
"uri": root_uri,
|
| 149 |
+
"name": os.path.basename(repository_absolute_path),
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
}
|
| 153 |
+
return initialize_params
|
| 154 |
+
|
| 155 |
+
def _start_server(self):
|
| 156 |
+
"""
|
| 157 |
+
Starts the JEDI Language Server
|
| 158 |
+
"""
|
| 159 |
+
|
| 160 |
+
def execute_client_command_handler(params):
|
| 161 |
+
return []
|
| 162 |
+
|
| 163 |
+
def do_nothing(params):
|
| 164 |
+
return
|
| 165 |
+
|
| 166 |
+
def check_experimental_status(params):
|
| 167 |
+
if params["quiescent"] == True:
|
| 168 |
+
self.completions_available.set()
|
| 169 |
+
|
| 170 |
+
def window_log_message(msg):
|
| 171 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 172 |
+
|
| 173 |
+
self.server.on_request("client/registerCapability", do_nothing)
|
| 174 |
+
self.server.on_notification("language/status", do_nothing)
|
| 175 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 176 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 177 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 178 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 179 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 180 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 181 |
+
|
| 182 |
+
self.logger.log("Starting jedi-language-server server process", logging.INFO)
|
| 183 |
+
self.server.start()
|
| 184 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 185 |
+
|
| 186 |
+
self.logger.log(
|
| 187 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 188 |
+
logging.INFO,
|
| 189 |
+
)
|
| 190 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 191 |
+
assert init_response["capabilities"]["textDocumentSync"]["change"] == 2
|
| 192 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 193 |
+
assert init_response["capabilities"]["completionProvider"] == {
|
| 194 |
+
"triggerCharacters": [".", "'", '"'],
|
| 195 |
+
"resolveProvider": True,
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
self.server.notify.initialized({})
|
projects/ui/serena-new/src/solidlsp/language_servers/kotlin_language_server.py
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Kotlin specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Kotlin.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import dataclasses
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import stat
|
| 10 |
+
|
| 11 |
+
from solidlsp.ls import SolidLanguageServer
|
| 12 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 13 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 14 |
+
from solidlsp.ls_utils import FileUtils, PlatformUtils
|
| 15 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 16 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 17 |
+
from solidlsp.settings import SolidLSPSettings
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@dataclasses.dataclass
|
| 21 |
+
class KotlinRuntimeDependencyPaths:
|
| 22 |
+
"""
|
| 23 |
+
Stores the paths to the runtime dependencies of Kotlin Language Server
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
java_path: str
|
| 27 |
+
java_home_path: str
|
| 28 |
+
kotlin_executable_path: str
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class KotlinLanguageServer(SolidLanguageServer):
|
| 32 |
+
"""
|
| 33 |
+
Provides Kotlin specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Kotlin.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
def __init__(
|
| 37 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 38 |
+
):
|
| 39 |
+
"""
|
| 40 |
+
Creates a Kotlin Language Server instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 41 |
+
"""
|
| 42 |
+
runtime_dependency_paths = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 43 |
+
self.runtime_dependency_paths = runtime_dependency_paths
|
| 44 |
+
|
| 45 |
+
# Create command to execute the Kotlin Language Server script
|
| 46 |
+
cmd = [self.runtime_dependency_paths.kotlin_executable_path, "--stdio"]
|
| 47 |
+
|
| 48 |
+
# Set environment variables including JAVA_HOME
|
| 49 |
+
proc_env = {"JAVA_HOME": self.runtime_dependency_paths.java_home_path}
|
| 50 |
+
|
| 51 |
+
super().__init__(
|
| 52 |
+
config,
|
| 53 |
+
logger,
|
| 54 |
+
repository_root_path,
|
| 55 |
+
ProcessLaunchInfo(cmd=cmd, env=proc_env, cwd=repository_root_path),
|
| 56 |
+
"kotlin",
|
| 57 |
+
solidlsp_settings,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
@classmethod
|
| 61 |
+
def _setup_runtime_dependencies(
|
| 62 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 63 |
+
) -> KotlinRuntimeDependencyPaths:
|
| 64 |
+
"""
|
| 65 |
+
Setup runtime dependencies for Kotlin Language Server and return the paths.
|
| 66 |
+
"""
|
| 67 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 68 |
+
|
| 69 |
+
# Verify platform support
|
| 70 |
+
assert (
|
| 71 |
+
platform_id.value.startswith("win-") or platform_id.value.startswith("linux-") or platform_id.value.startswith("osx-")
|
| 72 |
+
), "Only Windows, Linux and macOS platforms are supported for Kotlin in multilspy at the moment"
|
| 73 |
+
|
| 74 |
+
# Runtime dependency information
|
| 75 |
+
runtime_dependencies = {
|
| 76 |
+
"runtimeDependency": {
|
| 77 |
+
"id": "KotlinLsp",
|
| 78 |
+
"description": "Kotlin Language Server",
|
| 79 |
+
"url": "https://download-cdn.jetbrains.com/kotlin-lsp/0.253.10629/kotlin-0.253.10629.zip",
|
| 80 |
+
"archiveType": "zip",
|
| 81 |
+
},
|
| 82 |
+
"java": {
|
| 83 |
+
"win-x64": {
|
| 84 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-win32-x64-1.42.0-561.vsix",
|
| 85 |
+
"archiveType": "zip",
|
| 86 |
+
"java_home_path": "extension/jre/21.0.7-win32-x86_64",
|
| 87 |
+
"java_path": "extension/jre/21.0.7-win32-x86_64/bin/java.exe",
|
| 88 |
+
},
|
| 89 |
+
"linux-x64": {
|
| 90 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-x64-1.42.0-561.vsix",
|
| 91 |
+
"archiveType": "zip",
|
| 92 |
+
"java_home_path": "extension/jre/21.0.7-linux-x86_64",
|
| 93 |
+
"java_path": "extension/jre/21.0.7-linux-x86_64/bin/java",
|
| 94 |
+
},
|
| 95 |
+
"linux-arm64": {
|
| 96 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-arm64-1.42.0-561.vsix",
|
| 97 |
+
"archiveType": "zip",
|
| 98 |
+
"java_home_path": "extension/jre/21.0.7-linux-aarch64",
|
| 99 |
+
"java_path": "extension/jre/21.0.7-linux-aarch64/bin/java",
|
| 100 |
+
},
|
| 101 |
+
"osx-x64": {
|
| 102 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-x64-1.42.0-561.vsix",
|
| 103 |
+
"archiveType": "zip",
|
| 104 |
+
"java_home_path": "extension/jre/21.0.7-macosx-x86_64",
|
| 105 |
+
"java_path": "extension/jre/21.0.7-macosx-x86_64/bin/java",
|
| 106 |
+
},
|
| 107 |
+
"osx-arm64": {
|
| 108 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix",
|
| 109 |
+
"archiveType": "zip",
|
| 110 |
+
"java_home_path": "extension/jre/21.0.7-macosx-aarch64",
|
| 111 |
+
"java_path": "extension/jre/21.0.7-macosx-aarch64/bin/java",
|
| 112 |
+
},
|
| 113 |
+
},
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
kotlin_dependency = runtime_dependencies["runtimeDependency"]
|
| 117 |
+
java_dependency = runtime_dependencies["java"][platform_id.value]
|
| 118 |
+
|
| 119 |
+
# Setup paths for dependencies
|
| 120 |
+
static_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "kotlin_language_server")
|
| 121 |
+
os.makedirs(static_dir, exist_ok=True)
|
| 122 |
+
|
| 123 |
+
# Setup Java paths
|
| 124 |
+
java_dir = os.path.join(static_dir, "java")
|
| 125 |
+
os.makedirs(java_dir, exist_ok=True)
|
| 126 |
+
|
| 127 |
+
java_home_path = os.path.join(java_dir, java_dependency["java_home_path"])
|
| 128 |
+
java_path = os.path.join(java_dir, java_dependency["java_path"])
|
| 129 |
+
|
| 130 |
+
# Download and extract Java if not exists
|
| 131 |
+
if not os.path.exists(java_path):
|
| 132 |
+
logger.log(f"Downloading Java for {platform_id.value}...", logging.INFO)
|
| 133 |
+
FileUtils.download_and_extract_archive(logger, java_dependency["url"], java_dir, java_dependency["archiveType"])
|
| 134 |
+
# Make Java executable
|
| 135 |
+
if not platform_id.value.startswith("win-"):
|
| 136 |
+
os.chmod(java_path, 0o755)
|
| 137 |
+
|
| 138 |
+
assert os.path.exists(java_path), f"Java executable not found at {java_path}"
|
| 139 |
+
|
| 140 |
+
# Setup Kotlin Language Server paths
|
| 141 |
+
kotlin_ls_dir = static_dir
|
| 142 |
+
|
| 143 |
+
# Get platform-specific executable script path
|
| 144 |
+
if platform_id.value.startswith("win-"):
|
| 145 |
+
kotlin_script = os.path.join(kotlin_ls_dir, "kotlin-lsp.cmd")
|
| 146 |
+
else:
|
| 147 |
+
kotlin_script = os.path.join(kotlin_ls_dir, "kotlin-lsp.sh")
|
| 148 |
+
|
| 149 |
+
# Download and extract Kotlin Language Server if script doesn't exist
|
| 150 |
+
if not os.path.exists(kotlin_script):
|
| 151 |
+
logger.log("Downloading Kotlin Language Server...", logging.INFO)
|
| 152 |
+
FileUtils.download_and_extract_archive(logger, kotlin_dependency["url"], static_dir, kotlin_dependency["archiveType"])
|
| 153 |
+
|
| 154 |
+
# Make script executable on Unix platforms
|
| 155 |
+
if os.path.exists(kotlin_script) and not platform_id.value.startswith("win-"):
|
| 156 |
+
os.chmod(
|
| 157 |
+
kotlin_script, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
# Use script file
|
| 161 |
+
if os.path.exists(kotlin_script):
|
| 162 |
+
kotlin_executable_path = kotlin_script
|
| 163 |
+
logger.log(f"Using Kotlin Language Server script at {kotlin_script}", logging.INFO)
|
| 164 |
+
else:
|
| 165 |
+
raise FileNotFoundError(f"Kotlin Language Server script not found at {kotlin_script}")
|
| 166 |
+
|
| 167 |
+
return KotlinRuntimeDependencyPaths(
|
| 168 |
+
java_path=java_path, java_home_path=java_home_path, kotlin_executable_path=kotlin_executable_path
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
@staticmethod
|
| 172 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 173 |
+
"""
|
| 174 |
+
Returns the initialize params for the Kotlin Language Server.
|
| 175 |
+
"""
|
| 176 |
+
if not os.path.isabs(repository_absolute_path):
|
| 177 |
+
repository_absolute_path = os.path.abspath(repository_absolute_path)
|
| 178 |
+
|
| 179 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 180 |
+
initialize_params = {
|
| 181 |
+
"clientInfo": {"name": "Multilspy Kotlin Client", "version": "1.0.0"},
|
| 182 |
+
"locale": "en",
|
| 183 |
+
"rootPath": repository_absolute_path,
|
| 184 |
+
"rootUri": root_uri,
|
| 185 |
+
"capabilities": {
|
| 186 |
+
"workspace": {
|
| 187 |
+
"applyEdit": True,
|
| 188 |
+
"workspaceEdit": {
|
| 189 |
+
"documentChanges": True,
|
| 190 |
+
"resourceOperations": ["create", "rename", "delete"],
|
| 191 |
+
"failureHandling": "textOnlyTransactional",
|
| 192 |
+
"normalizesLineEndings": True,
|
| 193 |
+
"changeAnnotationSupport": {"groupsOnLabel": True},
|
| 194 |
+
},
|
| 195 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 196 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True, "relativePatternSupport": True},
|
| 197 |
+
"symbol": {
|
| 198 |
+
"dynamicRegistration": True,
|
| 199 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 200 |
+
"tagSupport": {"valueSet": [1]},
|
| 201 |
+
"resolveSupport": {"properties": ["location.range"]},
|
| 202 |
+
},
|
| 203 |
+
"codeLens": {"refreshSupport": True},
|
| 204 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 205 |
+
"configuration": True,
|
| 206 |
+
"workspaceFolders": True,
|
| 207 |
+
"semanticTokens": {"refreshSupport": True},
|
| 208 |
+
"fileOperations": {
|
| 209 |
+
"dynamicRegistration": True,
|
| 210 |
+
"didCreate": True,
|
| 211 |
+
"didRename": True,
|
| 212 |
+
"didDelete": True,
|
| 213 |
+
"willCreate": True,
|
| 214 |
+
"willRename": True,
|
| 215 |
+
"willDelete": True,
|
| 216 |
+
},
|
| 217 |
+
"inlineValue": {"refreshSupport": True},
|
| 218 |
+
"inlayHint": {"refreshSupport": True},
|
| 219 |
+
"diagnostics": {"refreshSupport": True},
|
| 220 |
+
},
|
| 221 |
+
"textDocument": {
|
| 222 |
+
"publishDiagnostics": {
|
| 223 |
+
"relatedInformation": True,
|
| 224 |
+
"versionSupport": False,
|
| 225 |
+
"tagSupport": {"valueSet": [1, 2]},
|
| 226 |
+
"codeDescriptionSupport": True,
|
| 227 |
+
"dataSupport": True,
|
| 228 |
+
},
|
| 229 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 230 |
+
"completion": {
|
| 231 |
+
"dynamicRegistration": True,
|
| 232 |
+
"contextSupport": True,
|
| 233 |
+
"completionItem": {
|
| 234 |
+
"snippetSupport": False,
|
| 235 |
+
"commitCharactersSupport": True,
|
| 236 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 237 |
+
"deprecatedSupport": True,
|
| 238 |
+
"preselectSupport": True,
|
| 239 |
+
"tagSupport": {"valueSet": [1]},
|
| 240 |
+
"insertReplaceSupport": False,
|
| 241 |
+
"resolveSupport": {"properties": ["documentation", "detail", "additionalTextEdits"]},
|
| 242 |
+
"insertTextModeSupport": {"valueSet": [1, 2]},
|
| 243 |
+
"labelDetailsSupport": True,
|
| 244 |
+
},
|
| 245 |
+
"insertTextMode": 2,
|
| 246 |
+
"completionItemKind": {
|
| 247 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
| 248 |
+
},
|
| 249 |
+
"completionList": {"itemDefaults": ["commitCharacters", "editRange", "insertTextFormat", "insertTextMode"]},
|
| 250 |
+
},
|
| 251 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 252 |
+
"signatureHelp": {
|
| 253 |
+
"dynamicRegistration": True,
|
| 254 |
+
"signatureInformation": {
|
| 255 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 256 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 257 |
+
"activeParameterSupport": True,
|
| 258 |
+
},
|
| 259 |
+
"contextSupport": True,
|
| 260 |
+
},
|
| 261 |
+
"definition": {"dynamicRegistration": True, "linkSupport": True},
|
| 262 |
+
"references": {"dynamicRegistration": True},
|
| 263 |
+
"documentHighlight": {"dynamicRegistration": True},
|
| 264 |
+
"documentSymbol": {
|
| 265 |
+
"dynamicRegistration": True,
|
| 266 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 267 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 268 |
+
"tagSupport": {"valueSet": [1]},
|
| 269 |
+
"labelSupport": True,
|
| 270 |
+
},
|
| 271 |
+
"codeAction": {
|
| 272 |
+
"dynamicRegistration": True,
|
| 273 |
+
"isPreferredSupport": True,
|
| 274 |
+
"disabledSupport": True,
|
| 275 |
+
"dataSupport": True,
|
| 276 |
+
"resolveSupport": {"properties": ["edit"]},
|
| 277 |
+
"codeActionLiteralSupport": {
|
| 278 |
+
"codeActionKind": {
|
| 279 |
+
"valueSet": [
|
| 280 |
+
"",
|
| 281 |
+
"quickfix",
|
| 282 |
+
"refactor",
|
| 283 |
+
"refactor.extract",
|
| 284 |
+
"refactor.inline",
|
| 285 |
+
"refactor.rewrite",
|
| 286 |
+
"source",
|
| 287 |
+
"source.organizeImports",
|
| 288 |
+
]
|
| 289 |
+
}
|
| 290 |
+
},
|
| 291 |
+
"honorsChangeAnnotations": False,
|
| 292 |
+
},
|
| 293 |
+
"codeLens": {"dynamicRegistration": True},
|
| 294 |
+
"formatting": {"dynamicRegistration": True},
|
| 295 |
+
"rangeFormatting": {"dynamicRegistration": True},
|
| 296 |
+
"onTypeFormatting": {"dynamicRegistration": True},
|
| 297 |
+
"rename": {
|
| 298 |
+
"dynamicRegistration": True,
|
| 299 |
+
"prepareSupport": True,
|
| 300 |
+
"prepareSupportDefaultBehavior": 1,
|
| 301 |
+
"honorsChangeAnnotations": True,
|
| 302 |
+
},
|
| 303 |
+
"documentLink": {"dynamicRegistration": True, "tooltipSupport": True},
|
| 304 |
+
"typeDefinition": {"dynamicRegistration": True, "linkSupport": True},
|
| 305 |
+
"implementation": {"dynamicRegistration": True, "linkSupport": True},
|
| 306 |
+
"colorProvider": {"dynamicRegistration": True},
|
| 307 |
+
"foldingRange": {
|
| 308 |
+
"dynamicRegistration": True,
|
| 309 |
+
"rangeLimit": 5000,
|
| 310 |
+
"lineFoldingOnly": True,
|
| 311 |
+
"foldingRangeKind": {"valueSet": ["comment", "imports", "region"]},
|
| 312 |
+
"foldingRange": {"collapsedText": False},
|
| 313 |
+
},
|
| 314 |
+
"declaration": {"dynamicRegistration": True, "linkSupport": True},
|
| 315 |
+
"selectionRange": {"dynamicRegistration": True},
|
| 316 |
+
"callHierarchy": {"dynamicRegistration": True},
|
| 317 |
+
"semanticTokens": {
|
| 318 |
+
"dynamicRegistration": True,
|
| 319 |
+
"tokenTypes": [
|
| 320 |
+
"namespace",
|
| 321 |
+
"type",
|
| 322 |
+
"class",
|
| 323 |
+
"enum",
|
| 324 |
+
"interface",
|
| 325 |
+
"struct",
|
| 326 |
+
"typeParameter",
|
| 327 |
+
"parameter",
|
| 328 |
+
"variable",
|
| 329 |
+
"property",
|
| 330 |
+
"enumMember",
|
| 331 |
+
"event",
|
| 332 |
+
"function",
|
| 333 |
+
"method",
|
| 334 |
+
"macro",
|
| 335 |
+
"keyword",
|
| 336 |
+
"modifier",
|
| 337 |
+
"comment",
|
| 338 |
+
"string",
|
| 339 |
+
"number",
|
| 340 |
+
"regexp",
|
| 341 |
+
"operator",
|
| 342 |
+
"decorator",
|
| 343 |
+
],
|
| 344 |
+
"tokenModifiers": [
|
| 345 |
+
"declaration",
|
| 346 |
+
"definition",
|
| 347 |
+
"readonly",
|
| 348 |
+
"static",
|
| 349 |
+
"deprecated",
|
| 350 |
+
"abstract",
|
| 351 |
+
"async",
|
| 352 |
+
"modification",
|
| 353 |
+
"documentation",
|
| 354 |
+
"defaultLibrary",
|
| 355 |
+
],
|
| 356 |
+
"formats": ["relative"],
|
| 357 |
+
"requests": {"range": True, "full": {"delta": True}},
|
| 358 |
+
"multilineTokenSupport": False,
|
| 359 |
+
"overlappingTokenSupport": False,
|
| 360 |
+
"serverCancelSupport": True,
|
| 361 |
+
"augmentsSyntaxTokens": True,
|
| 362 |
+
},
|
| 363 |
+
"linkedEditingRange": {"dynamicRegistration": True},
|
| 364 |
+
"typeHierarchy": {"dynamicRegistration": True},
|
| 365 |
+
"inlineValue": {"dynamicRegistration": True},
|
| 366 |
+
"inlayHint": {
|
| 367 |
+
"dynamicRegistration": True,
|
| 368 |
+
"resolveSupport": {"properties": ["tooltip", "textEdits", "label.tooltip", "label.location", "label.command"]},
|
| 369 |
+
},
|
| 370 |
+
"diagnostic": {"dynamicRegistration": True, "relatedDocumentSupport": False},
|
| 371 |
+
},
|
| 372 |
+
"window": {
|
| 373 |
+
"showMessage": {"messageActionItem": {"additionalPropertiesSupport": True}},
|
| 374 |
+
"showDocument": {"support": True},
|
| 375 |
+
"workDoneProgress": True,
|
| 376 |
+
},
|
| 377 |
+
"general": {
|
| 378 |
+
"staleRequestSupport": {
|
| 379 |
+
"cancel": True,
|
| 380 |
+
"retryOnContentModified": [
|
| 381 |
+
"textDocument/semanticTokens/full",
|
| 382 |
+
"textDocument/semanticTokens/range",
|
| 383 |
+
"textDocument/semanticTokens/full/delta",
|
| 384 |
+
],
|
| 385 |
+
},
|
| 386 |
+
"regularExpressions": {"engine": "ECMAScript", "version": "ES2020"},
|
| 387 |
+
"markdown": {"parser": "marked", "version": "1.1.0"},
|
| 388 |
+
"positionEncodings": ["utf-16"],
|
| 389 |
+
},
|
| 390 |
+
"notebookDocument": {"synchronization": {"dynamicRegistration": True, "executionSummarySupport": True}},
|
| 391 |
+
},
|
| 392 |
+
"initializationOptions": {
|
| 393 |
+
"workspaceFolders": [root_uri],
|
| 394 |
+
"storagePath": None,
|
| 395 |
+
"codegen": {"enabled": False},
|
| 396 |
+
"compiler": {"jvm": {"target": "default"}},
|
| 397 |
+
"completion": {"snippets": {"enabled": True}},
|
| 398 |
+
"diagnostics": {"enabled": True, "level": 4, "debounceTime": 250},
|
| 399 |
+
"scripts": {"enabled": True, "buildScriptsEnabled": True},
|
| 400 |
+
"indexing": {"enabled": True},
|
| 401 |
+
"externalSources": {"useKlsScheme": False, "autoConvertToKotlin": False},
|
| 402 |
+
"inlayHints": {"typeHints": False, "parameterHints": False, "chainedHints": False},
|
| 403 |
+
"formatting": {
|
| 404 |
+
"formatter": "ktfmt",
|
| 405 |
+
"ktfmt": {
|
| 406 |
+
"style": "google",
|
| 407 |
+
"indent": 4,
|
| 408 |
+
"maxWidth": 100,
|
| 409 |
+
"continuationIndent": 8,
|
| 410 |
+
"removeUnusedImports": True,
|
| 411 |
+
},
|
| 412 |
+
},
|
| 413 |
+
},
|
| 414 |
+
"trace": "verbose",
|
| 415 |
+
"processId": os.getpid(),
|
| 416 |
+
"workspaceFolders": [
|
| 417 |
+
{
|
| 418 |
+
"uri": root_uri,
|
| 419 |
+
"name": os.path.basename(repository_absolute_path),
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
}
|
| 423 |
+
return initialize_params
|
| 424 |
+
|
| 425 |
+
def _start_server(self):
|
| 426 |
+
"""
|
| 427 |
+
Starts the Kotlin Language Server
|
| 428 |
+
"""
|
| 429 |
+
|
| 430 |
+
def execute_client_command_handler(params):
|
| 431 |
+
return []
|
| 432 |
+
|
| 433 |
+
def do_nothing(params):
|
| 434 |
+
return
|
| 435 |
+
|
| 436 |
+
def window_log_message(msg):
|
| 437 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 438 |
+
|
| 439 |
+
self.server.on_request("client/registerCapability", do_nothing)
|
| 440 |
+
self.server.on_notification("language/status", do_nothing)
|
| 441 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 442 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 443 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 444 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 445 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 446 |
+
|
| 447 |
+
self.logger.log("Starting Kotlin server process", logging.INFO)
|
| 448 |
+
self.server.start()
|
| 449 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 450 |
+
|
| 451 |
+
self.logger.log(
|
| 452 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 453 |
+
logging.INFO,
|
| 454 |
+
)
|
| 455 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 456 |
+
|
| 457 |
+
capabilities = init_response["capabilities"]
|
| 458 |
+
assert "textDocumentSync" in capabilities, "Server must support textDocumentSync"
|
| 459 |
+
assert "hoverProvider" in capabilities, "Server must support hover"
|
| 460 |
+
assert "completionProvider" in capabilities, "Server must support code completion"
|
| 461 |
+
assert "signatureHelpProvider" in capabilities, "Server must support signature help"
|
| 462 |
+
assert "definitionProvider" in capabilities, "Server must support go to definition"
|
| 463 |
+
assert "referencesProvider" in capabilities, "Server must support find references"
|
| 464 |
+
assert "documentSymbolProvider" in capabilities, "Server must support document symbols"
|
| 465 |
+
assert "workspaceSymbolProvider" in capabilities, "Server must support workspace symbols"
|
| 466 |
+
assert "semanticTokensProvider" in capabilities, "Server must support semantic tokens"
|
| 467 |
+
|
| 468 |
+
self.server.notify.initialized({})
|
| 469 |
+
self.completions_available.set()
|
projects/ui/serena-new/src/solidlsp/language_servers/lua_ls.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Lua specific instantiation of the LanguageServer class using lua-language-server.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import platform
|
| 9 |
+
import shutil
|
| 10 |
+
import tarfile
|
| 11 |
+
import threading
|
| 12 |
+
import zipfile
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
import requests
|
| 16 |
+
from overrides import override
|
| 17 |
+
|
| 18 |
+
from solidlsp.ls import SolidLanguageServer
|
| 19 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 20 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 21 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 22 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 23 |
+
from solidlsp.settings import SolidLSPSettings
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class LuaLanguageServer(SolidLanguageServer):
|
| 27 |
+
"""
|
| 28 |
+
Provides Lua specific instantiation of the LanguageServer class using lua-language-server.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
@override
|
| 32 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 33 |
+
# For Lua projects, we should ignore:
|
| 34 |
+
# - .luarocks: package manager cache
|
| 35 |
+
# - lua_modules: local dependencies
|
| 36 |
+
# - node_modules: if the project has JavaScript components
|
| 37 |
+
return super().is_ignored_dirname(dirname) or dirname in [".luarocks", "lua_modules", "node_modules", "build", "dist", ".cache"]
|
| 38 |
+
|
| 39 |
+
@staticmethod
|
| 40 |
+
def _get_lua_ls_path():
|
| 41 |
+
"""Get the path to lua-language-server executable."""
|
| 42 |
+
# First check if it's in PATH
|
| 43 |
+
lua_ls = shutil.which("lua-language-server")
|
| 44 |
+
if lua_ls:
|
| 45 |
+
return lua_ls
|
| 46 |
+
|
| 47 |
+
# Check common installation locations
|
| 48 |
+
home = Path.home()
|
| 49 |
+
possible_paths = [
|
| 50 |
+
home / ".local" / "bin" / "lua-language-server",
|
| 51 |
+
home / ".serena" / "language_servers" / "lua" / "bin" / "lua-language-server",
|
| 52 |
+
Path("/usr/local/bin/lua-language-server"),
|
| 53 |
+
Path("/opt/lua-language-server/bin/lua-language-server"),
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
# Add Windows-specific paths
|
| 57 |
+
if platform.system() == "Windows":
|
| 58 |
+
possible_paths.extend(
|
| 59 |
+
[
|
| 60 |
+
home / "AppData" / "Local" / "lua-language-server" / "bin" / "lua-language-server.exe",
|
| 61 |
+
home / ".serena" / "language_servers" / "lua" / "bin" / "lua-language-server.exe",
|
| 62 |
+
]
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
for path in possible_paths:
|
| 66 |
+
if path.exists():
|
| 67 |
+
return str(path)
|
| 68 |
+
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def _download_lua_ls():
|
| 73 |
+
"""Download and install lua-language-server if not present."""
|
| 74 |
+
system = platform.system()
|
| 75 |
+
machine = platform.machine().lower()
|
| 76 |
+
lua_ls_version = "3.15.0"
|
| 77 |
+
|
| 78 |
+
# Map platform and architecture to download URL
|
| 79 |
+
if system == "Linux":
|
| 80 |
+
if machine in ["x86_64", "amd64"]:
|
| 81 |
+
download_name = f"lua-language-server-{lua_ls_version}-linux-x64.tar.gz"
|
| 82 |
+
elif machine in ["aarch64", "arm64"]:
|
| 83 |
+
download_name = f"lua-language-server-{lua_ls_version}-linux-arm64.tar.gz"
|
| 84 |
+
else:
|
| 85 |
+
raise RuntimeError(f"Unsupported Linux architecture: {machine}")
|
| 86 |
+
elif system == "Darwin":
|
| 87 |
+
if machine in ["x86_64", "amd64"]:
|
| 88 |
+
download_name = f"lua-language-server-{lua_ls_version}-darwin-x64.tar.gz"
|
| 89 |
+
elif machine in ["arm64", "aarch64"]:
|
| 90 |
+
download_name = f"lua-language-server-{lua_ls_version}-darwin-arm64.tar.gz"
|
| 91 |
+
else:
|
| 92 |
+
raise RuntimeError(f"Unsupported macOS architecture: {machine}")
|
| 93 |
+
elif system == "Windows":
|
| 94 |
+
if machine in ["amd64", "x86_64"]:
|
| 95 |
+
download_name = f"lua-language-server-{lua_ls_version}-win32-x64.zip"
|
| 96 |
+
else:
|
| 97 |
+
raise RuntimeError(f"Unsupported Windows architecture: {machine}")
|
| 98 |
+
else:
|
| 99 |
+
raise RuntimeError(f"Unsupported operating system: {system}")
|
| 100 |
+
|
| 101 |
+
download_url = f"https://github.com/LuaLS/lua-language-server/releases/download/{lua_ls_version}/{download_name}"
|
| 102 |
+
|
| 103 |
+
# Create installation directory
|
| 104 |
+
install_dir = Path.home() / ".serena" / "language_servers" / "lua"
|
| 105 |
+
install_dir.mkdir(parents=True, exist_ok=True)
|
| 106 |
+
|
| 107 |
+
# Download the file
|
| 108 |
+
print(f"Downloading lua-language-server from {download_url}...")
|
| 109 |
+
response = requests.get(download_url, stream=True)
|
| 110 |
+
response.raise_for_status()
|
| 111 |
+
|
| 112 |
+
# Save and extract
|
| 113 |
+
download_path = install_dir / download_name
|
| 114 |
+
with open(download_path, "wb") as f:
|
| 115 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 116 |
+
f.write(chunk)
|
| 117 |
+
|
| 118 |
+
print(f"Extracting lua-language-server to {install_dir}...")
|
| 119 |
+
if download_name.endswith(".tar.gz"):
|
| 120 |
+
with tarfile.open(download_path, "r:gz") as tar:
|
| 121 |
+
tar.extractall(install_dir)
|
| 122 |
+
elif download_name.endswith(".zip"):
|
| 123 |
+
with zipfile.ZipFile(download_path, "r") as zip_ref:
|
| 124 |
+
zip_ref.extractall(install_dir)
|
| 125 |
+
|
| 126 |
+
# Clean up download file
|
| 127 |
+
download_path.unlink()
|
| 128 |
+
|
| 129 |
+
# Make executable on Unix systems
|
| 130 |
+
if system != "Windows":
|
| 131 |
+
lua_ls_path = install_dir / "bin" / "lua-language-server"
|
| 132 |
+
if lua_ls_path.exists():
|
| 133 |
+
lua_ls_path.chmod(0o755)
|
| 134 |
+
return str(lua_ls_path)
|
| 135 |
+
else:
|
| 136 |
+
lua_ls_path = install_dir / "bin" / "lua-language-server.exe"
|
| 137 |
+
if lua_ls_path.exists():
|
| 138 |
+
return str(lua_ls_path)
|
| 139 |
+
|
| 140 |
+
raise RuntimeError("Failed to find lua-language-server executable after extraction")
|
| 141 |
+
|
| 142 |
+
@staticmethod
|
| 143 |
+
def _setup_runtime_dependency():
|
| 144 |
+
"""
|
| 145 |
+
Check if required Lua runtime dependencies are available.
|
| 146 |
+
Downloads lua-language-server if not present.
|
| 147 |
+
"""
|
| 148 |
+
lua_ls_path = LuaLanguageServer._get_lua_ls_path()
|
| 149 |
+
|
| 150 |
+
if not lua_ls_path:
|
| 151 |
+
print("lua-language-server not found. Downloading...")
|
| 152 |
+
lua_ls_path = LuaLanguageServer._download_lua_ls()
|
| 153 |
+
print(f"lua-language-server installed at: {lua_ls_path}")
|
| 154 |
+
|
| 155 |
+
return lua_ls_path
|
| 156 |
+
|
| 157 |
+
def __init__(
|
| 158 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 159 |
+
):
|
| 160 |
+
lua_ls_path = self._setup_runtime_dependency()
|
| 161 |
+
|
| 162 |
+
super().__init__(
|
| 163 |
+
config,
|
| 164 |
+
logger,
|
| 165 |
+
repository_root_path,
|
| 166 |
+
ProcessLaunchInfo(cmd=lua_ls_path, cwd=repository_root_path),
|
| 167 |
+
"lua",
|
| 168 |
+
solidlsp_settings,
|
| 169 |
+
)
|
| 170 |
+
self.server_ready = threading.Event()
|
| 171 |
+
self.request_id = 0
|
| 172 |
+
|
| 173 |
+
@staticmethod
|
| 174 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 175 |
+
"""
|
| 176 |
+
Returns the initialize params for the Lua Language Server.
|
| 177 |
+
"""
|
| 178 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 179 |
+
initialize_params = {
|
| 180 |
+
"locale": "en",
|
| 181 |
+
"capabilities": {
|
| 182 |
+
"textDocument": {
|
| 183 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 184 |
+
"definition": {"dynamicRegistration": True},
|
| 185 |
+
"references": {"dynamicRegistration": True},
|
| 186 |
+
"documentSymbol": {
|
| 187 |
+
"dynamicRegistration": True,
|
| 188 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 189 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 190 |
+
},
|
| 191 |
+
"completion": {
|
| 192 |
+
"dynamicRegistration": True,
|
| 193 |
+
"completionItem": {
|
| 194 |
+
"snippetSupport": True,
|
| 195 |
+
"commitCharactersSupport": True,
|
| 196 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 197 |
+
"deprecatedSupport": True,
|
| 198 |
+
"preselectSupport": True,
|
| 199 |
+
},
|
| 200 |
+
},
|
| 201 |
+
"hover": {
|
| 202 |
+
"dynamicRegistration": True,
|
| 203 |
+
"contentFormat": ["markdown", "plaintext"],
|
| 204 |
+
},
|
| 205 |
+
"signatureHelp": {
|
| 206 |
+
"dynamicRegistration": True,
|
| 207 |
+
"signatureInformation": {
|
| 208 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 209 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 210 |
+
},
|
| 211 |
+
},
|
| 212 |
+
},
|
| 213 |
+
"workspace": {
|
| 214 |
+
"workspaceFolders": True,
|
| 215 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 216 |
+
"configuration": True,
|
| 217 |
+
"symbol": {
|
| 218 |
+
"dynamicRegistration": True,
|
| 219 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 220 |
+
},
|
| 221 |
+
},
|
| 222 |
+
},
|
| 223 |
+
"processId": os.getpid(),
|
| 224 |
+
"rootPath": repository_absolute_path,
|
| 225 |
+
"rootUri": root_uri,
|
| 226 |
+
"workspaceFolders": [
|
| 227 |
+
{
|
| 228 |
+
"uri": root_uri,
|
| 229 |
+
"name": os.path.basename(repository_absolute_path),
|
| 230 |
+
}
|
| 231 |
+
],
|
| 232 |
+
"initializationOptions": {
|
| 233 |
+
# Lua Language Server specific options
|
| 234 |
+
"runtime": {
|
| 235 |
+
"version": "Lua 5.4",
|
| 236 |
+
"path": ["?.lua", "?/init.lua"],
|
| 237 |
+
},
|
| 238 |
+
"diagnostics": {
|
| 239 |
+
"enable": True,
|
| 240 |
+
"globals": ["vim", "describe", "it", "before_each", "after_each"], # Common globals
|
| 241 |
+
},
|
| 242 |
+
"workspace": {
|
| 243 |
+
"library": [], # Can be extended with project-specific libraries
|
| 244 |
+
"checkThirdParty": False,
|
| 245 |
+
"userThirdParty": [],
|
| 246 |
+
},
|
| 247 |
+
"telemetry": {
|
| 248 |
+
"enable": False,
|
| 249 |
+
},
|
| 250 |
+
"completion": {
|
| 251 |
+
"enable": True,
|
| 252 |
+
"callSnippet": "Both",
|
| 253 |
+
"keywordSnippet": "Both",
|
| 254 |
+
},
|
| 255 |
+
},
|
| 256 |
+
}
|
| 257 |
+
return initialize_params
|
| 258 |
+
|
| 259 |
+
def _start_server(self):
|
| 260 |
+
"""Start Lua Language Server process"""
|
| 261 |
+
|
| 262 |
+
def register_capability_handler(params):
|
| 263 |
+
return
|
| 264 |
+
|
| 265 |
+
def window_log_message(msg):
|
| 266 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 267 |
+
|
| 268 |
+
def do_nothing(params):
|
| 269 |
+
return
|
| 270 |
+
|
| 271 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 272 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 273 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 274 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 275 |
+
|
| 276 |
+
self.logger.log("Starting Lua Language Server process", logging.INFO)
|
| 277 |
+
self.server.start()
|
| 278 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 279 |
+
|
| 280 |
+
self.logger.log(
|
| 281 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 282 |
+
logging.INFO,
|
| 283 |
+
)
|
| 284 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 285 |
+
|
| 286 |
+
# Verify server capabilities
|
| 287 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 288 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 289 |
+
assert "documentSymbolProvider" in init_response["capabilities"]
|
| 290 |
+
assert "referencesProvider" in init_response["capabilities"]
|
| 291 |
+
|
| 292 |
+
self.server.notify.initialized({})
|
| 293 |
+
self.completions_available.set()
|
| 294 |
+
|
| 295 |
+
# Lua Language Server is typically ready immediately after initialization
|
| 296 |
+
self.server_ready.set()
|
| 297 |
+
self.server_ready.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/nixd_ls.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Server class using nixd (Nix Language Server).
|
| 3 |
+
|
| 4 |
+
Note: Windows is not supported as Nix itself doesn't support Windows natively.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import pathlib
|
| 10 |
+
import platform
|
| 11 |
+
import shutil
|
| 12 |
+
import subprocess
|
| 13 |
+
import threading
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
from overrides import override
|
| 17 |
+
|
| 18 |
+
from solidlsp import ls_types
|
| 19 |
+
from solidlsp.ls import SolidLanguageServer
|
| 20 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 21 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 22 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 23 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 24 |
+
from solidlsp.settings import SolidLSPSettings
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class NixLanguageServer(SolidLanguageServer):
|
| 28 |
+
"""
|
| 29 |
+
Provides Nix specific instantiation of the LanguageServer class using nixd.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def _extend_nix_symbol_range_to_include_semicolon(
|
| 33 |
+
self, symbol: ls_types.UnifiedSymbolInformation, file_content: str
|
| 34 |
+
) -> ls_types.UnifiedSymbolInformation:
|
| 35 |
+
"""
|
| 36 |
+
Extend symbol range to include trailing semicolon for Nix attribute symbols.
|
| 37 |
+
|
| 38 |
+
nixd provides ranges that exclude semicolons (expression-level), but serena needs
|
| 39 |
+
statement-level ranges that include semicolons for proper replacement.
|
| 40 |
+
"""
|
| 41 |
+
range_info = symbol["range"]
|
| 42 |
+
end_line = range_info["end"]["line"]
|
| 43 |
+
end_char = range_info["end"]["character"]
|
| 44 |
+
|
| 45 |
+
# Split file content into lines
|
| 46 |
+
lines = file_content.split("\n")
|
| 47 |
+
if end_line >= len(lines):
|
| 48 |
+
return symbol
|
| 49 |
+
|
| 50 |
+
line = lines[end_line]
|
| 51 |
+
|
| 52 |
+
# Check if there's a semicolon immediately after the current range end
|
| 53 |
+
if end_char < len(line) and line[end_char] == ";":
|
| 54 |
+
# Extend range to include the semicolon
|
| 55 |
+
new_range = {"start": range_info["start"], "end": {"line": end_line, "character": end_char + 1}}
|
| 56 |
+
|
| 57 |
+
# Create modified symbol with extended range
|
| 58 |
+
extended_symbol = symbol.copy()
|
| 59 |
+
extended_symbol["range"] = new_range
|
| 60 |
+
|
| 61 |
+
# CRITICAL: Also update the location.range if it exists
|
| 62 |
+
if extended_symbol.get("location"):
|
| 63 |
+
location = extended_symbol["location"].copy()
|
| 64 |
+
if "range" in location:
|
| 65 |
+
location["range"] = new_range.copy()
|
| 66 |
+
extended_symbol["location"] = location
|
| 67 |
+
|
| 68 |
+
return extended_symbol
|
| 69 |
+
|
| 70 |
+
return symbol
|
| 71 |
+
|
| 72 |
+
@override
|
| 73 |
+
def request_document_symbols(
|
| 74 |
+
self, relative_file_path: str, include_body: bool = False
|
| 75 |
+
) -> tuple[list[ls_types.UnifiedSymbolInformation], list[ls_types.UnifiedSymbolInformation]]:
|
| 76 |
+
"""
|
| 77 |
+
Override to extend Nix symbol ranges to include trailing semicolons.
|
| 78 |
+
|
| 79 |
+
nixd provides expression-level ranges (excluding semicolons) but serena needs
|
| 80 |
+
statement-level ranges (including semicolons) for proper symbol replacement.
|
| 81 |
+
"""
|
| 82 |
+
# Get symbols from parent implementation
|
| 83 |
+
all_symbols, root_symbols = super().request_document_symbols(relative_file_path, include_body)
|
| 84 |
+
|
| 85 |
+
# Get file content for range extension
|
| 86 |
+
file_content = self.language_server.retrieve_full_file_content(relative_file_path)
|
| 87 |
+
|
| 88 |
+
# Extend ranges for all symbols recursively
|
| 89 |
+
def extend_symbol_and_children(symbol: ls_types.UnifiedSymbolInformation) -> ls_types.UnifiedSymbolInformation:
|
| 90 |
+
# Extend this symbol's range
|
| 91 |
+
extended = self._extend_nix_symbol_range_to_include_semicolon(symbol, file_content)
|
| 92 |
+
|
| 93 |
+
# Extend children recursively
|
| 94 |
+
if extended.get("children"):
|
| 95 |
+
extended["children"] = [extend_symbol_and_children(child) for child in extended["children"]]
|
| 96 |
+
|
| 97 |
+
return extended
|
| 98 |
+
|
| 99 |
+
# Apply range extension to all symbols
|
| 100 |
+
extended_all_symbols = [extend_symbol_and_children(sym) for sym in all_symbols]
|
| 101 |
+
extended_root_symbols = [extend_symbol_and_children(sym) for sym in root_symbols]
|
| 102 |
+
|
| 103 |
+
return extended_all_symbols, extended_root_symbols
|
| 104 |
+
|
| 105 |
+
@override
|
| 106 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 107 |
+
# For Nix projects, we should ignore:
|
| 108 |
+
# - result: nix build output symlinks
|
| 109 |
+
# - result-*: multiple build outputs
|
| 110 |
+
# - .direnv: direnv cache
|
| 111 |
+
return super().is_ignored_dirname(dirname) or dirname in ["result", ".direnv"] or dirname.startswith("result-")
|
| 112 |
+
|
| 113 |
+
@staticmethod
|
| 114 |
+
def _get_nixd_version():
|
| 115 |
+
"""Get the installed nixd version or None if not found."""
|
| 116 |
+
try:
|
| 117 |
+
result = subprocess.run(["nixd", "--version"], capture_output=True, text=True, check=False)
|
| 118 |
+
if result.returncode == 0:
|
| 119 |
+
# nixd outputs version like: nixd 2.0.0
|
| 120 |
+
return result.stdout.strip()
|
| 121 |
+
except FileNotFoundError:
|
| 122 |
+
return None
|
| 123 |
+
return None
|
| 124 |
+
|
| 125 |
+
@staticmethod
|
| 126 |
+
def _check_nixd_installed():
|
| 127 |
+
"""Check if nixd is installed in the system."""
|
| 128 |
+
return shutil.which("nixd") is not None
|
| 129 |
+
|
| 130 |
+
@staticmethod
|
| 131 |
+
def _get_nixd_path():
|
| 132 |
+
"""Get the path to nixd executable."""
|
| 133 |
+
# First check if it's in PATH
|
| 134 |
+
nixd_path = shutil.which("nixd")
|
| 135 |
+
if nixd_path:
|
| 136 |
+
return nixd_path
|
| 137 |
+
|
| 138 |
+
# Check common installation locations
|
| 139 |
+
home = Path.home()
|
| 140 |
+
possible_paths = [
|
| 141 |
+
home / ".local" / "bin" / "nixd",
|
| 142 |
+
home / ".serena" / "language_servers" / "nixd" / "nixd",
|
| 143 |
+
home / ".nix-profile" / "bin" / "nixd",
|
| 144 |
+
Path("/usr/local/bin/nixd"),
|
| 145 |
+
Path("/run/current-system/sw/bin/nixd"), # NixOS system profile
|
| 146 |
+
Path("/opt/homebrew/bin/nixd"), # Homebrew on Apple Silicon
|
| 147 |
+
Path("/usr/local/opt/nixd/bin/nixd"), # Homebrew on Intel Mac
|
| 148 |
+
]
|
| 149 |
+
|
| 150 |
+
# Add Windows-specific paths
|
| 151 |
+
if platform.system() == "Windows":
|
| 152 |
+
possible_paths.extend(
|
| 153 |
+
[
|
| 154 |
+
home / "AppData" / "Local" / "nixd" / "nixd.exe",
|
| 155 |
+
home / ".serena" / "language_servers" / "nixd" / "nixd.exe",
|
| 156 |
+
]
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
for path in possible_paths:
|
| 160 |
+
if path.exists():
|
| 161 |
+
return str(path)
|
| 162 |
+
|
| 163 |
+
return None
|
| 164 |
+
|
| 165 |
+
@staticmethod
|
| 166 |
+
def _install_nixd_with_nix():
|
| 167 |
+
"""Install nixd using nix if available."""
|
| 168 |
+
# Check if nix is available
|
| 169 |
+
if not shutil.which("nix"):
|
| 170 |
+
return None
|
| 171 |
+
|
| 172 |
+
print("Installing nixd using nix... This may take a few minutes.")
|
| 173 |
+
try:
|
| 174 |
+
# Try to install nixd using nix profile
|
| 175 |
+
result = subprocess.run(
|
| 176 |
+
["nix", "profile", "install", "github:nix-community/nixd"],
|
| 177 |
+
capture_output=True,
|
| 178 |
+
text=True,
|
| 179 |
+
check=False,
|
| 180 |
+
timeout=600, # 10 minute timeout for building
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
if result.returncode == 0:
|
| 184 |
+
# Check if nixd is now in PATH
|
| 185 |
+
nixd_path = shutil.which("nixd")
|
| 186 |
+
if nixd_path:
|
| 187 |
+
print(f"Successfully installed nixd at: {nixd_path}")
|
| 188 |
+
return nixd_path
|
| 189 |
+
else:
|
| 190 |
+
# Try nix-env as fallback
|
| 191 |
+
result = subprocess.run(
|
| 192 |
+
["nix-env", "-iA", "nixpkgs.nixd"],
|
| 193 |
+
capture_output=True,
|
| 194 |
+
text=True,
|
| 195 |
+
check=False,
|
| 196 |
+
timeout=600,
|
| 197 |
+
)
|
| 198 |
+
if result.returncode == 0:
|
| 199 |
+
nixd_path = shutil.which("nixd")
|
| 200 |
+
if nixd_path:
|
| 201 |
+
print(f"Successfully installed nixd at: {nixd_path}")
|
| 202 |
+
return nixd_path
|
| 203 |
+
print(f"Failed to install nixd: {result.stderr}")
|
| 204 |
+
|
| 205 |
+
except subprocess.TimeoutExpired:
|
| 206 |
+
print("Nix install timed out after 10 minutes")
|
| 207 |
+
except Exception as e:
|
| 208 |
+
print(f"Error installing nixd with nix: {e}")
|
| 209 |
+
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
+
@staticmethod
|
| 213 |
+
def _setup_runtime_dependency():
|
| 214 |
+
"""
|
| 215 |
+
Check if required Nix runtime dependencies are available.
|
| 216 |
+
Attempts to install nixd if not present.
|
| 217 |
+
"""
|
| 218 |
+
# First check if Nix is available (nixd needs it at runtime)
|
| 219 |
+
if not shutil.which("nix"):
|
| 220 |
+
print("WARNING: Nix is not installed. nixd requires Nix to function properly.")
|
| 221 |
+
raise RuntimeError("Nix is required for nixd. Please install Nix from https://nixos.org/download.html")
|
| 222 |
+
|
| 223 |
+
nixd_path = NixLanguageServer._get_nixd_path()
|
| 224 |
+
|
| 225 |
+
if not nixd_path:
|
| 226 |
+
print("nixd not found. Attempting to install...")
|
| 227 |
+
|
| 228 |
+
# Try to install with nix if available
|
| 229 |
+
nixd_path = NixLanguageServer._install_nixd_with_nix()
|
| 230 |
+
|
| 231 |
+
if not nixd_path:
|
| 232 |
+
raise RuntimeError(
|
| 233 |
+
"nixd (Nix Language Server) is not installed.\n"
|
| 234 |
+
"Please install nixd using one of the following methods:\n"
|
| 235 |
+
" - Using Nix flakes: nix profile install github:nix-community/nixd\n"
|
| 236 |
+
" - From nixpkgs: nix-env -iA nixpkgs.nixd\n"
|
| 237 |
+
" - On macOS with Homebrew: brew install nixd\n\n"
|
| 238 |
+
"After installation, make sure 'nixd' is in your PATH."
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
# Verify nixd works
|
| 242 |
+
try:
|
| 243 |
+
result = subprocess.run([nixd_path, "--version"], capture_output=True, text=True, check=False, timeout=5)
|
| 244 |
+
if result.returncode != 0:
|
| 245 |
+
raise RuntimeError(f"nixd failed to run: {result.stderr}")
|
| 246 |
+
except Exception as e:
|
| 247 |
+
raise RuntimeError(f"Failed to verify nixd installation: {e}")
|
| 248 |
+
|
| 249 |
+
return nixd_path
|
| 250 |
+
|
| 251 |
+
def __init__(
|
| 252 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 253 |
+
):
|
| 254 |
+
nixd_path = self._setup_runtime_dependency()
|
| 255 |
+
|
| 256 |
+
super().__init__(
|
| 257 |
+
config,
|
| 258 |
+
logger,
|
| 259 |
+
repository_root_path,
|
| 260 |
+
ProcessLaunchInfo(cmd=nixd_path, cwd=repository_root_path),
|
| 261 |
+
"nix",
|
| 262 |
+
solidlsp_settings,
|
| 263 |
+
)
|
| 264 |
+
self.server_ready = threading.Event()
|
| 265 |
+
self.request_id = 0
|
| 266 |
+
|
| 267 |
+
@staticmethod
|
| 268 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 269 |
+
"""
|
| 270 |
+
Returns the initialize params for nixd.
|
| 271 |
+
"""
|
| 272 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 273 |
+
initialize_params = {
|
| 274 |
+
"locale": "en",
|
| 275 |
+
"capabilities": {
|
| 276 |
+
"textDocument": {
|
| 277 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 278 |
+
"definition": {"dynamicRegistration": True},
|
| 279 |
+
"references": {"dynamicRegistration": True},
|
| 280 |
+
"documentSymbol": {
|
| 281 |
+
"dynamicRegistration": True,
|
| 282 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 283 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 284 |
+
},
|
| 285 |
+
"completion": {
|
| 286 |
+
"dynamicRegistration": True,
|
| 287 |
+
"completionItem": {
|
| 288 |
+
"snippetSupport": True,
|
| 289 |
+
"commitCharactersSupport": True,
|
| 290 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 291 |
+
"deprecatedSupport": True,
|
| 292 |
+
"preselectSupport": True,
|
| 293 |
+
},
|
| 294 |
+
},
|
| 295 |
+
"hover": {
|
| 296 |
+
"dynamicRegistration": True,
|
| 297 |
+
"contentFormat": ["markdown", "plaintext"],
|
| 298 |
+
},
|
| 299 |
+
"signatureHelp": {
|
| 300 |
+
"dynamicRegistration": True,
|
| 301 |
+
"signatureInformation": {
|
| 302 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 303 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 304 |
+
},
|
| 305 |
+
},
|
| 306 |
+
"codeAction": {
|
| 307 |
+
"dynamicRegistration": True,
|
| 308 |
+
"codeActionLiteralSupport": {
|
| 309 |
+
"codeActionKind": {
|
| 310 |
+
"valueSet": [
|
| 311 |
+
"",
|
| 312 |
+
"quickfix",
|
| 313 |
+
"refactor",
|
| 314 |
+
"refactor.extract",
|
| 315 |
+
"refactor.inline",
|
| 316 |
+
"refactor.rewrite",
|
| 317 |
+
"source",
|
| 318 |
+
"source.organizeImports",
|
| 319 |
+
]
|
| 320 |
+
}
|
| 321 |
+
},
|
| 322 |
+
},
|
| 323 |
+
"rename": {"dynamicRegistration": True, "prepareSupport": True},
|
| 324 |
+
},
|
| 325 |
+
"workspace": {
|
| 326 |
+
"workspaceFolders": True,
|
| 327 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 328 |
+
"configuration": True,
|
| 329 |
+
"symbol": {
|
| 330 |
+
"dynamicRegistration": True,
|
| 331 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 332 |
+
},
|
| 333 |
+
},
|
| 334 |
+
},
|
| 335 |
+
"processId": os.getpid(),
|
| 336 |
+
"rootPath": repository_absolute_path,
|
| 337 |
+
"rootUri": root_uri,
|
| 338 |
+
"workspaceFolders": [
|
| 339 |
+
{
|
| 340 |
+
"uri": root_uri,
|
| 341 |
+
"name": os.path.basename(repository_absolute_path),
|
| 342 |
+
}
|
| 343 |
+
],
|
| 344 |
+
"initializationOptions": {
|
| 345 |
+
# nixd specific options
|
| 346 |
+
"nixpkgs": {"expr": "import <nixpkgs> { }"},
|
| 347 |
+
"formatting": {"command": ["nixpkgs-fmt"]}, # or ["alejandra"] or ["nixfmt"]
|
| 348 |
+
"options": {
|
| 349 |
+
"enable": True,
|
| 350 |
+
"target": {
|
| 351 |
+
"installable": "", # Will be auto-detected from flake.nix if present
|
| 352 |
+
},
|
| 353 |
+
},
|
| 354 |
+
},
|
| 355 |
+
}
|
| 356 |
+
return initialize_params
|
| 357 |
+
|
| 358 |
+
def _start_server(self):
|
| 359 |
+
"""Start nixd server process"""
|
| 360 |
+
|
| 361 |
+
def register_capability_handler(params):
|
| 362 |
+
return
|
| 363 |
+
|
| 364 |
+
def window_log_message(msg):
|
| 365 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 366 |
+
|
| 367 |
+
def do_nothing(params):
|
| 368 |
+
return
|
| 369 |
+
|
| 370 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 371 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 372 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 373 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 374 |
+
|
| 375 |
+
self.logger.log("Starting nixd server process", logging.INFO)
|
| 376 |
+
self.server.start()
|
| 377 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 378 |
+
|
| 379 |
+
self.logger.log(
|
| 380 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 381 |
+
logging.INFO,
|
| 382 |
+
)
|
| 383 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 384 |
+
|
| 385 |
+
# Verify server capabilities
|
| 386 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 387 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 388 |
+
assert "documentSymbolProvider" in init_response["capabilities"]
|
| 389 |
+
assert "referencesProvider" in init_response["capabilities"]
|
| 390 |
+
|
| 391 |
+
self.server.notify.initialized({})
|
| 392 |
+
self.completions_available.set()
|
| 393 |
+
|
| 394 |
+
# nixd server is typically ready immediately after initialization
|
| 395 |
+
self.server_ready.set()
|
| 396 |
+
self.server_ready.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/omnisharp.py
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides C# specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C#.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import threading
|
| 10 |
+
from collections.abc import Iterable
|
| 11 |
+
|
| 12 |
+
from overrides import override
|
| 13 |
+
|
| 14 |
+
from solidlsp.ls import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 16 |
+
from solidlsp.ls_exceptions import SolidLSPException
|
| 17 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 18 |
+
from solidlsp.ls_utils import DotnetVersion, FileUtils, PlatformId, PlatformUtils
|
| 19 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 20 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 21 |
+
from solidlsp.settings import SolidLSPSettings
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def breadth_first_file_scan(root) -> Iterable[str]:
|
| 25 |
+
"""
|
| 26 |
+
This function was obtained from https://stackoverflow.com/questions/49654234/is-there-a-breadth-first-search-option-available-in-os-walk-or-equivalent-py
|
| 27 |
+
It traverses the directory tree in breadth first order.
|
| 28 |
+
"""
|
| 29 |
+
dirs = [root]
|
| 30 |
+
# while we has dirs to scan
|
| 31 |
+
while dirs:
|
| 32 |
+
next_dirs = []
|
| 33 |
+
for parent in dirs:
|
| 34 |
+
# scan each dir
|
| 35 |
+
for f in os.listdir(parent):
|
| 36 |
+
# if there is a dir, then save for next ittr
|
| 37 |
+
# if it is a file then yield it (we'll return later)
|
| 38 |
+
ff = os.path.join(parent, f)
|
| 39 |
+
if os.path.isdir(ff):
|
| 40 |
+
next_dirs.append(ff)
|
| 41 |
+
else:
|
| 42 |
+
yield ff
|
| 43 |
+
|
| 44 |
+
# once we've done all the current dirs then
|
| 45 |
+
# we set up the next itter as the child dirs
|
| 46 |
+
# from the current itter.
|
| 47 |
+
dirs = next_dirs
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def find_least_depth_sln_file(root_dir) -> str | None:
|
| 51 |
+
for filename in breadth_first_file_scan(root_dir):
|
| 52 |
+
if filename.endswith(".sln"):
|
| 53 |
+
return filename
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class OmniSharp(SolidLanguageServer):
|
| 58 |
+
"""
|
| 59 |
+
Provides C# specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C#.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def __init__(
|
| 63 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 64 |
+
):
|
| 65 |
+
"""
|
| 66 |
+
Creates an OmniSharp instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 67 |
+
"""
|
| 68 |
+
omnisharp_executable_path, dll_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 69 |
+
|
| 70 |
+
slnfilename = find_least_depth_sln_file(repository_root_path)
|
| 71 |
+
if slnfilename is None:
|
| 72 |
+
logger.log("No *.sln file found in repository", logging.ERROR)
|
| 73 |
+
raise SolidLSPException("No SLN file found in repository")
|
| 74 |
+
|
| 75 |
+
cmd = " ".join(
|
| 76 |
+
[
|
| 77 |
+
omnisharp_executable_path,
|
| 78 |
+
"-lsp",
|
| 79 |
+
"--encoding",
|
| 80 |
+
"ascii",
|
| 81 |
+
"-z",
|
| 82 |
+
"-s",
|
| 83 |
+
f'"{slnfilename}"',
|
| 84 |
+
"--hostPID",
|
| 85 |
+
str(os.getpid()),
|
| 86 |
+
"DotNet:enablePackageRestore=false",
|
| 87 |
+
"--loglevel",
|
| 88 |
+
"trace",
|
| 89 |
+
"--plugin",
|
| 90 |
+
dll_path,
|
| 91 |
+
"FileOptions:SystemExcludeSearchPatterns:0=**/.git",
|
| 92 |
+
"FileOptions:SystemExcludeSearchPatterns:1=**/.svn",
|
| 93 |
+
"FileOptions:SystemExcludeSearchPatterns:2=**/.hg",
|
| 94 |
+
"FileOptions:SystemExcludeSearchPatterns:3=**/CVS",
|
| 95 |
+
"FileOptions:SystemExcludeSearchPatterns:4=**/.DS_Store",
|
| 96 |
+
"FileOptions:SystemExcludeSearchPatterns:5=**/Thumbs.db",
|
| 97 |
+
"RoslynExtensionsOptions:EnableAnalyzersSupport=true",
|
| 98 |
+
"FormattingOptions:EnableEditorConfigSupport=true",
|
| 99 |
+
"RoslynExtensionsOptions:EnableImportCompletion=true",
|
| 100 |
+
"Sdk:IncludePrereleases=true",
|
| 101 |
+
"RoslynExtensionsOptions:AnalyzeOpenDocumentsOnly=true",
|
| 102 |
+
"formattingOptions:useTabs=false",
|
| 103 |
+
"formattingOptions:tabSize=4",
|
| 104 |
+
"formattingOptions:indentationSize=4",
|
| 105 |
+
]
|
| 106 |
+
)
|
| 107 |
+
super().__init__(
|
| 108 |
+
config, logger, repository_root_path, ProcessLaunchInfo(cmd=cmd, cwd=repository_root_path), "csharp", solidlsp_settings
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
self.server_ready = threading.Event()
|
| 112 |
+
self.definition_available = threading.Event()
|
| 113 |
+
self.references_available = threading.Event()
|
| 114 |
+
|
| 115 |
+
@override
|
| 116 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 117 |
+
return super().is_ignored_dirname(dirname) or dirname in ["bin", "obj"]
|
| 118 |
+
|
| 119 |
+
@staticmethod
|
| 120 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 121 |
+
"""
|
| 122 |
+
Returns the initialize params for the Omnisharp Language Server.
|
| 123 |
+
"""
|
| 124 |
+
with open(os.path.join(os.path.dirname(__file__), "omnisharp", "initialize_params.json"), encoding="utf-8") as f:
|
| 125 |
+
d = json.load(f)
|
| 126 |
+
|
| 127 |
+
del d["_description"]
|
| 128 |
+
|
| 129 |
+
d["processId"] = os.getpid()
|
| 130 |
+
assert d["rootPath"] == "$rootPath"
|
| 131 |
+
d["rootPath"] = repository_absolute_path
|
| 132 |
+
|
| 133 |
+
assert d["rootUri"] == "$rootUri"
|
| 134 |
+
d["rootUri"] = pathlib.Path(repository_absolute_path).as_uri()
|
| 135 |
+
|
| 136 |
+
assert d["workspaceFolders"][0]["uri"] == "$uri"
|
| 137 |
+
d["workspaceFolders"][0]["uri"] = pathlib.Path(repository_absolute_path).as_uri()
|
| 138 |
+
|
| 139 |
+
assert d["workspaceFolders"][0]["name"] == "$name"
|
| 140 |
+
d["workspaceFolders"][0]["name"] = os.path.basename(repository_absolute_path)
|
| 141 |
+
|
| 142 |
+
return d
|
| 143 |
+
|
| 144 |
+
@classmethod
|
| 145 |
+
def _setup_runtime_dependencies(
|
| 146 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 147 |
+
) -> tuple[str, str]:
|
| 148 |
+
"""
|
| 149 |
+
Setup runtime dependencies for OmniSharp.
|
| 150 |
+
"""
|
| 151 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 152 |
+
dotnet_version = PlatformUtils.get_dotnet_version()
|
| 153 |
+
|
| 154 |
+
with open(os.path.join(os.path.dirname(__file__), "omnisharp", "runtime_dependencies.json"), encoding="utf-8") as f:
|
| 155 |
+
d = json.load(f)
|
| 156 |
+
del d["_description"]
|
| 157 |
+
|
| 158 |
+
assert platform_id in [
|
| 159 |
+
PlatformId.LINUX_x64,
|
| 160 |
+
PlatformId.WIN_x64,
|
| 161 |
+
], f"Only linux-x64 and win-x64 platform is supported at the moment but got {platform_id=}"
|
| 162 |
+
assert dotnet_version in [
|
| 163 |
+
DotnetVersion.V6,
|
| 164 |
+
DotnetVersion.V7,
|
| 165 |
+
DotnetVersion.V8,
|
| 166 |
+
DotnetVersion.V9,
|
| 167 |
+
], f"Only dotnet version 6-9 are supported at the moment but got {dotnet_version=}"
|
| 168 |
+
|
| 169 |
+
# TODO: Do away with this assumption
|
| 170 |
+
# Currently, runtime binaries are not available for .Net 7 and .Net 8. Hence, we assume .Net 6 runtime binaries to be compatible with .Net 7, .Net 8
|
| 171 |
+
if dotnet_version in [DotnetVersion.V7, DotnetVersion.V8, DotnetVersion.V9]:
|
| 172 |
+
dotnet_version = DotnetVersion.V6
|
| 173 |
+
|
| 174 |
+
runtime_dependencies = d["runtimeDependencies"]
|
| 175 |
+
runtime_dependencies = [dependency for dependency in runtime_dependencies if dependency["platformId"] == platform_id.value]
|
| 176 |
+
runtime_dependencies = [
|
| 177 |
+
dependency
|
| 178 |
+
for dependency in runtime_dependencies
|
| 179 |
+
if "dotnet_version" not in dependency or dependency["dotnet_version"] == dotnet_version.value
|
| 180 |
+
]
|
| 181 |
+
assert len(runtime_dependencies) == 2
|
| 182 |
+
runtime_dependencies = {
|
| 183 |
+
runtime_dependencies[0]["id"]: runtime_dependencies[0],
|
| 184 |
+
runtime_dependencies[1]["id"]: runtime_dependencies[1],
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
assert "OmniSharp" in runtime_dependencies
|
| 188 |
+
assert "RazorOmnisharp" in runtime_dependencies
|
| 189 |
+
|
| 190 |
+
omnisharp_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "OmniSharp")
|
| 191 |
+
if not os.path.exists(omnisharp_ls_dir):
|
| 192 |
+
os.makedirs(omnisharp_ls_dir)
|
| 193 |
+
FileUtils.download_and_extract_archive(logger, runtime_dependencies["OmniSharp"]["url"], omnisharp_ls_dir, "zip")
|
| 194 |
+
omnisharp_executable_path = os.path.join(omnisharp_ls_dir, runtime_dependencies["OmniSharp"]["binaryName"])
|
| 195 |
+
assert os.path.exists(omnisharp_executable_path)
|
| 196 |
+
os.chmod(omnisharp_executable_path, 0o755)
|
| 197 |
+
|
| 198 |
+
razor_omnisharp_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "RazorOmnisharp")
|
| 199 |
+
if not os.path.exists(razor_omnisharp_ls_dir):
|
| 200 |
+
os.makedirs(razor_omnisharp_ls_dir)
|
| 201 |
+
FileUtils.download_and_extract_archive(logger, runtime_dependencies["RazorOmnisharp"]["url"], razor_omnisharp_ls_dir, "zip")
|
| 202 |
+
razor_omnisharp_dll_path = os.path.join(razor_omnisharp_ls_dir, runtime_dependencies["RazorOmnisharp"]["dll_path"])
|
| 203 |
+
assert os.path.exists(razor_omnisharp_dll_path)
|
| 204 |
+
|
| 205 |
+
return omnisharp_executable_path, razor_omnisharp_dll_path
|
| 206 |
+
|
| 207 |
+
def _start_server(self):
|
| 208 |
+
"""
|
| 209 |
+
Starts the Omnisharp Language Server
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
def register_capability_handler(params):
|
| 213 |
+
assert "registrations" in params
|
| 214 |
+
for registration in params["registrations"]:
|
| 215 |
+
if registration["method"] == "textDocument/definition":
|
| 216 |
+
self.definition_available.set()
|
| 217 |
+
if registration["method"] == "textDocument/references":
|
| 218 |
+
self.references_available.set()
|
| 219 |
+
if registration["method"] == "textDocument/completion":
|
| 220 |
+
self.completions_available.set()
|
| 221 |
+
|
| 222 |
+
def lang_status_handler(params):
|
| 223 |
+
# TODO: Should we wait for
|
| 224 |
+
# server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}
|
| 225 |
+
# Before proceeding?
|
| 226 |
+
# if params["type"] == "ServiceReady" and params["message"] == "ServiceReady":
|
| 227 |
+
# self.service_ready_event.set()
|
| 228 |
+
pass
|
| 229 |
+
|
| 230 |
+
def execute_client_command_handler(params):
|
| 231 |
+
return []
|
| 232 |
+
|
| 233 |
+
def do_nothing(params):
|
| 234 |
+
return
|
| 235 |
+
|
| 236 |
+
def check_experimental_status(params):
|
| 237 |
+
if params["quiescent"] is True:
|
| 238 |
+
self.server_ready.set()
|
| 239 |
+
|
| 240 |
+
def workspace_configuration_handler(params):
|
| 241 |
+
# TODO: We do not know the appropriate way to handle this request. Should ideally contact the OmniSharp dev team
|
| 242 |
+
return [
|
| 243 |
+
{
|
| 244 |
+
"RoslynExtensionsOptions": {
|
| 245 |
+
"EnableDecompilationSupport": False,
|
| 246 |
+
"EnableAnalyzersSupport": True,
|
| 247 |
+
"EnableImportCompletion": True,
|
| 248 |
+
"EnableAsyncCompletion": False,
|
| 249 |
+
"DocumentAnalysisTimeoutMs": 30000,
|
| 250 |
+
"DiagnosticWorkersThreadCount": 18,
|
| 251 |
+
"AnalyzeOpenDocumentsOnly": True,
|
| 252 |
+
"InlayHintsOptions": {
|
| 253 |
+
"EnableForParameters": False,
|
| 254 |
+
"ForLiteralParameters": False,
|
| 255 |
+
"ForIndexerParameters": False,
|
| 256 |
+
"ForObjectCreationParameters": False,
|
| 257 |
+
"ForOtherParameters": False,
|
| 258 |
+
"SuppressForParametersThatDifferOnlyBySuffix": False,
|
| 259 |
+
"SuppressForParametersThatMatchMethodIntent": False,
|
| 260 |
+
"SuppressForParametersThatMatchArgumentName": False,
|
| 261 |
+
"EnableForTypes": False,
|
| 262 |
+
"ForImplicitVariableTypes": False,
|
| 263 |
+
"ForLambdaParameterTypes": False,
|
| 264 |
+
"ForImplicitObjectCreation": False,
|
| 265 |
+
},
|
| 266 |
+
"LocationPaths": None,
|
| 267 |
+
},
|
| 268 |
+
"FormattingOptions": {
|
| 269 |
+
"OrganizeImports": False,
|
| 270 |
+
"EnableEditorConfigSupport": True,
|
| 271 |
+
"NewLine": "\n",
|
| 272 |
+
"UseTabs": False,
|
| 273 |
+
"TabSize": 4,
|
| 274 |
+
"IndentationSize": 4,
|
| 275 |
+
"SpacingAfterMethodDeclarationName": False,
|
| 276 |
+
"SeparateImportDirectiveGroups": False,
|
| 277 |
+
"SpaceWithinMethodDeclarationParenthesis": False,
|
| 278 |
+
"SpaceBetweenEmptyMethodDeclarationParentheses": False,
|
| 279 |
+
"SpaceAfterMethodCallName": False,
|
| 280 |
+
"SpaceWithinMethodCallParentheses": False,
|
| 281 |
+
"SpaceBetweenEmptyMethodCallParentheses": False,
|
| 282 |
+
"SpaceAfterControlFlowStatementKeyword": True,
|
| 283 |
+
"SpaceWithinExpressionParentheses": False,
|
| 284 |
+
"SpaceWithinCastParentheses": False,
|
| 285 |
+
"SpaceWithinOtherParentheses": False,
|
| 286 |
+
"SpaceAfterCast": False,
|
| 287 |
+
"SpaceBeforeOpenSquareBracket": False,
|
| 288 |
+
"SpaceBetweenEmptySquareBrackets": False,
|
| 289 |
+
"SpaceWithinSquareBrackets": False,
|
| 290 |
+
"SpaceAfterColonInBaseTypeDeclaration": True,
|
| 291 |
+
"SpaceAfterComma": True,
|
| 292 |
+
"SpaceAfterDot": False,
|
| 293 |
+
"SpaceAfterSemicolonsInForStatement": True,
|
| 294 |
+
"SpaceBeforeColonInBaseTypeDeclaration": True,
|
| 295 |
+
"SpaceBeforeComma": False,
|
| 296 |
+
"SpaceBeforeDot": False,
|
| 297 |
+
"SpaceBeforeSemicolonsInForStatement": False,
|
| 298 |
+
"SpacingAroundBinaryOperator": "single",
|
| 299 |
+
"IndentBraces": False,
|
| 300 |
+
"IndentBlock": True,
|
| 301 |
+
"IndentSwitchSection": True,
|
| 302 |
+
"IndentSwitchCaseSection": True,
|
| 303 |
+
"IndentSwitchCaseSectionWhenBlock": True,
|
| 304 |
+
"LabelPositioning": "oneLess",
|
| 305 |
+
"WrappingPreserveSingleLine": True,
|
| 306 |
+
"WrappingKeepStatementsOnSingleLine": True,
|
| 307 |
+
"NewLinesForBracesInTypes": True,
|
| 308 |
+
"NewLinesForBracesInMethods": True,
|
| 309 |
+
"NewLinesForBracesInProperties": True,
|
| 310 |
+
"NewLinesForBracesInAccessors": True,
|
| 311 |
+
"NewLinesForBracesInAnonymousMethods": True,
|
| 312 |
+
"NewLinesForBracesInControlBlocks": True,
|
| 313 |
+
"NewLinesForBracesInAnonymousTypes": True,
|
| 314 |
+
"NewLinesForBracesInObjectCollectionArrayInitializers": True,
|
| 315 |
+
"NewLinesForBracesInLambdaExpressionBody": True,
|
| 316 |
+
"NewLineForElse": True,
|
| 317 |
+
"NewLineForCatch": True,
|
| 318 |
+
"NewLineForFinally": True,
|
| 319 |
+
"NewLineForMembersInObjectInit": True,
|
| 320 |
+
"NewLineForMembersInAnonymousTypes": True,
|
| 321 |
+
"NewLineForClausesInQuery": True,
|
| 322 |
+
},
|
| 323 |
+
"FileOptions": {
|
| 324 |
+
"SystemExcludeSearchPatterns": [
|
| 325 |
+
"**/node_modules/**/*",
|
| 326 |
+
"**/bin/**/*",
|
| 327 |
+
"**/obj/**/*",
|
| 328 |
+
"**/.git/**/*",
|
| 329 |
+
"**/.git",
|
| 330 |
+
"**/.svn",
|
| 331 |
+
"**/.hg",
|
| 332 |
+
"**/CVS",
|
| 333 |
+
"**/.DS_Store",
|
| 334 |
+
"**/Thumbs.db",
|
| 335 |
+
],
|
| 336 |
+
"ExcludeSearchPatterns": [],
|
| 337 |
+
},
|
| 338 |
+
"RenameOptions": {
|
| 339 |
+
"RenameOverloads": False,
|
| 340 |
+
"RenameInStrings": False,
|
| 341 |
+
"RenameInComments": False,
|
| 342 |
+
},
|
| 343 |
+
"ImplementTypeOptions": {
|
| 344 |
+
"InsertionBehavior": 0,
|
| 345 |
+
"PropertyGenerationBehavior": 0,
|
| 346 |
+
},
|
| 347 |
+
"DotNetCliOptions": {"LocationPaths": None},
|
| 348 |
+
"Plugins": {"LocationPaths": None},
|
| 349 |
+
}
|
| 350 |
+
]
|
| 351 |
+
|
| 352 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 353 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 354 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 355 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 356 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 357 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 358 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 359 |
+
self.server.on_request("workspace/configuration", workspace_configuration_handler)
|
| 360 |
+
|
| 361 |
+
self.logger.log("Starting OmniSharp server process", logging.INFO)
|
| 362 |
+
self.server.start()
|
| 363 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 364 |
+
|
| 365 |
+
self.logger.log(
|
| 366 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 367 |
+
logging.INFO,
|
| 368 |
+
)
|
| 369 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 370 |
+
self.server.notify.initialized({})
|
| 371 |
+
with open(os.path.join(os.path.dirname(__file__), "omnisharp", "workspace_did_change_configuration.json"), encoding="utf-8") as f:
|
| 372 |
+
self.server.notify.workspace_did_change_configuration({"settings": json.load(f)})
|
| 373 |
+
assert "capabilities" in init_response
|
| 374 |
+
if "definitionProvider" in init_response["capabilities"] and init_response["capabilities"]["definitionProvider"]:
|
| 375 |
+
self.definition_available.set()
|
| 376 |
+
if "referencesProvider" in init_response["capabilities"] and init_response["capabilities"]["referencesProvider"]:
|
| 377 |
+
self.references_available.set()
|
| 378 |
+
|
| 379 |
+
self.definition_available.wait()
|
| 380 |
+
self.references_available.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/pyright_server.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Python specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Python.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import re
|
| 9 |
+
import threading
|
| 10 |
+
|
| 11 |
+
from overrides import override
|
| 12 |
+
|
| 13 |
+
from solidlsp.ls import SolidLanguageServer
|
| 14 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 15 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 16 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 17 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 18 |
+
from solidlsp.settings import SolidLSPSettings
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class PyrightServer(SolidLanguageServer):
|
| 22 |
+
"""
|
| 23 |
+
Provides Python specific instantiation of the LanguageServer class using Pyright.
|
| 24 |
+
Contains various configurations and settings specific to Python.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
def __init__(
|
| 28 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 29 |
+
):
|
| 30 |
+
"""
|
| 31 |
+
Creates a PyrightServer instance. This class is not meant to be instantiated directly.
|
| 32 |
+
Use LanguageServer.create() instead.
|
| 33 |
+
"""
|
| 34 |
+
super().__init__(
|
| 35 |
+
config,
|
| 36 |
+
logger,
|
| 37 |
+
repository_root_path,
|
| 38 |
+
# Note 1: we can also use `pyright-langserver --stdio` but it requires pyright to be installed with npm
|
| 39 |
+
# Note 2: we can also use `bpyright-langserver --stdio` if we ever are unhappy with pyright
|
| 40 |
+
ProcessLaunchInfo(cmd="python -m pyright.langserver --stdio", cwd=repository_root_path),
|
| 41 |
+
"python",
|
| 42 |
+
solidlsp_settings,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
# Event to signal when initial workspace analysis is complete
|
| 46 |
+
self.analysis_complete = threading.Event()
|
| 47 |
+
self.found_source_files = False
|
| 48 |
+
|
| 49 |
+
@override
|
| 50 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 51 |
+
return super().is_ignored_dirname(dirname) or dirname in ["venv", "__pycache__"]
|
| 52 |
+
|
| 53 |
+
@staticmethod
|
| 54 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 55 |
+
"""
|
| 56 |
+
Returns the initialize params for the Pyright Language Server.
|
| 57 |
+
"""
|
| 58 |
+
# Create basic initialization parameters
|
| 59 |
+
initialize_params: InitializeParams = { # type: ignore
|
| 60 |
+
"processId": os.getpid(),
|
| 61 |
+
"rootPath": repository_absolute_path,
|
| 62 |
+
"rootUri": pathlib.Path(repository_absolute_path).as_uri(),
|
| 63 |
+
"initializationOptions": {
|
| 64 |
+
"exclude": [
|
| 65 |
+
"**/__pycache__",
|
| 66 |
+
"**/.venv",
|
| 67 |
+
"**/.env",
|
| 68 |
+
"**/build",
|
| 69 |
+
"**/dist",
|
| 70 |
+
"**/.pixi",
|
| 71 |
+
],
|
| 72 |
+
"reportMissingImports": "error",
|
| 73 |
+
},
|
| 74 |
+
"capabilities": {
|
| 75 |
+
"workspace": {
|
| 76 |
+
"workspaceEdit": {"documentChanges": True},
|
| 77 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 78 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True},
|
| 79 |
+
"symbol": {
|
| 80 |
+
"dynamicRegistration": True,
|
| 81 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 82 |
+
},
|
| 83 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 84 |
+
},
|
| 85 |
+
"textDocument": {
|
| 86 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 87 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 88 |
+
"signatureHelp": {
|
| 89 |
+
"dynamicRegistration": True,
|
| 90 |
+
"signatureInformation": {
|
| 91 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 92 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 93 |
+
},
|
| 94 |
+
},
|
| 95 |
+
"definition": {"dynamicRegistration": True},
|
| 96 |
+
"references": {"dynamicRegistration": True},
|
| 97 |
+
"documentSymbol": {
|
| 98 |
+
"dynamicRegistration": True,
|
| 99 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 100 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 101 |
+
},
|
| 102 |
+
"publishDiagnostics": {"relatedInformation": True},
|
| 103 |
+
},
|
| 104 |
+
},
|
| 105 |
+
"workspaceFolders": [
|
| 106 |
+
{"uri": pathlib.Path(repository_absolute_path).as_uri(), "name": os.path.basename(repository_absolute_path)}
|
| 107 |
+
],
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
return initialize_params
|
| 111 |
+
|
| 112 |
+
def _start_server(self):
|
| 113 |
+
"""
|
| 114 |
+
Starts the Pyright Language Server and waits for initial workspace analysis to complete.
|
| 115 |
+
|
| 116 |
+
This prevents zombie processes by ensuring Pyright has finished its initial background
|
| 117 |
+
tasks before we consider the server ready.
|
| 118 |
+
|
| 119 |
+
Usage:
|
| 120 |
+
```
|
| 121 |
+
async with lsp.start_server():
|
| 122 |
+
# LanguageServer has been initialized and workspace analysis is complete
|
| 123 |
+
await lsp.request_definition(...)
|
| 124 |
+
await lsp.request_references(...)
|
| 125 |
+
# Shutdown the LanguageServer on exit from scope
|
| 126 |
+
# LanguageServer has been shutdown cleanly
|
| 127 |
+
```
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
def execute_client_command_handler(params):
|
| 131 |
+
return []
|
| 132 |
+
|
| 133 |
+
def do_nothing(params):
|
| 134 |
+
return
|
| 135 |
+
|
| 136 |
+
def window_log_message(msg):
|
| 137 |
+
"""
|
| 138 |
+
Monitor Pyright's log messages to detect when initial analysis is complete.
|
| 139 |
+
Pyright logs "Found X source files" when it finishes scanning the workspace.
|
| 140 |
+
"""
|
| 141 |
+
message_text = msg.get("message", "")
|
| 142 |
+
self.logger.log(f"LSP: window/logMessage: {message_text}", logging.INFO)
|
| 143 |
+
|
| 144 |
+
# Look for "Found X source files" which indicates workspace scanning is complete
|
| 145 |
+
# Unfortunately, pyright is unreliable and there seems to be no better way
|
| 146 |
+
if re.search(r"Found \d+ source files?", message_text):
|
| 147 |
+
self.logger.log("Pyright workspace scanning complete", logging.INFO)
|
| 148 |
+
self.found_source_files = True
|
| 149 |
+
self.analysis_complete.set()
|
| 150 |
+
self.completions_available.set()
|
| 151 |
+
|
| 152 |
+
def check_experimental_status(params):
|
| 153 |
+
"""
|
| 154 |
+
Also listen for experimental/serverStatus as a backup signal
|
| 155 |
+
"""
|
| 156 |
+
if params.get("quiescent") == True:
|
| 157 |
+
self.logger.log("Received experimental/serverStatus with quiescent=true", logging.INFO)
|
| 158 |
+
if not self.found_source_files:
|
| 159 |
+
self.analysis_complete.set()
|
| 160 |
+
self.completions_available.set()
|
| 161 |
+
|
| 162 |
+
# Set up notification handlers
|
| 163 |
+
self.server.on_request("client/registerCapability", do_nothing)
|
| 164 |
+
self.server.on_notification("language/status", do_nothing)
|
| 165 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 166 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 167 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 168 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 169 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 170 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 171 |
+
|
| 172 |
+
self.logger.log("Starting pyright-langserver server process", logging.INFO)
|
| 173 |
+
self.server.start()
|
| 174 |
+
|
| 175 |
+
# Send proper initialization parameters
|
| 176 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 177 |
+
|
| 178 |
+
self.logger.log(
|
| 179 |
+
"Sending initialize request from LSP client to pyright server and awaiting response",
|
| 180 |
+
logging.INFO,
|
| 181 |
+
)
|
| 182 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 183 |
+
self.logger.log(f"Received initialize response from pyright server: {init_response}", logging.INFO)
|
| 184 |
+
|
| 185 |
+
# Verify that the server supports our required features
|
| 186 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 187 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 188 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 189 |
+
|
| 190 |
+
# Complete the initialization handshake
|
| 191 |
+
self.server.notify.initialized({})
|
| 192 |
+
|
| 193 |
+
# Wait for Pyright to complete its initial workspace analysis
|
| 194 |
+
# This prevents zombie processes by ensuring background tasks finish
|
| 195 |
+
self.logger.log("Waiting for Pyright to complete initial workspace analysis...", logging.INFO)
|
| 196 |
+
if self.analysis_complete.wait(timeout=5.0):
|
| 197 |
+
self.logger.log("Pyright initial analysis complete, server ready", logging.INFO)
|
| 198 |
+
else:
|
| 199 |
+
self.logger.log("Timeout waiting for Pyright analysis completion, proceeding anyway", logging.WARNING)
|
| 200 |
+
# Fallback: assume analysis is complete after timeout
|
| 201 |
+
self.analysis_complete.set()
|
| 202 |
+
self.completions_available.set()
|
projects/ui/serena-new/src/solidlsp/language_servers/r_language_server.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
import subprocess
|
| 5 |
+
import threading
|
| 6 |
+
|
| 7 |
+
from overrides import override
|
| 8 |
+
|
| 9 |
+
from solidlsp.ls import SolidLanguageServer
|
| 10 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 11 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 12 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 13 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 14 |
+
from solidlsp.settings import SolidLSPSettings
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class RLanguageServer(SolidLanguageServer):
|
| 18 |
+
"""R Language Server implementation using the languageserver R package."""
|
| 19 |
+
|
| 20 |
+
@override
|
| 21 |
+
def _get_wait_time_for_cross_file_referencing(self) -> float:
|
| 22 |
+
return 5.0 # R language server needs extra time for workspace indexing in CI environments
|
| 23 |
+
|
| 24 |
+
@override
|
| 25 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 26 |
+
# For R projects, ignore common directories
|
| 27 |
+
return super().is_ignored_dirname(dirname) or dirname in [
|
| 28 |
+
"renv", # R environment management
|
| 29 |
+
"packrat", # Legacy R package management
|
| 30 |
+
".Rproj.user", # RStudio project files
|
| 31 |
+
"vignettes", # Package vignettes (often large)
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
@staticmethod
|
| 35 |
+
def _check_r_installation():
|
| 36 |
+
"""Check if R and languageserver are available."""
|
| 37 |
+
try:
|
| 38 |
+
# Check R installation
|
| 39 |
+
result = subprocess.run(["R", "--version"], capture_output=True, text=True, check=False)
|
| 40 |
+
if result.returncode != 0:
|
| 41 |
+
raise RuntimeError("R is not installed or not in PATH")
|
| 42 |
+
|
| 43 |
+
# Check languageserver package
|
| 44 |
+
result = subprocess.run(
|
| 45 |
+
["R", "--vanilla", "--quiet", "--slave", "-e", "if (!require('languageserver', quietly=TRUE)) quit(status=1)"],
|
| 46 |
+
capture_output=True,
|
| 47 |
+
text=True,
|
| 48 |
+
check=False,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
if result.returncode != 0:
|
| 52 |
+
raise RuntimeError(
|
| 53 |
+
"R languageserver package is not installed.\nInstall it with: R -e \"install.packages('languageserver')\""
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
except FileNotFoundError:
|
| 57 |
+
raise RuntimeError("R is not installed. Please install R from https://www.r-project.org/")
|
| 58 |
+
|
| 59 |
+
def __init__(
|
| 60 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 61 |
+
):
|
| 62 |
+
# Check R installation
|
| 63 |
+
self._check_r_installation()
|
| 64 |
+
|
| 65 |
+
# R command to start language server
|
| 66 |
+
# Use --vanilla for minimal startup and --quiet to suppress all output except LSP
|
| 67 |
+
# Set specific options to improve parsing stability
|
| 68 |
+
r_cmd = 'R --vanilla --quiet --slave -e "options(languageserver.debug_mode = FALSE); languageserver::run()"'
|
| 69 |
+
|
| 70 |
+
super().__init__(
|
| 71 |
+
config,
|
| 72 |
+
logger,
|
| 73 |
+
repository_root_path,
|
| 74 |
+
ProcessLaunchInfo(cmd=r_cmd, cwd=repository_root_path),
|
| 75 |
+
"r",
|
| 76 |
+
solidlsp_settings,
|
| 77 |
+
)
|
| 78 |
+
self.server_ready = threading.Event()
|
| 79 |
+
|
| 80 |
+
@staticmethod
|
| 81 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 82 |
+
"""Initialize params for R Language Server."""
|
| 83 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 84 |
+
initialize_params = {
|
| 85 |
+
"locale": "en",
|
| 86 |
+
"capabilities": {
|
| 87 |
+
"textDocument": {
|
| 88 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 89 |
+
"completion": {
|
| 90 |
+
"dynamicRegistration": True,
|
| 91 |
+
"completionItem": {
|
| 92 |
+
"snippetSupport": True,
|
| 93 |
+
"commitCharactersSupport": True,
|
| 94 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 95 |
+
"deprecatedSupport": True,
|
| 96 |
+
"preselectSupport": True,
|
| 97 |
+
},
|
| 98 |
+
},
|
| 99 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 100 |
+
"definition": {"dynamicRegistration": True},
|
| 101 |
+
"references": {"dynamicRegistration": True},
|
| 102 |
+
"documentSymbol": {
|
| 103 |
+
"dynamicRegistration": True,
|
| 104 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 105 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 106 |
+
},
|
| 107 |
+
"formatting": {"dynamicRegistration": True},
|
| 108 |
+
"rangeFormatting": {"dynamicRegistration": True},
|
| 109 |
+
},
|
| 110 |
+
"workspace": {
|
| 111 |
+
"workspaceFolders": True,
|
| 112 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 113 |
+
"symbol": {
|
| 114 |
+
"dynamicRegistration": True,
|
| 115 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 116 |
+
},
|
| 117 |
+
},
|
| 118 |
+
},
|
| 119 |
+
"processId": os.getpid(),
|
| 120 |
+
"rootPath": repository_absolute_path,
|
| 121 |
+
"rootUri": root_uri,
|
| 122 |
+
"workspaceFolders": [
|
| 123 |
+
{
|
| 124 |
+
"uri": root_uri,
|
| 125 |
+
"name": os.path.basename(repository_absolute_path),
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
}
|
| 129 |
+
return initialize_params
|
| 130 |
+
|
| 131 |
+
def _start_server(self):
|
| 132 |
+
"""Start R Language Server process."""
|
| 133 |
+
|
| 134 |
+
def window_log_message(msg):
|
| 135 |
+
self.logger.log(f"R LSP: window/logMessage: {msg}", logging.INFO)
|
| 136 |
+
|
| 137 |
+
def do_nothing(params):
|
| 138 |
+
return
|
| 139 |
+
|
| 140 |
+
def register_capability_handler(params):
|
| 141 |
+
return
|
| 142 |
+
|
| 143 |
+
# Register LSP message handlers
|
| 144 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 145 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 146 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 147 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 148 |
+
|
| 149 |
+
self.logger.log("Starting R Language Server process", logging.INFO)
|
| 150 |
+
self.server.start()
|
| 151 |
+
|
| 152 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 153 |
+
self.logger.log(
|
| 154 |
+
"Sending initialize request to R Language Server",
|
| 155 |
+
logging.INFO,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 159 |
+
|
| 160 |
+
# Verify server capabilities
|
| 161 |
+
capabilities = init_response.get("capabilities", {})
|
| 162 |
+
assert "textDocumentSync" in capabilities
|
| 163 |
+
if "completionProvider" in capabilities:
|
| 164 |
+
self.logger.log("R LSP completion provider available", logging.INFO)
|
| 165 |
+
if "definitionProvider" in capabilities:
|
| 166 |
+
self.logger.log("R LSP definition provider available", logging.INFO)
|
| 167 |
+
|
| 168 |
+
self.server.notify.initialized({})
|
| 169 |
+
self.completions_available.set()
|
| 170 |
+
|
| 171 |
+
# R Language Server is ready after initialization
|
| 172 |
+
self.server_ready.set()
|
projects/ui/serena-new/src/solidlsp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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Ruby LSP Language Server implementation using Shopify's ruby-lsp.
|
| 3 |
+
Provides modern Ruby language server capabilities with improved performance.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import pathlib
|
| 10 |
+
import shutil
|
| 11 |
+
import subprocess
|
| 12 |
+
import threading
|
| 13 |
+
|
| 14 |
+
from overrides import override
|
| 15 |
+
|
| 16 |
+
from solidlsp.ls import SolidLanguageServer
|
| 17 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 18 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 19 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 20 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 21 |
+
from solidlsp.settings import SolidLSPSettings
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class RubyLsp(SolidLanguageServer):
|
| 25 |
+
"""
|
| 26 |
+
Provides Ruby specific instantiation of the LanguageServer class using ruby-lsp.
|
| 27 |
+
Contains various configurations and settings specific to Ruby with modern LSP features.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
def __init__(
|
| 31 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 32 |
+
):
|
| 33 |
+
"""
|
| 34 |
+
Creates a RubyLsp instance. This class is not meant to be instantiated directly.
|
| 35 |
+
Use LanguageServer.create() instead.
|
| 36 |
+
"""
|
| 37 |
+
ruby_lsp_executable = self._setup_runtime_dependencies(logger, config, repository_root_path)
|
| 38 |
+
super().__init__(
|
| 39 |
+
config,
|
| 40 |
+
logger,
|
| 41 |
+
repository_root_path,
|
| 42 |
+
ProcessLaunchInfo(cmd=ruby_lsp_executable, cwd=repository_root_path),
|
| 43 |
+
"ruby",
|
| 44 |
+
solidlsp_settings,
|
| 45 |
+
)
|
| 46 |
+
self.analysis_complete = threading.Event()
|
| 47 |
+
self.service_ready_event = threading.Event()
|
| 48 |
+
|
| 49 |
+
# Set timeout for ruby-lsp requests - ruby-lsp is fast
|
| 50 |
+
self.set_request_timeout(30.0) # 30 seconds for initialization and requests
|
| 51 |
+
|
| 52 |
+
@override
|
| 53 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 54 |
+
"""Override to ignore Ruby-specific directories that cause performance issues."""
|
| 55 |
+
ruby_ignored_dirs = [
|
| 56 |
+
"vendor", # Ruby vendor directory
|
| 57 |
+
".bundle", # Bundler cache
|
| 58 |
+
"tmp", # Temporary files
|
| 59 |
+
"log", # Log files
|
| 60 |
+
"coverage", # Test coverage reports
|
| 61 |
+
".yardoc", # YARD documentation cache
|
| 62 |
+
"doc", # Generated documentation
|
| 63 |
+
"node_modules", # Node modules (for Rails with JS)
|
| 64 |
+
"storage", # Active Storage files (Rails)
|
| 65 |
+
"public/packs", # Webpacker output
|
| 66 |
+
"public/webpack", # Webpack output
|
| 67 |
+
"public/assets", # Rails compiled assets
|
| 68 |
+
]
|
| 69 |
+
return super().is_ignored_dirname(dirname) or dirname in ruby_ignored_dirs
|
| 70 |
+
|
| 71 |
+
@override
|
| 72 |
+
def _get_wait_time_for_cross_file_referencing(self) -> float:
|
| 73 |
+
"""Override to provide optimal wait time for ruby-lsp cross-file reference resolution.
|
| 74 |
+
|
| 75 |
+
ruby-lsp typically initializes quickly, but may need a brief moment
|
| 76 |
+
for cross-file analysis in larger projects.
|
| 77 |
+
"""
|
| 78 |
+
return 0.5 # 500ms should be sufficient for ruby-lsp
|
| 79 |
+
|
| 80 |
+
@staticmethod
|
| 81 |
+
def _find_executable_with_extensions(executable_name: str) -> str | None:
|
| 82 |
+
"""
|
| 83 |
+
Find executable with Windows-specific extensions (.bat, .cmd, .exe) if on Windows.
|
| 84 |
+
Returns the full path to the executable or None if not found.
|
| 85 |
+
"""
|
| 86 |
+
import platform
|
| 87 |
+
|
| 88 |
+
if platform.system() == "Windows":
|
| 89 |
+
# Try Windows-specific extensions first
|
| 90 |
+
for ext in [".bat", ".cmd", ".exe"]:
|
| 91 |
+
path = shutil.which(f"{executable_name}{ext}")
|
| 92 |
+
if path:
|
| 93 |
+
return path
|
| 94 |
+
# Fall back to default search
|
| 95 |
+
return shutil.which(executable_name)
|
| 96 |
+
else:
|
| 97 |
+
# Unix systems
|
| 98 |
+
return shutil.which(executable_name)
|
| 99 |
+
|
| 100 |
+
@staticmethod
|
| 101 |
+
def _setup_runtime_dependencies(logger: LanguageServerLogger, config: LanguageServerConfig, repository_root_path: str) -> list[str]:
|
| 102 |
+
"""
|
| 103 |
+
Setup runtime dependencies for ruby-lsp and return the command list to start the server.
|
| 104 |
+
Installation strategy: Bundler project > global ruby-lsp > gem install ruby-lsp
|
| 105 |
+
"""
|
| 106 |
+
# Check if Ruby is installed
|
| 107 |
+
try:
|
| 108 |
+
result = subprocess.run(["ruby", "--version"], check=True, capture_output=True, cwd=repository_root_path, text=True)
|
| 109 |
+
ruby_version = result.stdout.strip()
|
| 110 |
+
logger.log(f"Ruby version: {ruby_version}", logging.INFO)
|
| 111 |
+
|
| 112 |
+
# Extract version number for compatibility checks
|
| 113 |
+
import re
|
| 114 |
+
|
| 115 |
+
version_match = re.search(r"ruby (\d+)\.(\d+)\.(\d+)", ruby_version)
|
| 116 |
+
if version_match:
|
| 117 |
+
major, minor, patch = map(int, version_match.groups())
|
| 118 |
+
if major < 2 or (major == 2 and minor < 6):
|
| 119 |
+
logger.log(f"Warning: Ruby {major}.{minor}.{patch} detected. ruby-lsp works best with Ruby 2.6+", logging.WARNING)
|
| 120 |
+
|
| 121 |
+
except subprocess.CalledProcessError as e:
|
| 122 |
+
error_msg = e.stderr if isinstance(e.stderr, str) else e.stderr.decode() if e.stderr else "Unknown error"
|
| 123 |
+
raise RuntimeError(
|
| 124 |
+
f"Error checking Ruby installation: {error_msg}. Please ensure Ruby is properly installed and in PATH."
|
| 125 |
+
) from e
|
| 126 |
+
except FileNotFoundError as e:
|
| 127 |
+
raise RuntimeError(
|
| 128 |
+
"Ruby is not installed or not found in PATH. Please install Ruby using one of these methods:\n"
|
| 129 |
+
" - Using rbenv: rbenv install 3.0.0 && rbenv global 3.0.0\n"
|
| 130 |
+
" - Using RVM: rvm install 3.0.0 && rvm use 3.0.0 --default\n"
|
| 131 |
+
" - Using asdf: asdf install ruby 3.0.0 && asdf global ruby 3.0.0\n"
|
| 132 |
+
" - System package manager (brew install ruby, apt install ruby, etc.)"
|
| 133 |
+
) from e
|
| 134 |
+
|
| 135 |
+
# Check for Bundler project (Gemfile exists)
|
| 136 |
+
gemfile_path = os.path.join(repository_root_path, "Gemfile")
|
| 137 |
+
gemfile_lock_path = os.path.join(repository_root_path, "Gemfile.lock")
|
| 138 |
+
is_bundler_project = os.path.exists(gemfile_path)
|
| 139 |
+
|
| 140 |
+
if is_bundler_project:
|
| 141 |
+
logger.log("Detected Bundler project (Gemfile found)", logging.INFO)
|
| 142 |
+
|
| 143 |
+
# Check if bundle command is available using Windows-compatible search
|
| 144 |
+
bundle_path = RubyLsp._find_executable_with_extensions("bundle")
|
| 145 |
+
if not bundle_path:
|
| 146 |
+
# Try common bundle executables
|
| 147 |
+
for bundle_cmd in ["bin/bundle", "bundle"]:
|
| 148 |
+
if bundle_cmd.startswith("bin/"):
|
| 149 |
+
bundle_full_path = os.path.join(repository_root_path, bundle_cmd)
|
| 150 |
+
else:
|
| 151 |
+
bundle_full_path = RubyLsp._find_executable_with_extensions(bundle_cmd)
|
| 152 |
+
if bundle_full_path and os.path.exists(bundle_full_path):
|
| 153 |
+
bundle_path = bundle_full_path if bundle_cmd.startswith("bin/") else bundle_cmd
|
| 154 |
+
break
|
| 155 |
+
|
| 156 |
+
if not bundle_path:
|
| 157 |
+
logger.log(
|
| 158 |
+
"Bundler project detected but 'bundle' command not found. Falling back to global ruby-lsp installation.",
|
| 159 |
+
logging.WARNING,
|
| 160 |
+
)
|
| 161 |
+
else:
|
| 162 |
+
# Check if ruby-lsp is in Gemfile.lock
|
| 163 |
+
ruby_lsp_in_bundle = False
|
| 164 |
+
if os.path.exists(gemfile_lock_path):
|
| 165 |
+
try:
|
| 166 |
+
with open(gemfile_lock_path) as f:
|
| 167 |
+
content = f.read()
|
| 168 |
+
ruby_lsp_in_bundle = "ruby-lsp" in content.lower()
|
| 169 |
+
except Exception as e:
|
| 170 |
+
logger.log(f"Warning: Could not read Gemfile.lock: {e}", logging.WARNING)
|
| 171 |
+
|
| 172 |
+
if ruby_lsp_in_bundle:
|
| 173 |
+
logger.log("Found ruby-lsp in Gemfile.lock", logging.INFO)
|
| 174 |
+
return [bundle_path, "exec", "ruby-lsp"]
|
| 175 |
+
else:
|
| 176 |
+
logger.log(
|
| 177 |
+
"ruby-lsp not found in Gemfile.lock. Consider adding 'gem \"ruby-lsp\"' to your Gemfile for better compatibility.",
|
| 178 |
+
logging.INFO,
|
| 179 |
+
)
|
| 180 |
+
# Fall through to global installation check
|
| 181 |
+
|
| 182 |
+
# Check if ruby-lsp is available globally using Windows-compatible search
|
| 183 |
+
ruby_lsp_path = RubyLsp._find_executable_with_extensions("ruby-lsp")
|
| 184 |
+
if ruby_lsp_path:
|
| 185 |
+
logger.log(f"Found ruby-lsp at: {ruby_lsp_path}", logging.INFO)
|
| 186 |
+
return [ruby_lsp_path]
|
| 187 |
+
|
| 188 |
+
# Try to install ruby-lsp globally
|
| 189 |
+
logger.log("ruby-lsp not found, attempting to install globally...", logging.INFO)
|
| 190 |
+
try:
|
| 191 |
+
subprocess.run(["gem", "install", "ruby-lsp"], check=True, capture_output=True, cwd=repository_root_path)
|
| 192 |
+
logger.log("Successfully installed ruby-lsp globally", logging.INFO)
|
| 193 |
+
# Find the newly installed ruby-lsp executable
|
| 194 |
+
ruby_lsp_path = RubyLsp._find_executable_with_extensions("ruby-lsp")
|
| 195 |
+
return [ruby_lsp_path] if ruby_lsp_path else ["ruby-lsp"]
|
| 196 |
+
except subprocess.CalledProcessError as e:
|
| 197 |
+
error_msg = e.stderr if isinstance(e.stderr, str) else e.stderr.decode() if e.stderr else str(e)
|
| 198 |
+
if is_bundler_project:
|
| 199 |
+
raise RuntimeError(
|
| 200 |
+
f"Failed to install ruby-lsp globally: {error_msg}\n"
|
| 201 |
+
"For Bundler projects, please add 'gem \"ruby-lsp\"' to your Gemfile and run 'bundle install'.\n"
|
| 202 |
+
"Alternatively, install globally: gem install ruby-lsp"
|
| 203 |
+
) from e
|
| 204 |
+
raise RuntimeError(f"Failed to install ruby-lsp: {error_msg}\nPlease try installing manually: gem install ruby-lsp") from e
|
| 205 |
+
|
| 206 |
+
@staticmethod
|
| 207 |
+
def _detect_rails_project(repository_root_path: str) -> bool:
|
| 208 |
+
"""
|
| 209 |
+
Detect if this is a Rails project by checking for Rails-specific files.
|
| 210 |
+
"""
|
| 211 |
+
rails_indicators = [
|
| 212 |
+
"config/application.rb",
|
| 213 |
+
"config/environment.rb",
|
| 214 |
+
"app/controllers/application_controller.rb",
|
| 215 |
+
"Rakefile",
|
| 216 |
+
]
|
| 217 |
+
|
| 218 |
+
for indicator in rails_indicators:
|
| 219 |
+
if os.path.exists(os.path.join(repository_root_path, indicator)):
|
| 220 |
+
return True
|
| 221 |
+
|
| 222 |
+
# Check for Rails in Gemfile
|
| 223 |
+
gemfile_path = os.path.join(repository_root_path, "Gemfile")
|
| 224 |
+
if os.path.exists(gemfile_path):
|
| 225 |
+
try:
|
| 226 |
+
with open(gemfile_path) as f:
|
| 227 |
+
content = f.read().lower()
|
| 228 |
+
if "gem 'rails'" in content or 'gem "rails"' in content:
|
| 229 |
+
return True
|
| 230 |
+
except Exception:
|
| 231 |
+
pass
|
| 232 |
+
|
| 233 |
+
return False
|
| 234 |
+
|
| 235 |
+
@staticmethod
|
| 236 |
+
def _get_ruby_exclude_patterns(repository_root_path: str) -> list[str]:
|
| 237 |
+
"""
|
| 238 |
+
Get Ruby and Rails-specific exclude patterns for better performance.
|
| 239 |
+
"""
|
| 240 |
+
base_patterns = [
|
| 241 |
+
"**/vendor/**", # Ruby vendor directory
|
| 242 |
+
"**/.bundle/**", # Bundler cache
|
| 243 |
+
"**/tmp/**", # Temporary files
|
| 244 |
+
"**/log/**", # Log files
|
| 245 |
+
"**/coverage/**", # Test coverage reports
|
| 246 |
+
"**/.yardoc/**", # YARD documentation cache
|
| 247 |
+
"**/doc/**", # Generated documentation
|
| 248 |
+
"**/.git/**", # Git directory
|
| 249 |
+
"**/node_modules/**", # Node modules (for Rails with JS)
|
| 250 |
+
"**/public/assets/**", # Rails compiled assets
|
| 251 |
+
]
|
| 252 |
+
|
| 253 |
+
# Add Rails-specific patterns if this is a Rails project
|
| 254 |
+
if RubyLsp._detect_rails_project(repository_root_path):
|
| 255 |
+
base_patterns.extend(
|
| 256 |
+
[
|
| 257 |
+
"**/app/assets/builds/**", # Rails 7+ CSS builds
|
| 258 |
+
"**/storage/**", # Active Storage
|
| 259 |
+
"**/public/packs/**", # Webpacker
|
| 260 |
+
"**/public/webpack/**", # Webpack
|
| 261 |
+
]
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
return base_patterns
|
| 265 |
+
|
| 266 |
+
def _get_initialize_params(self) -> InitializeParams:
|
| 267 |
+
"""
|
| 268 |
+
Returns ruby-lsp specific initialization parameters.
|
| 269 |
+
"""
|
| 270 |
+
exclude_patterns = self._get_ruby_exclude_patterns(self.repository_root_path)
|
| 271 |
+
|
| 272 |
+
initialize_params = {
|
| 273 |
+
"processId": os.getpid(),
|
| 274 |
+
"rootPath": self.repository_root_path,
|
| 275 |
+
"rootUri": pathlib.Path(self.repository_root_path).as_uri(),
|
| 276 |
+
"capabilities": {
|
| 277 |
+
"workspace": {
|
| 278 |
+
"workspaceEdit": {"documentChanges": True},
|
| 279 |
+
"configuration": True,
|
| 280 |
+
},
|
| 281 |
+
"window": {
|
| 282 |
+
"workDoneProgress": True,
|
| 283 |
+
},
|
| 284 |
+
"textDocument": {
|
| 285 |
+
"documentSymbol": {
|
| 286 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 287 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 288 |
+
},
|
| 289 |
+
"completion": {
|
| 290 |
+
"completionItem": {
|
| 291 |
+
"snippetSupport": True,
|
| 292 |
+
"commitCharactersSupport": True,
|
| 293 |
+
}
|
| 294 |
+
},
|
| 295 |
+
},
|
| 296 |
+
},
|
| 297 |
+
"initializationOptions": {
|
| 298 |
+
# ruby-lsp enables all features by default, so we don't need to specify enabledFeatures
|
| 299 |
+
"experimentalFeaturesEnabled": False,
|
| 300 |
+
"featuresConfiguration": {},
|
| 301 |
+
"indexing": {
|
| 302 |
+
"includedPatterns": ["**/*.rb", "**/*.rake", "**/*.ru", "**/*.erb"],
|
| 303 |
+
"excludedPatterns": exclude_patterns,
|
| 304 |
+
},
|
| 305 |
+
},
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
return initialize_params
|
| 309 |
+
|
| 310 |
+
def _start_server(self) -> None:
|
| 311 |
+
"""
|
| 312 |
+
Starts the ruby-lsp Language Server for Ruby
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
def register_capability_handler(params: dict) -> None:
|
| 316 |
+
assert "registrations" in params
|
| 317 |
+
for registration in params["registrations"]:
|
| 318 |
+
self.logger.log(f"Registered capability: {registration['method']}", logging.INFO)
|
| 319 |
+
return
|
| 320 |
+
|
| 321 |
+
def lang_status_handler(params: dict) -> None:
|
| 322 |
+
self.logger.log(f"LSP: language/status: {params}", logging.INFO)
|
| 323 |
+
if params.get("type") == "ready":
|
| 324 |
+
self.logger.log("ruby-lsp service is ready.", logging.INFO)
|
| 325 |
+
self.analysis_complete.set()
|
| 326 |
+
self.completions_available.set()
|
| 327 |
+
|
| 328 |
+
def execute_client_command_handler(params: dict) -> list:
|
| 329 |
+
return []
|
| 330 |
+
|
| 331 |
+
def do_nothing(params: dict) -> None:
|
| 332 |
+
return
|
| 333 |
+
|
| 334 |
+
def window_log_message(msg: dict) -> None:
|
| 335 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 336 |
+
|
| 337 |
+
def progress_handler(params: dict) -> None:
|
| 338 |
+
# ruby-lsp sends progress notifications during indexing
|
| 339 |
+
self.logger.log(f"LSP: $/progress: {params}", logging.DEBUG)
|
| 340 |
+
if "value" in params:
|
| 341 |
+
value = params["value"]
|
| 342 |
+
# Check for completion indicators
|
| 343 |
+
if value.get("kind") == "end":
|
| 344 |
+
self.logger.log("ruby-lsp indexing complete ($/progress end)", logging.INFO)
|
| 345 |
+
self.analysis_complete.set()
|
| 346 |
+
self.completions_available.set()
|
| 347 |
+
elif value.get("kind") == "begin":
|
| 348 |
+
self.logger.log("ruby-lsp indexing started ($/progress begin)", logging.INFO)
|
| 349 |
+
elif "percentage" in value:
|
| 350 |
+
percentage = value.get("percentage", 0)
|
| 351 |
+
self.logger.log(f"ruby-lsp indexing progress: {percentage}%", logging.DEBUG)
|
| 352 |
+
# Handle direct progress format (fallback)
|
| 353 |
+
elif "token" in params and "value" in params:
|
| 354 |
+
token = params.get("token")
|
| 355 |
+
if isinstance(token, str) and "indexing" in token.lower():
|
| 356 |
+
value = params.get("value", {})
|
| 357 |
+
if value.get("kind") == "end" or value.get("percentage") == 100:
|
| 358 |
+
self.logger.log("ruby-lsp indexing complete (token progress)", logging.INFO)
|
| 359 |
+
self.analysis_complete.set()
|
| 360 |
+
self.completions_available.set()
|
| 361 |
+
|
| 362 |
+
def window_work_done_progress_create(params: dict) -> None:
|
| 363 |
+
"""Handle workDoneProgress/create requests from ruby-lsp"""
|
| 364 |
+
self.logger.log(f"LSP: window/workDoneProgress/create: {params}", logging.DEBUG)
|
| 365 |
+
return {}
|
| 366 |
+
|
| 367 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 368 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 369 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 370 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 371 |
+
self.server.on_notification("$/progress", progress_handler)
|
| 372 |
+
self.server.on_request("window/workDoneProgress/create", window_work_done_progress_create)
|
| 373 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 374 |
+
|
| 375 |
+
self.logger.log("Starting ruby-lsp server process", logging.INFO)
|
| 376 |
+
self.server.start()
|
| 377 |
+
initialize_params = self._get_initialize_params()
|
| 378 |
+
|
| 379 |
+
self.logger.log(
|
| 380 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 381 |
+
logging.INFO,
|
| 382 |
+
)
|
| 383 |
+
self.logger.log(f"Sending init params: {json.dumps(initialize_params, indent=4)}", logging.INFO)
|
| 384 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 385 |
+
self.logger.log(f"Received init response: {init_response}", logging.INFO)
|
| 386 |
+
|
| 387 |
+
# Verify expected capabilities
|
| 388 |
+
# Note: ruby-lsp may return textDocumentSync in different formats (number or object)
|
| 389 |
+
text_document_sync = init_response["capabilities"].get("textDocumentSync")
|
| 390 |
+
if isinstance(text_document_sync, int):
|
| 391 |
+
assert text_document_sync in [1, 2], f"Unexpected textDocumentSync value: {text_document_sync}"
|
| 392 |
+
elif isinstance(text_document_sync, dict):
|
| 393 |
+
# ruby-lsp returns an object with change property
|
| 394 |
+
assert "change" in text_document_sync, "textDocumentSync object should have 'change' property"
|
| 395 |
+
|
| 396 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 397 |
+
|
| 398 |
+
self.server.notify.initialized({})
|
| 399 |
+
# Wait for ruby-lsp to complete its initial indexing
|
| 400 |
+
# ruby-lsp has fast indexing
|
| 401 |
+
self.logger.log("Waiting for ruby-lsp to complete initial indexing...", logging.INFO)
|
| 402 |
+
if self.analysis_complete.wait(timeout=30.0):
|
| 403 |
+
self.logger.log("ruby-lsp initial indexing complete, server ready", logging.INFO)
|
| 404 |
+
else:
|
| 405 |
+
self.logger.log("Timeout waiting for ruby-lsp indexing completion, proceeding anyway", logging.WARNING)
|
| 406 |
+
# Fallback: assume indexing is complete after timeout
|
| 407 |
+
self.analysis_complete.set()
|
| 408 |
+
self.completions_available.set()
|
| 409 |
+
|
| 410 |
+
def _handle_initialization_response(self, init_response):
|
| 411 |
+
"""
|
| 412 |
+
Handle the initialization response from ruby-lsp and validate capabilities.
|
| 413 |
+
"""
|
| 414 |
+
if "capabilities" in init_response:
|
| 415 |
+
capabilities = init_response["capabilities"]
|
| 416 |
+
|
| 417 |
+
# Validate textDocumentSync (ruby-lsp may return different formats)
|
| 418 |
+
text_document_sync = capabilities.get("textDocumentSync")
|
| 419 |
+
if isinstance(text_document_sync, int):
|
| 420 |
+
assert text_document_sync in [1, 2], f"Unexpected textDocumentSync value: {text_document_sync}"
|
| 421 |
+
elif isinstance(text_document_sync, dict):
|
| 422 |
+
# ruby-lsp returns an object with change property
|
| 423 |
+
assert "change" in text_document_sync, "textDocumentSync object should have 'change' property"
|
| 424 |
+
|
| 425 |
+
# Log important capabilities
|
| 426 |
+
important_capabilities = [
|
| 427 |
+
"completionProvider",
|
| 428 |
+
"hoverProvider",
|
| 429 |
+
"definitionProvider",
|
| 430 |
+
"referencesProvider",
|
| 431 |
+
"documentSymbolProvider",
|
| 432 |
+
"codeActionProvider",
|
| 433 |
+
"documentFormattingProvider",
|
| 434 |
+
"semanticTokensProvider",
|
| 435 |
+
]
|
| 436 |
+
|
| 437 |
+
for cap in important_capabilities:
|
| 438 |
+
if cap in capabilities:
|
| 439 |
+
self.logger.log(f"ruby-lsp {cap}: available", logging.DEBUG)
|
| 440 |
+
|
| 441 |
+
# Signal that the service is ready
|
| 442 |
+
self.service_ready_event.set()
|
projects/ui/serena-new/src/solidlsp/language_servers/rust_analyzer.py
ADDED
|
@@ -0,0 +1,639 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Rust specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Rust.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import shutil
|
| 9 |
+
import subprocess
|
| 10 |
+
import threading
|
| 11 |
+
|
| 12 |
+
from overrides import override
|
| 13 |
+
|
| 14 |
+
from solidlsp.ls import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 16 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 17 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 18 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 19 |
+
from solidlsp.settings import SolidLSPSettings
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class RustAnalyzer(SolidLanguageServer):
|
| 23 |
+
"""
|
| 24 |
+
Provides Rust specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Rust.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
@staticmethod
|
| 28 |
+
def _get_rustup_version():
|
| 29 |
+
"""Get installed rustup version or None if not found."""
|
| 30 |
+
try:
|
| 31 |
+
result = subprocess.run(["rustup", "--version"], capture_output=True, text=True, check=False)
|
| 32 |
+
if result.returncode == 0:
|
| 33 |
+
return result.stdout.strip()
|
| 34 |
+
except FileNotFoundError:
|
| 35 |
+
return None
|
| 36 |
+
return None
|
| 37 |
+
|
| 38 |
+
@staticmethod
|
| 39 |
+
def _get_rust_analyzer_path():
|
| 40 |
+
"""Get rust-analyzer path via rustup or system PATH."""
|
| 41 |
+
# First try rustup
|
| 42 |
+
try:
|
| 43 |
+
result = subprocess.run(["rustup", "which", "rust-analyzer"], capture_output=True, text=True, check=False)
|
| 44 |
+
if result.returncode == 0:
|
| 45 |
+
return result.stdout.strip()
|
| 46 |
+
except FileNotFoundError:
|
| 47 |
+
pass
|
| 48 |
+
|
| 49 |
+
# Fallback to system PATH
|
| 50 |
+
return shutil.which("rust-analyzer")
|
| 51 |
+
|
| 52 |
+
@staticmethod
|
| 53 |
+
def _ensure_rust_analyzer_installed():
|
| 54 |
+
"""Ensure rust-analyzer is available, install via rustup if needed."""
|
| 55 |
+
path = RustAnalyzer._get_rust_analyzer_path()
|
| 56 |
+
if path:
|
| 57 |
+
return path
|
| 58 |
+
|
| 59 |
+
# Check if rustup is available
|
| 60 |
+
if not RustAnalyzer._get_rustup_version():
|
| 61 |
+
raise RuntimeError(
|
| 62 |
+
"Neither rust-analyzer nor rustup is installed.\n"
|
| 63 |
+
"Please install Rust via https://rustup.rs/ or install rust-analyzer separately."
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Try to install rust-analyzer component
|
| 67 |
+
result = subprocess.run(["rustup", "component", "add", "rust-analyzer"], check=False, capture_output=True, text=True)
|
| 68 |
+
if result.returncode != 0:
|
| 69 |
+
raise RuntimeError(f"Failed to install rust-analyzer via rustup: {result.stderr}")
|
| 70 |
+
|
| 71 |
+
# Try again after installation
|
| 72 |
+
path = RustAnalyzer._get_rust_analyzer_path()
|
| 73 |
+
if not path:
|
| 74 |
+
raise RuntimeError("rust-analyzer installation succeeded but binary not found in PATH")
|
| 75 |
+
|
| 76 |
+
return path
|
| 77 |
+
|
| 78 |
+
def __init__(
|
| 79 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 80 |
+
):
|
| 81 |
+
"""
|
| 82 |
+
Creates a RustAnalyzer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 83 |
+
"""
|
| 84 |
+
rustanalyzer_executable_path = self._ensure_rust_analyzer_installed()
|
| 85 |
+
logger.log(f"Using rust-analyzer at: {rustanalyzer_executable_path}", logging.INFO)
|
| 86 |
+
|
| 87 |
+
super().__init__(
|
| 88 |
+
config,
|
| 89 |
+
logger,
|
| 90 |
+
repository_root_path,
|
| 91 |
+
ProcessLaunchInfo(cmd=rustanalyzer_executable_path, cwd=repository_root_path),
|
| 92 |
+
"rust",
|
| 93 |
+
solidlsp_settings,
|
| 94 |
+
)
|
| 95 |
+
self.server_ready = threading.Event()
|
| 96 |
+
self.service_ready_event = threading.Event()
|
| 97 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 98 |
+
self.resolve_main_method_available = threading.Event()
|
| 99 |
+
|
| 100 |
+
@override
|
| 101 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 102 |
+
return super().is_ignored_dirname(dirname) or dirname in ["target"]
|
| 103 |
+
|
| 104 |
+
@staticmethod
|
| 105 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 106 |
+
"""
|
| 107 |
+
Returns the initialize params for the Rust Analyzer Language Server.
|
| 108 |
+
"""
|
| 109 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 110 |
+
initialize_params = {
|
| 111 |
+
"clientInfo": {"name": "Visual Studio Code - Insiders", "version": "1.82.0-insider"},
|
| 112 |
+
"locale": "en",
|
| 113 |
+
"capabilities": {
|
| 114 |
+
"workspace": {
|
| 115 |
+
"applyEdit": True,
|
| 116 |
+
"workspaceEdit": {
|
| 117 |
+
"documentChanges": True,
|
| 118 |
+
"resourceOperations": ["create", "rename", "delete"],
|
| 119 |
+
"failureHandling": "textOnlyTransactional",
|
| 120 |
+
"normalizesLineEndings": True,
|
| 121 |
+
"changeAnnotationSupport": {"groupsOnLabel": True},
|
| 122 |
+
},
|
| 123 |
+
"configuration": True,
|
| 124 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True, "relativePatternSupport": True},
|
| 125 |
+
"symbol": {
|
| 126 |
+
"dynamicRegistration": True,
|
| 127 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 128 |
+
"tagSupport": {"valueSet": [1]},
|
| 129 |
+
"resolveSupport": {"properties": ["location.range"]},
|
| 130 |
+
},
|
| 131 |
+
"codeLens": {"refreshSupport": True},
|
| 132 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 133 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 134 |
+
"workspaceFolders": True,
|
| 135 |
+
"semanticTokens": {"refreshSupport": True},
|
| 136 |
+
"fileOperations": {
|
| 137 |
+
"dynamicRegistration": True,
|
| 138 |
+
"didCreate": True,
|
| 139 |
+
"didRename": True,
|
| 140 |
+
"didDelete": True,
|
| 141 |
+
"willCreate": True,
|
| 142 |
+
"willRename": True,
|
| 143 |
+
"willDelete": True,
|
| 144 |
+
},
|
| 145 |
+
"inlineValue": {"refreshSupport": True},
|
| 146 |
+
"inlayHint": {"refreshSupport": True},
|
| 147 |
+
"diagnostics": {"refreshSupport": True},
|
| 148 |
+
},
|
| 149 |
+
"textDocument": {
|
| 150 |
+
"publishDiagnostics": {
|
| 151 |
+
"relatedInformation": True,
|
| 152 |
+
"versionSupport": False,
|
| 153 |
+
"tagSupport": {"valueSet": [1, 2]},
|
| 154 |
+
"codeDescriptionSupport": True,
|
| 155 |
+
"dataSupport": True,
|
| 156 |
+
},
|
| 157 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 158 |
+
"completion": {
|
| 159 |
+
"dynamicRegistration": True,
|
| 160 |
+
"contextSupport": True,
|
| 161 |
+
"completionItem": {
|
| 162 |
+
"snippetSupport": True,
|
| 163 |
+
"commitCharactersSupport": True,
|
| 164 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 165 |
+
"deprecatedSupport": True,
|
| 166 |
+
"preselectSupport": True,
|
| 167 |
+
"tagSupport": {"valueSet": [1]},
|
| 168 |
+
"insertReplaceSupport": True,
|
| 169 |
+
"resolveSupport": {"properties": ["documentation", "detail", "additionalTextEdits"]},
|
| 170 |
+
"insertTextModeSupport": {"valueSet": [1, 2]},
|
| 171 |
+
"labelDetailsSupport": True,
|
| 172 |
+
},
|
| 173 |
+
"insertTextMode": 2,
|
| 174 |
+
"completionItemKind": {
|
| 175 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
| 176 |
+
},
|
| 177 |
+
"completionList": {"itemDefaults": ["commitCharacters", "editRange", "insertTextFormat", "insertTextMode"]},
|
| 178 |
+
},
|
| 179 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 180 |
+
"signatureHelp": {
|
| 181 |
+
"dynamicRegistration": True,
|
| 182 |
+
"signatureInformation": {
|
| 183 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 184 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 185 |
+
"activeParameterSupport": True,
|
| 186 |
+
},
|
| 187 |
+
"contextSupport": True,
|
| 188 |
+
},
|
| 189 |
+
"definition": {"dynamicRegistration": True, "linkSupport": True},
|
| 190 |
+
"references": {"dynamicRegistration": True},
|
| 191 |
+
"documentHighlight": {"dynamicRegistration": True},
|
| 192 |
+
"documentSymbol": {
|
| 193 |
+
"dynamicRegistration": True,
|
| 194 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 195 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 196 |
+
"tagSupport": {"valueSet": [1]},
|
| 197 |
+
"labelSupport": True,
|
| 198 |
+
},
|
| 199 |
+
"codeAction": {
|
| 200 |
+
"dynamicRegistration": True,
|
| 201 |
+
"isPreferredSupport": True,
|
| 202 |
+
"disabledSupport": True,
|
| 203 |
+
"dataSupport": True,
|
| 204 |
+
"resolveSupport": {"properties": ["edit"]},
|
| 205 |
+
"codeActionLiteralSupport": {
|
| 206 |
+
"codeActionKind": {
|
| 207 |
+
"valueSet": [
|
| 208 |
+
"",
|
| 209 |
+
"quickfix",
|
| 210 |
+
"refactor",
|
| 211 |
+
"refactor.extract",
|
| 212 |
+
"refactor.inline",
|
| 213 |
+
"refactor.rewrite",
|
| 214 |
+
"source",
|
| 215 |
+
"source.organizeImports",
|
| 216 |
+
]
|
| 217 |
+
}
|
| 218 |
+
},
|
| 219 |
+
"honorsChangeAnnotations": False,
|
| 220 |
+
},
|
| 221 |
+
"codeLens": {"dynamicRegistration": True},
|
| 222 |
+
"formatting": {"dynamicRegistration": True},
|
| 223 |
+
"rangeFormatting": {"dynamicRegistration": True},
|
| 224 |
+
"onTypeFormatting": {"dynamicRegistration": True},
|
| 225 |
+
"rename": {
|
| 226 |
+
"dynamicRegistration": True,
|
| 227 |
+
"prepareSupport": True,
|
| 228 |
+
"prepareSupportDefaultBehavior": 1,
|
| 229 |
+
"honorsChangeAnnotations": True,
|
| 230 |
+
},
|
| 231 |
+
"documentLink": {"dynamicRegistration": True, "tooltipSupport": True},
|
| 232 |
+
"typeDefinition": {"dynamicRegistration": True, "linkSupport": True},
|
| 233 |
+
"implementation": {"dynamicRegistration": True, "linkSupport": True},
|
| 234 |
+
"colorProvider": {"dynamicRegistration": True},
|
| 235 |
+
"foldingRange": {
|
| 236 |
+
"dynamicRegistration": True,
|
| 237 |
+
"rangeLimit": 5000,
|
| 238 |
+
"lineFoldingOnly": True,
|
| 239 |
+
"foldingRangeKind": {"valueSet": ["comment", "imports", "region"]},
|
| 240 |
+
"foldingRange": {"collapsedText": False},
|
| 241 |
+
},
|
| 242 |
+
"declaration": {"dynamicRegistration": True, "linkSupport": True},
|
| 243 |
+
"selectionRange": {"dynamicRegistration": True},
|
| 244 |
+
"callHierarchy": {"dynamicRegistration": True},
|
| 245 |
+
"semanticTokens": {
|
| 246 |
+
"dynamicRegistration": True,
|
| 247 |
+
"tokenTypes": [
|
| 248 |
+
"namespace",
|
| 249 |
+
"type",
|
| 250 |
+
"class",
|
| 251 |
+
"enum",
|
| 252 |
+
"interface",
|
| 253 |
+
"struct",
|
| 254 |
+
"typeParameter",
|
| 255 |
+
"parameter",
|
| 256 |
+
"variable",
|
| 257 |
+
"property",
|
| 258 |
+
"enumMember",
|
| 259 |
+
"event",
|
| 260 |
+
"function",
|
| 261 |
+
"method",
|
| 262 |
+
"macro",
|
| 263 |
+
"keyword",
|
| 264 |
+
"modifier",
|
| 265 |
+
"comment",
|
| 266 |
+
"string",
|
| 267 |
+
"number",
|
| 268 |
+
"regexp",
|
| 269 |
+
"operator",
|
| 270 |
+
"decorator",
|
| 271 |
+
],
|
| 272 |
+
"tokenModifiers": [
|
| 273 |
+
"declaration",
|
| 274 |
+
"definition",
|
| 275 |
+
"readonly",
|
| 276 |
+
"static",
|
| 277 |
+
"deprecated",
|
| 278 |
+
"abstract",
|
| 279 |
+
"async",
|
| 280 |
+
"modification",
|
| 281 |
+
"documentation",
|
| 282 |
+
"defaultLibrary",
|
| 283 |
+
],
|
| 284 |
+
"formats": ["relative"],
|
| 285 |
+
"requests": {"range": True, "full": {"delta": True}},
|
| 286 |
+
"multilineTokenSupport": False,
|
| 287 |
+
"overlappingTokenSupport": False,
|
| 288 |
+
"serverCancelSupport": True,
|
| 289 |
+
"augmentsSyntaxTokens": False,
|
| 290 |
+
},
|
| 291 |
+
"linkedEditingRange": {"dynamicRegistration": True},
|
| 292 |
+
"typeHierarchy": {"dynamicRegistration": True},
|
| 293 |
+
"inlineValue": {"dynamicRegistration": True},
|
| 294 |
+
"inlayHint": {
|
| 295 |
+
"dynamicRegistration": True,
|
| 296 |
+
"resolveSupport": {"properties": ["tooltip", "textEdits", "label.tooltip", "label.location", "label.command"]},
|
| 297 |
+
},
|
| 298 |
+
"diagnostic": {"dynamicRegistration": True, "relatedDocumentSupport": False},
|
| 299 |
+
},
|
| 300 |
+
"window": {
|
| 301 |
+
"showMessage": {"messageActionItem": {"additionalPropertiesSupport": True}},
|
| 302 |
+
"showDocument": {"support": True},
|
| 303 |
+
"workDoneProgress": True,
|
| 304 |
+
},
|
| 305 |
+
"general": {
|
| 306 |
+
"staleRequestSupport": {
|
| 307 |
+
"cancel": True,
|
| 308 |
+
"retryOnContentModified": [
|
| 309 |
+
"textDocument/semanticTokens/full",
|
| 310 |
+
"textDocument/semanticTokens/range",
|
| 311 |
+
"textDocument/semanticTokens/full/delta",
|
| 312 |
+
],
|
| 313 |
+
},
|
| 314 |
+
"regularExpressions": {"engine": "ECMAScript", "version": "ES2020"},
|
| 315 |
+
"markdown": {
|
| 316 |
+
"parser": "marked",
|
| 317 |
+
"version": "1.1.0",
|
| 318 |
+
"allowedTags": [
|
| 319 |
+
"ul",
|
| 320 |
+
"li",
|
| 321 |
+
"p",
|
| 322 |
+
"code",
|
| 323 |
+
"blockquote",
|
| 324 |
+
"ol",
|
| 325 |
+
"h1",
|
| 326 |
+
"h2",
|
| 327 |
+
"h3",
|
| 328 |
+
"h4",
|
| 329 |
+
"h5",
|
| 330 |
+
"h6",
|
| 331 |
+
"hr",
|
| 332 |
+
"em",
|
| 333 |
+
"pre",
|
| 334 |
+
"table",
|
| 335 |
+
"thead",
|
| 336 |
+
"tbody",
|
| 337 |
+
"tr",
|
| 338 |
+
"th",
|
| 339 |
+
"td",
|
| 340 |
+
"div",
|
| 341 |
+
"del",
|
| 342 |
+
"a",
|
| 343 |
+
"strong",
|
| 344 |
+
"br",
|
| 345 |
+
"img",
|
| 346 |
+
"span",
|
| 347 |
+
],
|
| 348 |
+
},
|
| 349 |
+
"positionEncodings": ["utf-16"],
|
| 350 |
+
},
|
| 351 |
+
"notebookDocument": {"synchronization": {"dynamicRegistration": True, "executionSummarySupport": True}},
|
| 352 |
+
"experimental": {
|
| 353 |
+
"snippetTextEdit": True,
|
| 354 |
+
"codeActionGroup": True,
|
| 355 |
+
"hoverActions": True,
|
| 356 |
+
"serverStatusNotification": True,
|
| 357 |
+
"colorDiagnosticOutput": True,
|
| 358 |
+
"openServerLogs": True,
|
| 359 |
+
"localDocs": True,
|
| 360 |
+
"commands": {
|
| 361 |
+
"commands": [
|
| 362 |
+
"rust-analyzer.runSingle",
|
| 363 |
+
"rust-analyzer.debugSingle",
|
| 364 |
+
"rust-analyzer.showReferences",
|
| 365 |
+
"rust-analyzer.gotoLocation",
|
| 366 |
+
"editor.action.triggerParameterHints",
|
| 367 |
+
]
|
| 368 |
+
},
|
| 369 |
+
},
|
| 370 |
+
},
|
| 371 |
+
"initializationOptions": {
|
| 372 |
+
"cargoRunner": None,
|
| 373 |
+
"runnables": {"extraEnv": None, "problemMatcher": ["$rustc"], "command": None, "extraArgs": []},
|
| 374 |
+
"statusBar": {"clickAction": "openLogs"},
|
| 375 |
+
"server": {"path": None, "extraEnv": None},
|
| 376 |
+
"trace": {"server": "verbose", "extension": False},
|
| 377 |
+
"debug": {
|
| 378 |
+
"engine": "auto",
|
| 379 |
+
"sourceFileMap": {"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"},
|
| 380 |
+
"openDebugPane": False,
|
| 381 |
+
"engineSettings": {},
|
| 382 |
+
},
|
| 383 |
+
"restartServerOnConfigChange": False,
|
| 384 |
+
"typing": {"continueCommentsOnNewline": True, "autoClosingAngleBrackets": {"enable": False}},
|
| 385 |
+
"diagnostics": {
|
| 386 |
+
"previewRustcOutput": False,
|
| 387 |
+
"useRustcErrorCode": False,
|
| 388 |
+
"disabled": [],
|
| 389 |
+
"enable": True,
|
| 390 |
+
"experimental": {"enable": False},
|
| 391 |
+
"remapPrefix": {},
|
| 392 |
+
"warningsAsHint": [],
|
| 393 |
+
"warningsAsInfo": [],
|
| 394 |
+
},
|
| 395 |
+
"discoverProjectRunner": None,
|
| 396 |
+
"showUnlinkedFileNotification": True,
|
| 397 |
+
"showDependenciesExplorer": True,
|
| 398 |
+
"assist": {"emitMustUse": False, "expressionFillDefault": "todo"},
|
| 399 |
+
"cachePriming": {"enable": True, "numThreads": 0},
|
| 400 |
+
"cargo": {
|
| 401 |
+
"autoreload": True,
|
| 402 |
+
"buildScripts": {
|
| 403 |
+
"enable": True,
|
| 404 |
+
"invocationLocation": "workspace",
|
| 405 |
+
"invocationStrategy": "per_workspace",
|
| 406 |
+
"overrideCommand": None,
|
| 407 |
+
"useRustcWrapper": True,
|
| 408 |
+
},
|
| 409 |
+
"cfgs": {},
|
| 410 |
+
"extraArgs": [],
|
| 411 |
+
"extraEnv": {},
|
| 412 |
+
"features": [],
|
| 413 |
+
"noDefaultFeatures": False,
|
| 414 |
+
"sysroot": "discover",
|
| 415 |
+
"sysrootSrc": None,
|
| 416 |
+
"target": None,
|
| 417 |
+
"unsetTest": ["core"],
|
| 418 |
+
},
|
| 419 |
+
"checkOnSave": True,
|
| 420 |
+
"check": {
|
| 421 |
+
"allTargets": True,
|
| 422 |
+
"command": "check",
|
| 423 |
+
"extraArgs": [],
|
| 424 |
+
"extraEnv": {},
|
| 425 |
+
"features": None,
|
| 426 |
+
"ignore": [],
|
| 427 |
+
"invocationLocation": "workspace",
|
| 428 |
+
"invocationStrategy": "per_workspace",
|
| 429 |
+
"noDefaultFeatures": None,
|
| 430 |
+
"overrideCommand": None,
|
| 431 |
+
"targets": None,
|
| 432 |
+
},
|
| 433 |
+
"completion": {
|
| 434 |
+
"autoimport": {"enable": True},
|
| 435 |
+
"autoself": {"enable": True},
|
| 436 |
+
"callable": {"snippets": "fill_arguments"},
|
| 437 |
+
"fullFunctionSignatures": {"enable": False},
|
| 438 |
+
"limit": None,
|
| 439 |
+
"postfix": {"enable": True},
|
| 440 |
+
"privateEditable": {"enable": False},
|
| 441 |
+
"snippets": {
|
| 442 |
+
"custom": {
|
| 443 |
+
"Arc::new": {
|
| 444 |
+
"postfix": "arc",
|
| 445 |
+
"body": "Arc::new(${receiver})",
|
| 446 |
+
"requires": "std::sync::Arc",
|
| 447 |
+
"description": "Put the expression into an `Arc`",
|
| 448 |
+
"scope": "expr",
|
| 449 |
+
},
|
| 450 |
+
"Rc::new": {
|
| 451 |
+
"postfix": "rc",
|
| 452 |
+
"body": "Rc::new(${receiver})",
|
| 453 |
+
"requires": "std::rc::Rc",
|
| 454 |
+
"description": "Put the expression into an `Rc`",
|
| 455 |
+
"scope": "expr",
|
| 456 |
+
},
|
| 457 |
+
"Box::pin": {
|
| 458 |
+
"postfix": "pinbox",
|
| 459 |
+
"body": "Box::pin(${receiver})",
|
| 460 |
+
"requires": "std::boxed::Box",
|
| 461 |
+
"description": "Put the expression into a pinned `Box`",
|
| 462 |
+
"scope": "expr",
|
| 463 |
+
},
|
| 464 |
+
"Ok": {
|
| 465 |
+
"postfix": "ok",
|
| 466 |
+
"body": "Ok(${receiver})",
|
| 467 |
+
"description": "Wrap the expression in a `Result::Ok`",
|
| 468 |
+
"scope": "expr",
|
| 469 |
+
},
|
| 470 |
+
"Err": {
|
| 471 |
+
"postfix": "err",
|
| 472 |
+
"body": "Err(${receiver})",
|
| 473 |
+
"description": "Wrap the expression in a `Result::Err`",
|
| 474 |
+
"scope": "expr",
|
| 475 |
+
},
|
| 476 |
+
"Some": {
|
| 477 |
+
"postfix": "some",
|
| 478 |
+
"body": "Some(${receiver})",
|
| 479 |
+
"description": "Wrap the expression in an `Option::Some`",
|
| 480 |
+
"scope": "expr",
|
| 481 |
+
},
|
| 482 |
+
}
|
| 483 |
+
},
|
| 484 |
+
},
|
| 485 |
+
"files": {"excludeDirs": [], "watcher": "client"},
|
| 486 |
+
"highlightRelated": {
|
| 487 |
+
"breakPoints": {"enable": True},
|
| 488 |
+
"closureCaptures": {"enable": True},
|
| 489 |
+
"exitPoints": {"enable": True},
|
| 490 |
+
"references": {"enable": True},
|
| 491 |
+
"yieldPoints": {"enable": True},
|
| 492 |
+
},
|
| 493 |
+
"hover": {
|
| 494 |
+
"actions": {
|
| 495 |
+
"debug": {"enable": True},
|
| 496 |
+
"enable": True,
|
| 497 |
+
"gotoTypeDef": {"enable": True},
|
| 498 |
+
"implementations": {"enable": True},
|
| 499 |
+
"references": {"enable": False},
|
| 500 |
+
"run": {"enable": True},
|
| 501 |
+
},
|
| 502 |
+
"documentation": {"enable": True, "keywords": {"enable": True}},
|
| 503 |
+
"links": {"enable": True},
|
| 504 |
+
"memoryLayout": {"alignment": "hexadecimal", "enable": True, "niches": False, "offset": "hexadecimal", "size": "both"},
|
| 505 |
+
},
|
| 506 |
+
"imports": {
|
| 507 |
+
"granularity": {"enforce": False, "group": "crate"},
|
| 508 |
+
"group": {"enable": True},
|
| 509 |
+
"merge": {"glob": True},
|
| 510 |
+
"preferNoStd": False,
|
| 511 |
+
"preferPrelude": False,
|
| 512 |
+
"prefix": "plain",
|
| 513 |
+
},
|
| 514 |
+
"inlayHints": {
|
| 515 |
+
"bindingModeHints": {"enable": False},
|
| 516 |
+
"chainingHints": {"enable": True},
|
| 517 |
+
"closingBraceHints": {"enable": True, "minLines": 25},
|
| 518 |
+
"closureCaptureHints": {"enable": False},
|
| 519 |
+
"closureReturnTypeHints": {"enable": "never"},
|
| 520 |
+
"closureStyle": "impl_fn",
|
| 521 |
+
"discriminantHints": {"enable": "never"},
|
| 522 |
+
"expressionAdjustmentHints": {"enable": "never", "hideOutsideUnsafe": False, "mode": "prefix"},
|
| 523 |
+
"lifetimeElisionHints": {"enable": "never", "useParameterNames": False},
|
| 524 |
+
"maxLength": 25,
|
| 525 |
+
"parameterHints": {"enable": True},
|
| 526 |
+
"reborrowHints": {"enable": "never"},
|
| 527 |
+
"renderColons": True,
|
| 528 |
+
"typeHints": {"enable": True, "hideClosureInitialization": False, "hideNamedConstructor": False},
|
| 529 |
+
},
|
| 530 |
+
"interpret": {"tests": False},
|
| 531 |
+
"joinLines": {"joinAssignments": True, "joinElseIf": True, "removeTrailingComma": True, "unwrapTrivialBlock": True},
|
| 532 |
+
"lens": {
|
| 533 |
+
"debug": {"enable": True},
|
| 534 |
+
"enable": True,
|
| 535 |
+
"forceCustomCommands": True,
|
| 536 |
+
"implementations": {"enable": True},
|
| 537 |
+
"location": "above_name",
|
| 538 |
+
"references": {
|
| 539 |
+
"adt": {"enable": False},
|
| 540 |
+
"enumVariant": {"enable": False},
|
| 541 |
+
"method": {"enable": False},
|
| 542 |
+
"trait": {"enable": False},
|
| 543 |
+
},
|
| 544 |
+
"run": {"enable": True},
|
| 545 |
+
},
|
| 546 |
+
"linkedProjects": [],
|
| 547 |
+
"lru": {"capacity": None, "query": {"capacities": {}}},
|
| 548 |
+
"notifications": {"cargoTomlNotFound": True},
|
| 549 |
+
"numThreads": None,
|
| 550 |
+
"procMacro": {"attributes": {"enable": True}, "enable": True, "ignored": {}, "server": None},
|
| 551 |
+
"references": {"excludeImports": False},
|
| 552 |
+
"rust": {"analyzerTargetDir": None},
|
| 553 |
+
"rustc": {"source": None},
|
| 554 |
+
"rustfmt": {"extraArgs": [], "overrideCommand": None, "rangeFormatting": {"enable": False}},
|
| 555 |
+
"semanticHighlighting": {
|
| 556 |
+
"doc": {"comment": {"inject": {"enable": True}}},
|
| 557 |
+
"nonStandardTokens": True,
|
| 558 |
+
"operator": {"enable": True, "specialization": {"enable": False}},
|
| 559 |
+
"punctuation": {"enable": False, "separate": {"macro": {"bang": False}}, "specialization": {"enable": False}},
|
| 560 |
+
"strings": {"enable": True},
|
| 561 |
+
},
|
| 562 |
+
"signatureInfo": {"detail": "full", "documentation": {"enable": True}},
|
| 563 |
+
"workspace": {"symbol": {"search": {"kind": "only_types", "limit": 128, "scope": "workspace"}}},
|
| 564 |
+
},
|
| 565 |
+
"trace": "verbose",
|
| 566 |
+
"processId": os.getpid(),
|
| 567 |
+
"rootPath": repository_absolute_path,
|
| 568 |
+
"rootUri": root_uri,
|
| 569 |
+
"workspaceFolders": [
|
| 570 |
+
{
|
| 571 |
+
"uri": root_uri,
|
| 572 |
+
"name": os.path.basename(repository_absolute_path),
|
| 573 |
+
}
|
| 574 |
+
],
|
| 575 |
+
}
|
| 576 |
+
return initialize_params
|
| 577 |
+
|
| 578 |
+
def _start_server(self):
|
| 579 |
+
"""
|
| 580 |
+
Starts the Rust Analyzer Language Server
|
| 581 |
+
"""
|
| 582 |
+
|
| 583 |
+
def register_capability_handler(params):
|
| 584 |
+
assert "registrations" in params
|
| 585 |
+
for registration in params["registrations"]:
|
| 586 |
+
if registration["method"] == "workspace/executeCommand":
|
| 587 |
+
self.initialize_searcher_command_available.set()
|
| 588 |
+
self.resolve_main_method_available.set()
|
| 589 |
+
return
|
| 590 |
+
|
| 591 |
+
def lang_status_handler(params):
|
| 592 |
+
# TODO: Should we wait for
|
| 593 |
+
# server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}
|
| 594 |
+
# Before proceeding?
|
| 595 |
+
if params["type"] == "ServiceReady" and params["message"] == "ServiceReady":
|
| 596 |
+
self.service_ready_event.set()
|
| 597 |
+
|
| 598 |
+
def execute_client_command_handler(params):
|
| 599 |
+
return []
|
| 600 |
+
|
| 601 |
+
def do_nothing(params):
|
| 602 |
+
return
|
| 603 |
+
|
| 604 |
+
def check_experimental_status(params):
|
| 605 |
+
if params["quiescent"] == True:
|
| 606 |
+
self.server_ready.set()
|
| 607 |
+
|
| 608 |
+
def window_log_message(msg):
|
| 609 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 610 |
+
|
| 611 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 612 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 613 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 614 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 615 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 616 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 617 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 618 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 619 |
+
|
| 620 |
+
self.logger.log("Starting RustAnalyzer server process", logging.INFO)
|
| 621 |
+
self.server.start()
|
| 622 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 623 |
+
|
| 624 |
+
self.logger.log(
|
| 625 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 626 |
+
logging.INFO,
|
| 627 |
+
)
|
| 628 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 629 |
+
assert init_response["capabilities"]["textDocumentSync"]["change"] == 2
|
| 630 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 631 |
+
assert init_response["capabilities"]["completionProvider"] == {
|
| 632 |
+
"resolveProvider": True,
|
| 633 |
+
"triggerCharacters": [":", ".", "'", "("],
|
| 634 |
+
"completionItem": {"labelDetailsSupport": True},
|
| 635 |
+
}
|
| 636 |
+
self.server.notify.initialized({})
|
| 637 |
+
self.completions_available.set()
|
| 638 |
+
|
| 639 |
+
self.server_ready.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/solargraph.py
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Ruby specific instantiation of the LanguageServer class using Solargraph.
|
| 3 |
+
Contains various configurations and settings specific to Ruby.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import pathlib
|
| 10 |
+
import re
|
| 11 |
+
import shutil
|
| 12 |
+
import subprocess
|
| 13 |
+
import threading
|
| 14 |
+
|
| 15 |
+
from overrides import override
|
| 16 |
+
|
| 17 |
+
from solidlsp.ls import SolidLanguageServer
|
| 18 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 19 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 20 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 21 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 22 |
+
from solidlsp.settings import SolidLSPSettings
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class Solargraph(SolidLanguageServer):
|
| 26 |
+
"""
|
| 27 |
+
Provides Ruby specific instantiation of the LanguageServer class using Solargraph.
|
| 28 |
+
Contains various configurations and settings specific to Ruby.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __init__(
|
| 32 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 33 |
+
):
|
| 34 |
+
"""
|
| 35 |
+
Creates a Solargraph instance. This class is not meant to be instantiated directly.
|
| 36 |
+
Use LanguageServer.create() instead.
|
| 37 |
+
"""
|
| 38 |
+
solargraph_executable_path = self._setup_runtime_dependencies(logger, config, repository_root_path)
|
| 39 |
+
super().__init__(
|
| 40 |
+
config,
|
| 41 |
+
logger,
|
| 42 |
+
repository_root_path,
|
| 43 |
+
ProcessLaunchInfo(cmd=f"{solargraph_executable_path} stdio", cwd=repository_root_path),
|
| 44 |
+
"ruby",
|
| 45 |
+
solidlsp_settings,
|
| 46 |
+
)
|
| 47 |
+
# Override internal language enum for file matching (excludes .erb files)
|
| 48 |
+
# while keeping LSP languageId as "ruby" for protocol compliance
|
| 49 |
+
from solidlsp.ls_config import Language
|
| 50 |
+
|
| 51 |
+
self.language = Language.RUBY_SOLARGRAPH
|
| 52 |
+
self.analysis_complete = threading.Event()
|
| 53 |
+
self.service_ready_event = threading.Event()
|
| 54 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 55 |
+
self.resolve_main_method_available = threading.Event()
|
| 56 |
+
|
| 57 |
+
# Set timeout for Solargraph requests - Bundler environments may need more time
|
| 58 |
+
self.set_request_timeout(120.0) # 120 seconds for initialization and requests
|
| 59 |
+
|
| 60 |
+
@override
|
| 61 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 62 |
+
ruby_ignored_dirs = [
|
| 63 |
+
"vendor", # Ruby vendor directory
|
| 64 |
+
".bundle", # Bundler cache
|
| 65 |
+
"tmp", # Temporary files
|
| 66 |
+
"log", # Log files
|
| 67 |
+
"coverage", # Test coverage reports
|
| 68 |
+
".yardoc", # YARD documentation cache
|
| 69 |
+
"doc", # Generated documentation
|
| 70 |
+
"node_modules", # Node modules (for Rails with JS)
|
| 71 |
+
"storage", # Active Storage files (Rails)
|
| 72 |
+
]
|
| 73 |
+
return super().is_ignored_dirname(dirname) or dirname in ruby_ignored_dirs
|
| 74 |
+
|
| 75 |
+
@staticmethod
|
| 76 |
+
def _setup_runtime_dependencies(logger: LanguageServerLogger, config: LanguageServerConfig, repository_root_path: str) -> str:
|
| 77 |
+
"""
|
| 78 |
+
Setup runtime dependencies for Solargraph and return the command to start the server.
|
| 79 |
+
"""
|
| 80 |
+
# Check if Ruby is installed
|
| 81 |
+
try:
|
| 82 |
+
result = subprocess.run(["ruby", "--version"], check=True, capture_output=True, cwd=repository_root_path, text=True)
|
| 83 |
+
ruby_version = result.stdout.strip()
|
| 84 |
+
logger.log(f"Ruby version: {ruby_version}", logging.INFO)
|
| 85 |
+
|
| 86 |
+
# Extract version number for compatibility checks
|
| 87 |
+
version_match = re.search(r"ruby (\d+)\.(\d+)\.(\d+)", ruby_version)
|
| 88 |
+
if version_match:
|
| 89 |
+
major, minor, patch = map(int, version_match.groups())
|
| 90 |
+
if major < 2 or (major == 2 and minor < 6):
|
| 91 |
+
logger.log(f"Warning: Ruby {major}.{minor}.{patch} detected. Solargraph works best with Ruby 2.6+", logging.WARNING)
|
| 92 |
+
|
| 93 |
+
except subprocess.CalledProcessError as e:
|
| 94 |
+
error_msg = e.stderr.decode() if e.stderr else "Unknown error"
|
| 95 |
+
raise RuntimeError(
|
| 96 |
+
f"Error checking Ruby installation: {error_msg}. Please ensure Ruby is properly installed and in PATH."
|
| 97 |
+
) from e
|
| 98 |
+
except FileNotFoundError as e:
|
| 99 |
+
raise RuntimeError(
|
| 100 |
+
"Ruby is not installed or not found in PATH. Please install Ruby using one of these methods:\n"
|
| 101 |
+
" - Using rbenv: rbenv install 3.0.0 && rbenv global 3.0.0\n"
|
| 102 |
+
" - Using RVM: rvm install 3.0.0 && rvm use 3.0.0 --default\n"
|
| 103 |
+
" - Using asdf: asdf install ruby 3.0.0 && asdf global ruby 3.0.0\n"
|
| 104 |
+
" - System package manager (brew install ruby, apt install ruby, etc.)"
|
| 105 |
+
) from e
|
| 106 |
+
|
| 107 |
+
# Helper function for Windows-compatible executable search
|
| 108 |
+
def find_executable_with_extensions(executable_name: str) -> str | None:
|
| 109 |
+
"""Find executable with Windows-specific extensions if on Windows."""
|
| 110 |
+
import platform
|
| 111 |
+
|
| 112 |
+
if platform.system() == "Windows":
|
| 113 |
+
for ext in [".bat", ".cmd", ".exe"]:
|
| 114 |
+
path = shutil.which(f"{executable_name}{ext}")
|
| 115 |
+
if path:
|
| 116 |
+
return path
|
| 117 |
+
return shutil.which(executable_name)
|
| 118 |
+
else:
|
| 119 |
+
return shutil.which(executable_name)
|
| 120 |
+
|
| 121 |
+
# Check for Bundler project (Gemfile exists)
|
| 122 |
+
gemfile_path = os.path.join(repository_root_path, "Gemfile")
|
| 123 |
+
gemfile_lock_path = os.path.join(repository_root_path, "Gemfile.lock")
|
| 124 |
+
is_bundler_project = os.path.exists(gemfile_path)
|
| 125 |
+
|
| 126 |
+
if is_bundler_project:
|
| 127 |
+
logger.log("Detected Bundler project (Gemfile found)", logging.INFO)
|
| 128 |
+
|
| 129 |
+
# Check if bundle command is available
|
| 130 |
+
bundle_path = find_executable_with_extensions("bundle")
|
| 131 |
+
if not bundle_path:
|
| 132 |
+
# Try common bundle executables
|
| 133 |
+
for bundle_cmd in ["bin/bundle", "bundle"]:
|
| 134 |
+
if bundle_cmd.startswith("bin/"):
|
| 135 |
+
bundle_full_path = os.path.join(repository_root_path, bundle_cmd)
|
| 136 |
+
else:
|
| 137 |
+
bundle_full_path = find_executable_with_extensions(bundle_cmd)
|
| 138 |
+
if bundle_full_path and os.path.exists(bundle_full_path):
|
| 139 |
+
bundle_path = bundle_full_path if bundle_cmd.startswith("bin/") else bundle_cmd
|
| 140 |
+
break
|
| 141 |
+
|
| 142 |
+
if not bundle_path:
|
| 143 |
+
raise RuntimeError(
|
| 144 |
+
"Bundler project detected but 'bundle' command not found. Please install Bundler:\n"
|
| 145 |
+
" - gem install bundler\n"
|
| 146 |
+
" - Or use your Ruby version manager's bundler installation\n"
|
| 147 |
+
" - Ensure the bundle command is in your PATH"
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
# Check if solargraph is in Gemfile.lock
|
| 151 |
+
solargraph_in_bundle = False
|
| 152 |
+
if os.path.exists(gemfile_lock_path):
|
| 153 |
+
try:
|
| 154 |
+
with open(gemfile_lock_path) as f:
|
| 155 |
+
content = f.read()
|
| 156 |
+
solargraph_in_bundle = "solargraph" in content.lower()
|
| 157 |
+
except Exception as e:
|
| 158 |
+
logger.log(f"Warning: Could not read Gemfile.lock: {e}", logging.WARNING)
|
| 159 |
+
|
| 160 |
+
if solargraph_in_bundle:
|
| 161 |
+
logger.log("Found solargraph in Gemfile.lock", logging.INFO)
|
| 162 |
+
return f"{bundle_path} exec solargraph"
|
| 163 |
+
else:
|
| 164 |
+
logger.log(
|
| 165 |
+
"solargraph not found in Gemfile.lock. Please add 'gem \"solargraph\"' to your Gemfile and run 'bundle install'",
|
| 166 |
+
logging.WARNING,
|
| 167 |
+
)
|
| 168 |
+
# Fall through to global installation check
|
| 169 |
+
|
| 170 |
+
# Check if solargraph is installed globally
|
| 171 |
+
# First, try to find solargraph in PATH (includes asdf shims) with Windows support
|
| 172 |
+
solargraph_path = find_executable_with_extensions("solargraph")
|
| 173 |
+
if solargraph_path:
|
| 174 |
+
logger.log(f"Found solargraph at: {solargraph_path}", logging.INFO)
|
| 175 |
+
return solargraph_path
|
| 176 |
+
|
| 177 |
+
# Fallback to gem exec (for non-Bundler projects or when global solargraph not found)
|
| 178 |
+
if not is_bundler_project:
|
| 179 |
+
runtime_dependencies = [
|
| 180 |
+
{
|
| 181 |
+
"url": "https://rubygems.org/downloads/solargraph-0.51.1.gem",
|
| 182 |
+
"installCommand": "gem install solargraph -v 0.51.1",
|
| 183 |
+
"binaryName": "solargraph",
|
| 184 |
+
"archiveType": "gem",
|
| 185 |
+
}
|
| 186 |
+
]
|
| 187 |
+
|
| 188 |
+
dependency = runtime_dependencies[0]
|
| 189 |
+
try:
|
| 190 |
+
result = subprocess.run(
|
| 191 |
+
["gem", "list", "^solargraph$", "-i"], check=False, capture_output=True, text=True, cwd=repository_root_path
|
| 192 |
+
)
|
| 193 |
+
if result.stdout.strip() == "false":
|
| 194 |
+
logger.log("Installing Solargraph...", logging.INFO)
|
| 195 |
+
subprocess.run(dependency["installCommand"].split(), check=True, capture_output=True, cwd=repository_root_path)
|
| 196 |
+
|
| 197 |
+
return "gem exec solargraph"
|
| 198 |
+
except subprocess.CalledProcessError as e:
|
| 199 |
+
error_msg = e.stderr.decode() if e.stderr else str(e)
|
| 200 |
+
raise RuntimeError(
|
| 201 |
+
f"Failed to check or install Solargraph: {error_msg}\nPlease try installing manually: gem install solargraph"
|
| 202 |
+
) from e
|
| 203 |
+
else:
|
| 204 |
+
raise RuntimeError(
|
| 205 |
+
"This appears to be a Bundler project, but solargraph is not available. "
|
| 206 |
+
"Please add 'gem \"solargraph\"' to your Gemfile and run 'bundle install'."
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
@staticmethod
|
| 210 |
+
def _detect_rails_project(repository_root_path: str) -> bool:
|
| 211 |
+
"""
|
| 212 |
+
Detect if this is a Rails project by checking for Rails-specific files.
|
| 213 |
+
"""
|
| 214 |
+
rails_indicators = [
|
| 215 |
+
"config/application.rb",
|
| 216 |
+
"config/environment.rb",
|
| 217 |
+
"app/controllers/application_controller.rb",
|
| 218 |
+
"Rakefile",
|
| 219 |
+
]
|
| 220 |
+
|
| 221 |
+
for indicator in rails_indicators:
|
| 222 |
+
if os.path.exists(os.path.join(repository_root_path, indicator)):
|
| 223 |
+
return True
|
| 224 |
+
|
| 225 |
+
# Check for Rails in Gemfile
|
| 226 |
+
gemfile_path = os.path.join(repository_root_path, "Gemfile")
|
| 227 |
+
if os.path.exists(gemfile_path):
|
| 228 |
+
try:
|
| 229 |
+
with open(gemfile_path) as f:
|
| 230 |
+
content = f.read().lower()
|
| 231 |
+
if "gem 'rails'" in content or 'gem "rails"' in content:
|
| 232 |
+
return True
|
| 233 |
+
except Exception:
|
| 234 |
+
pass
|
| 235 |
+
|
| 236 |
+
return False
|
| 237 |
+
|
| 238 |
+
@staticmethod
|
| 239 |
+
def _get_ruby_exclude_patterns(repository_root_path: str) -> list[str]:
|
| 240 |
+
"""
|
| 241 |
+
Get Ruby and Rails-specific exclude patterns for better performance.
|
| 242 |
+
"""
|
| 243 |
+
base_patterns = [
|
| 244 |
+
"**/vendor/**", # Ruby vendor directory (similar to node_modules)
|
| 245 |
+
"**/.bundle/**", # Bundler cache
|
| 246 |
+
"**/tmp/**", # Temporary files
|
| 247 |
+
"**/log/**", # Log files
|
| 248 |
+
"**/coverage/**", # Test coverage reports
|
| 249 |
+
"**/.yardoc/**", # YARD documentation cache
|
| 250 |
+
"**/doc/**", # Generated documentation
|
| 251 |
+
"**/.git/**", # Git directory
|
| 252 |
+
"**/node_modules/**", # Node modules (for Rails with JS)
|
| 253 |
+
"**/public/assets/**", # Rails compiled assets
|
| 254 |
+
]
|
| 255 |
+
|
| 256 |
+
# Add Rails-specific patterns if this is a Rails project
|
| 257 |
+
if Solargraph._detect_rails_project(repository_root_path):
|
| 258 |
+
rails_patterns = [
|
| 259 |
+
"**/public/packs/**", # Webpacker output
|
| 260 |
+
"**/public/webpack/**", # Webpack output
|
| 261 |
+
"**/storage/**", # Active Storage files
|
| 262 |
+
"**/tmp/cache/**", # Rails cache
|
| 263 |
+
"**/tmp/pids/**", # Process IDs
|
| 264 |
+
"**/tmp/sessions/**", # Session files
|
| 265 |
+
"**/tmp/sockets/**", # Socket files
|
| 266 |
+
"**/db/*.sqlite3", # SQLite databases
|
| 267 |
+
]
|
| 268 |
+
base_patterns.extend(rails_patterns)
|
| 269 |
+
|
| 270 |
+
return base_patterns
|
| 271 |
+
|
| 272 |
+
@staticmethod
|
| 273 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 274 |
+
"""
|
| 275 |
+
Returns the initialize params for the Solargraph Language Server.
|
| 276 |
+
"""
|
| 277 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 278 |
+
exclude_patterns = Solargraph._get_ruby_exclude_patterns(repository_absolute_path)
|
| 279 |
+
|
| 280 |
+
initialize_params: InitializeParams = { # type: ignore
|
| 281 |
+
"processId": os.getpid(),
|
| 282 |
+
"rootPath": repository_absolute_path,
|
| 283 |
+
"rootUri": root_uri,
|
| 284 |
+
"initializationOptions": {
|
| 285 |
+
"exclude": exclude_patterns,
|
| 286 |
+
},
|
| 287 |
+
"capabilities": {
|
| 288 |
+
"workspace": {
|
| 289 |
+
"workspaceEdit": {"documentChanges": True},
|
| 290 |
+
},
|
| 291 |
+
"textDocument": {
|
| 292 |
+
"documentSymbol": {
|
| 293 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 294 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 295 |
+
},
|
| 296 |
+
},
|
| 297 |
+
},
|
| 298 |
+
"trace": "verbose",
|
| 299 |
+
"workspaceFolders": [
|
| 300 |
+
{
|
| 301 |
+
"uri": root_uri,
|
| 302 |
+
"name": os.path.basename(repository_absolute_path),
|
| 303 |
+
}
|
| 304 |
+
],
|
| 305 |
+
}
|
| 306 |
+
return initialize_params
|
| 307 |
+
|
| 308 |
+
def _start_server(self):
|
| 309 |
+
"""
|
| 310 |
+
Starts the Solargraph Language Server for Ruby
|
| 311 |
+
"""
|
| 312 |
+
|
| 313 |
+
def register_capability_handler(params):
|
| 314 |
+
assert "registrations" in params
|
| 315 |
+
for registration in params["registrations"]:
|
| 316 |
+
if registration["method"] == "workspace/executeCommand":
|
| 317 |
+
self.initialize_searcher_command_available.set()
|
| 318 |
+
self.resolve_main_method_available.set()
|
| 319 |
+
return
|
| 320 |
+
|
| 321 |
+
def lang_status_handler(params):
|
| 322 |
+
self.logger.log(f"LSP: language/status: {params}", logging.INFO)
|
| 323 |
+
if params.get("type") == "ServiceReady" and params.get("message") == "Service is ready.":
|
| 324 |
+
self.logger.log("Solargraph service is ready.", logging.INFO)
|
| 325 |
+
self.analysis_complete.set()
|
| 326 |
+
self.completions_available.set()
|
| 327 |
+
|
| 328 |
+
def execute_client_command_handler(params):
|
| 329 |
+
return []
|
| 330 |
+
|
| 331 |
+
def do_nothing(params):
|
| 332 |
+
return
|
| 333 |
+
|
| 334 |
+
def window_log_message(msg):
|
| 335 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 336 |
+
|
| 337 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 338 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 339 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 340 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 341 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 342 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 343 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 344 |
+
|
| 345 |
+
self.logger.log("Starting solargraph server process", logging.INFO)
|
| 346 |
+
self.server.start()
|
| 347 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 348 |
+
|
| 349 |
+
self.logger.log(
|
| 350 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 351 |
+
logging.INFO,
|
| 352 |
+
)
|
| 353 |
+
self.logger.log(f"Sending init params: {json.dumps(initialize_params, indent=4)}", logging.INFO)
|
| 354 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 355 |
+
self.logger.log(f"Received init response: {init_response}", logging.INFO)
|
| 356 |
+
assert init_response["capabilities"]["textDocumentSync"] == 2
|
| 357 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 358 |
+
assert init_response["capabilities"]["completionProvider"] == {
|
| 359 |
+
"resolveProvider": True,
|
| 360 |
+
"triggerCharacters": [".", ":", "@"],
|
| 361 |
+
}
|
| 362 |
+
self.server.notify.initialized({})
|
| 363 |
+
|
| 364 |
+
# Wait for Solargraph to complete its initial workspace analysis
|
| 365 |
+
# This prevents issues by ensuring background tasks finish
|
| 366 |
+
self.logger.log("Waiting for Solargraph to complete initial workspace analysis...", logging.INFO)
|
| 367 |
+
if self.analysis_complete.wait(timeout=60.0):
|
| 368 |
+
self.logger.log("Solargraph initial analysis complete, server ready", logging.INFO)
|
| 369 |
+
else:
|
| 370 |
+
self.logger.log("Timeout waiting for Solargraph analysis completion, proceeding anyway", logging.WARNING)
|
| 371 |
+
# Fallback: assume analysis is complete after timeout
|
| 372 |
+
self.analysis_complete.set()
|
| 373 |
+
self.completions_available.set()
|
projects/ui/serena-new/src/solidlsp/language_servers/sourcekit_lsp.py
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
import subprocess
|
| 5 |
+
import threading
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
from overrides import override
|
| 9 |
+
|
| 10 |
+
from solidlsp import ls_types
|
| 11 |
+
from solidlsp.ls import SolidLanguageServer
|
| 12 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 13 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 14 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 15 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 16 |
+
from solidlsp.settings import SolidLSPSettings
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SourceKitLSP(SolidLanguageServer):
|
| 20 |
+
"""
|
| 21 |
+
Provides Swift specific instantiation of the LanguageServer class using sourcekit-lsp.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
@override
|
| 25 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 26 |
+
# For Swift projects, we should ignore:
|
| 27 |
+
# - .build: Swift Package Manager build artifacts
|
| 28 |
+
# - .swiftpm: Swift Package Manager metadata
|
| 29 |
+
# - node_modules: if the project has JavaScript components
|
| 30 |
+
# - dist/build: common output directories
|
| 31 |
+
return super().is_ignored_dirname(dirname) or dirname in [".build", ".swiftpm", "node_modules", "dist", "build"]
|
| 32 |
+
|
| 33 |
+
@staticmethod
|
| 34 |
+
def _get_sourcekit_lsp_version() -> str:
|
| 35 |
+
"""Get the installed sourcekit-lsp version or raise error if sourcekit was not found."""
|
| 36 |
+
try:
|
| 37 |
+
result = subprocess.run(["sourcekit-lsp", "-h"], capture_output=True, text=True, check=False)
|
| 38 |
+
if result.returncode == 0:
|
| 39 |
+
return result.stdout.strip()
|
| 40 |
+
else:
|
| 41 |
+
raise Exception(f"`sourcekit-lsp -h` resulted in: {result}")
|
| 42 |
+
except Exception as e:
|
| 43 |
+
raise RuntimeError(
|
| 44 |
+
"Could not find sourcekit-lsp, please install it as described in https://github.com/apple/sourcekit-lsp#installation"
|
| 45 |
+
"And make sure it is available on your PATH."
|
| 46 |
+
) from e
|
| 47 |
+
|
| 48 |
+
def __init__(
|
| 49 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 50 |
+
):
|
| 51 |
+
sourcekit_version = self._get_sourcekit_lsp_version()
|
| 52 |
+
logger.log(f"Starting sourcekit lsp with version: {sourcekit_version}", logging.INFO)
|
| 53 |
+
|
| 54 |
+
super().__init__(
|
| 55 |
+
config,
|
| 56 |
+
logger,
|
| 57 |
+
repository_root_path,
|
| 58 |
+
ProcessLaunchInfo(cmd="sourcekit-lsp", cwd=repository_root_path),
|
| 59 |
+
"swift",
|
| 60 |
+
solidlsp_settings,
|
| 61 |
+
)
|
| 62 |
+
self.server_ready = threading.Event()
|
| 63 |
+
self.request_id = 0
|
| 64 |
+
self._did_sleep_before_requesting_references = False
|
| 65 |
+
|
| 66 |
+
@staticmethod
|
| 67 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 68 |
+
"""
|
| 69 |
+
Returns the initialize params for the Swift Language Server.
|
| 70 |
+
"""
|
| 71 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 72 |
+
|
| 73 |
+
initialize_params = {
|
| 74 |
+
"capabilities": {
|
| 75 |
+
"general": {
|
| 76 |
+
"markdown": {"parser": "marked", "version": "1.1.0"},
|
| 77 |
+
"positionEncodings": ["utf-16"],
|
| 78 |
+
"regularExpressions": {"engine": "ECMAScript", "version": "ES2020"},
|
| 79 |
+
"staleRequestSupport": {
|
| 80 |
+
"cancel": True,
|
| 81 |
+
"retryOnContentModified": [
|
| 82 |
+
"textDocument/semanticTokens/full",
|
| 83 |
+
"textDocument/semanticTokens/range",
|
| 84 |
+
"textDocument/semanticTokens/full/delta",
|
| 85 |
+
],
|
| 86 |
+
},
|
| 87 |
+
},
|
| 88 |
+
"notebookDocument": {"synchronization": {"dynamicRegistration": True, "executionSummarySupport": True}},
|
| 89 |
+
"textDocument": {
|
| 90 |
+
"callHierarchy": {"dynamicRegistration": True},
|
| 91 |
+
"codeAction": {
|
| 92 |
+
"codeActionLiteralSupport": {
|
| 93 |
+
"codeActionKind": {
|
| 94 |
+
"valueSet": [
|
| 95 |
+
"",
|
| 96 |
+
"quickfix",
|
| 97 |
+
"refactor",
|
| 98 |
+
"refactor.extract",
|
| 99 |
+
"refactor.inline",
|
| 100 |
+
"refactor.rewrite",
|
| 101 |
+
"source",
|
| 102 |
+
"source.organizeImports",
|
| 103 |
+
]
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
"dataSupport": True,
|
| 107 |
+
"disabledSupport": True,
|
| 108 |
+
"dynamicRegistration": True,
|
| 109 |
+
"honorsChangeAnnotations": True,
|
| 110 |
+
"isPreferredSupport": True,
|
| 111 |
+
"resolveSupport": {"properties": ["edit"]},
|
| 112 |
+
},
|
| 113 |
+
"codeLens": {"dynamicRegistration": True},
|
| 114 |
+
"colorProvider": {"dynamicRegistration": True},
|
| 115 |
+
"completion": {
|
| 116 |
+
"completionItem": {
|
| 117 |
+
"commitCharactersSupport": True,
|
| 118 |
+
"deprecatedSupport": True,
|
| 119 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 120 |
+
"insertReplaceSupport": True,
|
| 121 |
+
"insertTextModeSupport": {"valueSet": [1, 2]},
|
| 122 |
+
"labelDetailsSupport": True,
|
| 123 |
+
"preselectSupport": True,
|
| 124 |
+
"resolveSupport": {"properties": ["documentation", "detail", "additionalTextEdits"]},
|
| 125 |
+
"snippetSupport": True,
|
| 126 |
+
"tagSupport": {"valueSet": [1]},
|
| 127 |
+
},
|
| 128 |
+
"completionItemKind": {
|
| 129 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
| 130 |
+
},
|
| 131 |
+
"completionList": {"itemDefaults": ["commitCharacters", "editRange", "insertTextFormat", "insertTextMode", "data"]},
|
| 132 |
+
"contextSupport": True,
|
| 133 |
+
"dynamicRegistration": True,
|
| 134 |
+
"insertTextMode": 2,
|
| 135 |
+
},
|
| 136 |
+
"declaration": {"dynamicRegistration": True, "linkSupport": True},
|
| 137 |
+
"definition": {"dynamicRegistration": True, "linkSupport": True},
|
| 138 |
+
"diagnostic": {"dynamicRegistration": True, "relatedDocumentSupport": False},
|
| 139 |
+
"documentHighlight": {"dynamicRegistration": True},
|
| 140 |
+
"documentLink": {"dynamicRegistration": True, "tooltipSupport": True},
|
| 141 |
+
"documentSymbol": {
|
| 142 |
+
"dynamicRegistration": True,
|
| 143 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 144 |
+
"labelSupport": True,
|
| 145 |
+
"symbolKind": {
|
| 146 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
| 147 |
+
},
|
| 148 |
+
"tagSupport": {"valueSet": [1]},
|
| 149 |
+
},
|
| 150 |
+
"foldingRange": {
|
| 151 |
+
"dynamicRegistration": True,
|
| 152 |
+
"foldingRange": {"collapsedText": False},
|
| 153 |
+
"foldingRangeKind": {"valueSet": ["comment", "imports", "region"]},
|
| 154 |
+
"lineFoldingOnly": True,
|
| 155 |
+
"rangeLimit": 5000,
|
| 156 |
+
},
|
| 157 |
+
"formatting": {"dynamicRegistration": True},
|
| 158 |
+
"hover": {"contentFormat": ["markdown", "plaintext"], "dynamicRegistration": True},
|
| 159 |
+
"implementation": {"dynamicRegistration": True, "linkSupport": True},
|
| 160 |
+
"inlayHint": {
|
| 161 |
+
"dynamicRegistration": True,
|
| 162 |
+
"resolveSupport": {"properties": ["tooltip", "textEdits", "label.tooltip", "label.location", "label.command"]},
|
| 163 |
+
},
|
| 164 |
+
"inlineValue": {"dynamicRegistration": True},
|
| 165 |
+
"linkedEditingRange": {"dynamicRegistration": True},
|
| 166 |
+
"onTypeFormatting": {"dynamicRegistration": True},
|
| 167 |
+
"publishDiagnostics": {
|
| 168 |
+
"codeDescriptionSupport": True,
|
| 169 |
+
"dataSupport": True,
|
| 170 |
+
"relatedInformation": True,
|
| 171 |
+
"tagSupport": {"valueSet": [1, 2]},
|
| 172 |
+
"versionSupport": False,
|
| 173 |
+
},
|
| 174 |
+
"rangeFormatting": {"dynamicRegistration": True, "rangesSupport": True},
|
| 175 |
+
"references": {"dynamicRegistration": True},
|
| 176 |
+
"rename": {
|
| 177 |
+
"dynamicRegistration": True,
|
| 178 |
+
"honorsChangeAnnotations": True,
|
| 179 |
+
"prepareSupport": True,
|
| 180 |
+
"prepareSupportDefaultBehavior": 1,
|
| 181 |
+
},
|
| 182 |
+
"selectionRange": {"dynamicRegistration": True},
|
| 183 |
+
"semanticTokens": {
|
| 184 |
+
"augmentsSyntaxTokens": True,
|
| 185 |
+
"dynamicRegistration": True,
|
| 186 |
+
"formats": ["relative"],
|
| 187 |
+
"multilineTokenSupport": False,
|
| 188 |
+
"overlappingTokenSupport": False,
|
| 189 |
+
"requests": {"full": {"delta": True}, "range": True},
|
| 190 |
+
"serverCancelSupport": True,
|
| 191 |
+
"tokenModifiers": [
|
| 192 |
+
"declaration",
|
| 193 |
+
"definition",
|
| 194 |
+
"readonly",
|
| 195 |
+
"static",
|
| 196 |
+
"deprecated",
|
| 197 |
+
"abstract",
|
| 198 |
+
"async",
|
| 199 |
+
"modification",
|
| 200 |
+
"documentation",
|
| 201 |
+
"defaultLibrary",
|
| 202 |
+
],
|
| 203 |
+
"tokenTypes": [
|
| 204 |
+
"namespace",
|
| 205 |
+
"type",
|
| 206 |
+
"class",
|
| 207 |
+
"enum",
|
| 208 |
+
"interface",
|
| 209 |
+
"struct",
|
| 210 |
+
"typeParameter",
|
| 211 |
+
"parameter",
|
| 212 |
+
"variable",
|
| 213 |
+
"property",
|
| 214 |
+
"enumMember",
|
| 215 |
+
"event",
|
| 216 |
+
"function",
|
| 217 |
+
"method",
|
| 218 |
+
"macro",
|
| 219 |
+
"keyword",
|
| 220 |
+
"modifier",
|
| 221 |
+
"comment",
|
| 222 |
+
"string",
|
| 223 |
+
"number",
|
| 224 |
+
"regexp",
|
| 225 |
+
"operator",
|
| 226 |
+
"decorator",
|
| 227 |
+
],
|
| 228 |
+
},
|
| 229 |
+
"signatureHelp": {
|
| 230 |
+
"contextSupport": True,
|
| 231 |
+
"dynamicRegistration": True,
|
| 232 |
+
"signatureInformation": {
|
| 233 |
+
"activeParameterSupport": True,
|
| 234 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 235 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 236 |
+
},
|
| 237 |
+
},
|
| 238 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True},
|
| 239 |
+
"typeDefinition": {"dynamicRegistration": True, "linkSupport": True},
|
| 240 |
+
"typeHierarchy": {"dynamicRegistration": True},
|
| 241 |
+
},
|
| 242 |
+
"window": {
|
| 243 |
+
"showDocument": {"support": True},
|
| 244 |
+
"showMessage": {"messageActionItem": {"additionalPropertiesSupport": True}},
|
| 245 |
+
"workDoneProgress": True,
|
| 246 |
+
},
|
| 247 |
+
"workspace": {
|
| 248 |
+
"applyEdit": True,
|
| 249 |
+
"codeLens": {"refreshSupport": True},
|
| 250 |
+
"configuration": True,
|
| 251 |
+
"diagnostics": {"refreshSupport": True},
|
| 252 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 253 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True, "relativePatternSupport": True},
|
| 254 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 255 |
+
"fileOperations": {
|
| 256 |
+
"didCreate": True,
|
| 257 |
+
"didDelete": True,
|
| 258 |
+
"didRename": True,
|
| 259 |
+
"dynamicRegistration": True,
|
| 260 |
+
"willCreate": True,
|
| 261 |
+
"willDelete": True,
|
| 262 |
+
"willRename": True,
|
| 263 |
+
},
|
| 264 |
+
"foldingRange": {"refreshSupport": True},
|
| 265 |
+
"inlayHint": {"refreshSupport": True},
|
| 266 |
+
"inlineValue": {"refreshSupport": True},
|
| 267 |
+
"semanticTokens": {"refreshSupport": False},
|
| 268 |
+
"symbol": {
|
| 269 |
+
"dynamicRegistration": True,
|
| 270 |
+
"resolveSupport": {"properties": ["location.range"]},
|
| 271 |
+
"symbolKind": {
|
| 272 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
| 273 |
+
},
|
| 274 |
+
"tagSupport": {"valueSet": [1]},
|
| 275 |
+
},
|
| 276 |
+
"workspaceEdit": {
|
| 277 |
+
"changeAnnotationSupport": {"groupsOnLabel": True},
|
| 278 |
+
"documentChanges": True,
|
| 279 |
+
"failureHandling": "textOnlyTransactional",
|
| 280 |
+
"normalizesLineEndings": True,
|
| 281 |
+
"resourceOperations": ["create", "rename", "delete"],
|
| 282 |
+
},
|
| 283 |
+
"workspaceFolders": True,
|
| 284 |
+
},
|
| 285 |
+
},
|
| 286 |
+
"clientInfo": {"name": "Visual Studio Code", "version": "1.102.2"},
|
| 287 |
+
"initializationOptions": {
|
| 288 |
+
"backgroundIndexing": True,
|
| 289 |
+
"backgroundPreparationMode": "enabled",
|
| 290 |
+
"textDocument/codeLens": {"supportedCommands": {"swift.debug": "swift.debug", "swift.run": "swift.run"}},
|
| 291 |
+
"window/didChangeActiveDocument": True,
|
| 292 |
+
"workspace/getReferenceDocument": True,
|
| 293 |
+
"workspace/peekDocuments": True,
|
| 294 |
+
},
|
| 295 |
+
"locale": "en",
|
| 296 |
+
"processId": os.getpid(),
|
| 297 |
+
"rootPath": repository_absolute_path,
|
| 298 |
+
"rootUri": root_uri,
|
| 299 |
+
"workspaceFolders": [
|
| 300 |
+
{
|
| 301 |
+
"uri": root_uri,
|
| 302 |
+
"name": os.path.basename(repository_absolute_path),
|
| 303 |
+
}
|
| 304 |
+
],
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
return initialize_params
|
| 308 |
+
|
| 309 |
+
def _start_server(self):
|
| 310 |
+
"""Start sourcekit-lsp server process"""
|
| 311 |
+
|
| 312 |
+
def register_capability_handler(_params):
|
| 313 |
+
return
|
| 314 |
+
|
| 315 |
+
def window_log_message(msg):
|
| 316 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 317 |
+
|
| 318 |
+
def do_nothing(_params):
|
| 319 |
+
return
|
| 320 |
+
|
| 321 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 322 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 323 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 324 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 325 |
+
|
| 326 |
+
self.logger.log("Starting sourcekit-lsp server process", logging.INFO)
|
| 327 |
+
self.server.start()
|
| 328 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 329 |
+
|
| 330 |
+
self.logger.log(
|
| 331 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 332 |
+
logging.INFO,
|
| 333 |
+
)
|
| 334 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 335 |
+
|
| 336 |
+
capabilities = init_response["capabilities"]
|
| 337 |
+
self.logger.log(f"SourceKit LSP capabilities: {list(capabilities.keys())}", logging.INFO)
|
| 338 |
+
|
| 339 |
+
assert "textDocumentSync" in capabilities, "textDocumentSync capability missing"
|
| 340 |
+
assert "definitionProvider" in capabilities, "definitionProvider capability missing"
|
| 341 |
+
|
| 342 |
+
self.server.notify.initialized({})
|
| 343 |
+
self.completions_available.set()
|
| 344 |
+
|
| 345 |
+
self.server_ready.set()
|
| 346 |
+
self.server_ready.wait()
|
| 347 |
+
|
| 348 |
+
@override
|
| 349 |
+
def request_references(self, relative_file_path: str, line: int, column: int) -> list[ls_types.Location]:
|
| 350 |
+
# SourceKit LSP needs a short initialization period after startup
|
| 351 |
+
# before it can provide accurate reference information. This sleep
|
| 352 |
+
# prevents race conditions where references might not be available yet.
|
| 353 |
+
# Unfortunately, sourcekit doesn't send a signal when it's really ready
|
| 354 |
+
if not self._did_sleep_before_requesting_references:
|
| 355 |
+
self.logger.log("Sleeping 5s before requesting references for the first time", logging.DEBUG)
|
| 356 |
+
time.sleep(5)
|
| 357 |
+
self._did_sleep_before_requesting_references = True
|
| 358 |
+
return super().request_references(relative_file_path, line, column)
|
projects/ui/serena-new/src/solidlsp/language_servers/terraform_ls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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
import threading
|
| 5 |
+
|
| 6 |
+
from overrides import override
|
| 7 |
+
|
| 8 |
+
from solidlsp.ls import SolidLanguageServer
|
| 9 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 10 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 11 |
+
from solidlsp.ls_utils import PathUtils, PlatformUtils
|
| 12 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 13 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 14 |
+
from solidlsp.settings import SolidLSPSettings
|
| 15 |
+
|
| 16 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class TerraformLS(SolidLanguageServer):
|
| 20 |
+
"""
|
| 21 |
+
Provides Terraform specific instantiation of the LanguageServer class using terraform-ls.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
@override
|
| 25 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 26 |
+
return super().is_ignored_dirname(dirname) or dirname in [".terraform", "terraform.tfstate.d"]
|
| 27 |
+
|
| 28 |
+
@staticmethod
|
| 29 |
+
def _ensure_tf_command_available(logger: LanguageServerLogger):
|
| 30 |
+
logger.log("Starting terraform version detection...", logging.DEBUG)
|
| 31 |
+
|
| 32 |
+
# 1. Try to find terraform using shutil.which
|
| 33 |
+
terraform_cmd = shutil.which("terraform")
|
| 34 |
+
if terraform_cmd is not None:
|
| 35 |
+
logger.log(f"Found terraform via shutil.which: {terraform_cmd}", logging.DEBUG)
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
# TODO: is this needed?
|
| 39 |
+
# 2. Fallback to TERRAFORM_CLI_PATH (set by hashicorp/setup-terraform action)
|
| 40 |
+
if not terraform_cmd:
|
| 41 |
+
terraform_cli_path = os.environ.get("TERRAFORM_CLI_PATH")
|
| 42 |
+
if terraform_cli_path:
|
| 43 |
+
logger.log(f"Trying TERRAFORM_CLI_PATH: {terraform_cli_path}", logging.DEBUG)
|
| 44 |
+
# TODO: use binary name from runtime dependencies if we keep this code
|
| 45 |
+
if os.name == "nt":
|
| 46 |
+
terraform_binary = os.path.join(terraform_cli_path, "terraform.exe")
|
| 47 |
+
else:
|
| 48 |
+
terraform_binary = os.path.join(terraform_cli_path, "terraform")
|
| 49 |
+
if os.path.exists(terraform_binary):
|
| 50 |
+
terraform_cmd = terraform_binary
|
| 51 |
+
logger.log(f"Found terraform via TERRAFORM_CLI_PATH: {terraform_cmd}", logging.DEBUG)
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
raise RuntimeError(
|
| 55 |
+
"Terraform executable not found, please ensure Terraform is installed."
|
| 56 |
+
"See https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli for instructions."
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def _setup_runtime_dependencies(cls, logger: LanguageServerLogger, solidlsp_settings: SolidLSPSettings) -> str:
|
| 61 |
+
"""
|
| 62 |
+
Setup runtime dependencies for terraform-ls.
|
| 63 |
+
Downloads and installs terraform-ls if not already present.
|
| 64 |
+
"""
|
| 65 |
+
cls._ensure_tf_command_available(logger)
|
| 66 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 67 |
+
deps = RuntimeDependencyCollection(
|
| 68 |
+
[
|
| 69 |
+
RuntimeDependency(
|
| 70 |
+
id="TerraformLS",
|
| 71 |
+
description="terraform-ls for macOS (ARM64)",
|
| 72 |
+
url="https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_darwin_arm64.zip",
|
| 73 |
+
platform_id="osx-arm64",
|
| 74 |
+
archive_type="zip",
|
| 75 |
+
binary_name="terraform-ls",
|
| 76 |
+
),
|
| 77 |
+
RuntimeDependency(
|
| 78 |
+
id="TerraformLS",
|
| 79 |
+
description="terraform-ls for macOS (x64)",
|
| 80 |
+
url="https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_darwin_amd64.zip",
|
| 81 |
+
platform_id="osx-x64",
|
| 82 |
+
archive_type="zip",
|
| 83 |
+
binary_name="terraform-ls",
|
| 84 |
+
),
|
| 85 |
+
RuntimeDependency(
|
| 86 |
+
id="TerraformLS",
|
| 87 |
+
description="terraform-ls for Linux (ARM64)",
|
| 88 |
+
url="https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_linux_arm64.zip",
|
| 89 |
+
platform_id="linux-arm64",
|
| 90 |
+
archive_type="zip",
|
| 91 |
+
binary_name="terraform-ls",
|
| 92 |
+
),
|
| 93 |
+
RuntimeDependency(
|
| 94 |
+
id="TerraformLS",
|
| 95 |
+
description="terraform-ls for Linux (x64)",
|
| 96 |
+
url="https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_linux_amd64.zip",
|
| 97 |
+
platform_id="linux-x64",
|
| 98 |
+
archive_type="zip",
|
| 99 |
+
binary_name="terraform-ls",
|
| 100 |
+
),
|
| 101 |
+
RuntimeDependency(
|
| 102 |
+
id="TerraformLS",
|
| 103 |
+
description="terraform-ls for Windows (x64)",
|
| 104 |
+
url="https://releases.hashicorp.com/terraform-ls/0.36.5/terraform-ls_0.36.5_windows_amd64.zip",
|
| 105 |
+
platform_id="win-x64",
|
| 106 |
+
archive_type="zip",
|
| 107 |
+
binary_name="terraform-ls.exe",
|
| 108 |
+
),
|
| 109 |
+
]
|
| 110 |
+
)
|
| 111 |
+
dependency = deps.single_for_current_platform()
|
| 112 |
+
|
| 113 |
+
terraform_ls_executable_path = deps.binary_path(cls.ls_resources_dir(solidlsp_settings))
|
| 114 |
+
if not os.path.exists(terraform_ls_executable_path):
|
| 115 |
+
logger.log(f"Downloading terraform-ls from {dependency.url}", logging.INFO)
|
| 116 |
+
deps.install(logger, cls.ls_resources_dir(solidlsp_settings))
|
| 117 |
+
|
| 118 |
+
assert os.path.exists(terraform_ls_executable_path), f"terraform-ls executable not found at {terraform_ls_executable_path}"
|
| 119 |
+
|
| 120 |
+
# Make the executable file executable on Unix-like systems
|
| 121 |
+
if platform_id.value != "win-x64":
|
| 122 |
+
os.chmod(terraform_ls_executable_path, 0o755)
|
| 123 |
+
|
| 124 |
+
return terraform_ls_executable_path
|
| 125 |
+
|
| 126 |
+
def __init__(
|
| 127 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 128 |
+
):
|
| 129 |
+
"""
|
| 130 |
+
Creates a TerraformLS instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 131 |
+
"""
|
| 132 |
+
terraform_ls_executable_path = self._setup_runtime_dependencies(logger, solidlsp_settings)
|
| 133 |
+
|
| 134 |
+
super().__init__(
|
| 135 |
+
config,
|
| 136 |
+
logger,
|
| 137 |
+
repository_root_path,
|
| 138 |
+
ProcessLaunchInfo(cmd=f"{terraform_ls_executable_path} serve", cwd=repository_root_path),
|
| 139 |
+
"terraform",
|
| 140 |
+
solidlsp_settings,
|
| 141 |
+
)
|
| 142 |
+
self.server_ready = threading.Event()
|
| 143 |
+
self.request_id = 0
|
| 144 |
+
|
| 145 |
+
@staticmethod
|
| 146 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 147 |
+
"""
|
| 148 |
+
Returns the initialize params for the Terraform Language Server.
|
| 149 |
+
"""
|
| 150 |
+
root_uri = PathUtils.path_to_uri(repository_absolute_path)
|
| 151 |
+
return {
|
| 152 |
+
"processId": os.getpid(),
|
| 153 |
+
"locale": "en",
|
| 154 |
+
"rootPath": repository_absolute_path,
|
| 155 |
+
"rootUri": root_uri,
|
| 156 |
+
"capabilities": {
|
| 157 |
+
"textDocument": {
|
| 158 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 159 |
+
"completion": {"dynamicRegistration": True, "completionItem": {"snippetSupport": True}},
|
| 160 |
+
"definition": {"dynamicRegistration": True},
|
| 161 |
+
"documentSymbol": {
|
| 162 |
+
"dynamicRegistration": True,
|
| 163 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 164 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 165 |
+
},
|
| 166 |
+
},
|
| 167 |
+
"workspace": {"workspaceFolders": True, "didChangeConfiguration": {"dynamicRegistration": True}},
|
| 168 |
+
},
|
| 169 |
+
"workspaceFolders": [
|
| 170 |
+
{
|
| 171 |
+
"name": os.path.basename(repository_absolute_path),
|
| 172 |
+
"uri": root_uri,
|
| 173 |
+
}
|
| 174 |
+
],
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
def _start_server(self):
|
| 178 |
+
"""Start terraform-ls server process"""
|
| 179 |
+
|
| 180 |
+
def register_capability_handler(params):
|
| 181 |
+
return
|
| 182 |
+
|
| 183 |
+
def window_log_message(msg):
|
| 184 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 185 |
+
|
| 186 |
+
def do_nothing(params):
|
| 187 |
+
return
|
| 188 |
+
|
| 189 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 190 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 191 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 192 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 193 |
+
|
| 194 |
+
self.logger.log("Starting terraform-ls server process", logging.INFO)
|
| 195 |
+
self.server.start()
|
| 196 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 197 |
+
|
| 198 |
+
self.logger.log(
|
| 199 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 200 |
+
logging.INFO,
|
| 201 |
+
)
|
| 202 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 203 |
+
|
| 204 |
+
# Verify server capabilities
|
| 205 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 206 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 207 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 208 |
+
|
| 209 |
+
self.server.notify.initialized({})
|
| 210 |
+
self.completions_available.set()
|
| 211 |
+
|
| 212 |
+
# terraform-ls server is typically ready immediately after initialization
|
| 213 |
+
self.server_ready.set()
|
| 214 |
+
self.server_ready.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/typescript_language_server.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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. Contains various configurations and settings specific to TypeScript.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import shutil
|
| 9 |
+
import threading
|
| 10 |
+
|
| 11 |
+
from overrides import override
|
| 12 |
+
from sensai.util.logging import LogTime
|
| 13 |
+
|
| 14 |
+
from solidlsp.ls import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 16 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 17 |
+
from solidlsp.ls_utils import PlatformId, PlatformUtils
|
| 18 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 19 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 20 |
+
from solidlsp.settings import SolidLSPSettings
|
| 21 |
+
|
| 22 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 23 |
+
|
| 24 |
+
# Platform-specific imports
|
| 25 |
+
if os.name != "nt": # Unix-like systems
|
| 26 |
+
import pwd
|
| 27 |
+
else:
|
| 28 |
+
# Dummy pwd module for Windows
|
| 29 |
+
class pwd:
|
| 30 |
+
@staticmethod
|
| 31 |
+
def getpwuid(uid):
|
| 32 |
+
return type("obj", (), {"pw_name": os.environ.get("USERNAME", "unknown")})()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Conditionally import pwd module (Unix-only)
|
| 36 |
+
if not PlatformUtils.get_platform_id().value.startswith("win"):
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class TypeScriptLanguageServer(SolidLanguageServer):
|
| 41 |
+
"""
|
| 42 |
+
Provides TypeScript specific instantiation of the LanguageServer class. Contains various configurations and settings specific to TypeScript.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(
|
| 46 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 47 |
+
):
|
| 48 |
+
"""
|
| 49 |
+
Creates a TypeScriptLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 50 |
+
"""
|
| 51 |
+
ts_lsp_executable_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 52 |
+
super().__init__(
|
| 53 |
+
config,
|
| 54 |
+
logger,
|
| 55 |
+
repository_root_path,
|
| 56 |
+
ProcessLaunchInfo(cmd=ts_lsp_executable_path, cwd=repository_root_path),
|
| 57 |
+
"typescript",
|
| 58 |
+
solidlsp_settings,
|
| 59 |
+
)
|
| 60 |
+
self.server_ready = threading.Event()
|
| 61 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 62 |
+
|
| 63 |
+
@override
|
| 64 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 65 |
+
return super().is_ignored_dirname(dirname) or dirname in [
|
| 66 |
+
"node_modules",
|
| 67 |
+
"dist",
|
| 68 |
+
"build",
|
| 69 |
+
"coverage",
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
@classmethod
|
| 73 |
+
def _setup_runtime_dependencies(
|
| 74 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 75 |
+
) -> list[str]:
|
| 76 |
+
"""
|
| 77 |
+
Setup runtime dependencies for TypeScript Language Server and return the command to start the server.
|
| 78 |
+
"""
|
| 79 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 80 |
+
|
| 81 |
+
valid_platforms = [
|
| 82 |
+
PlatformId.LINUX_x64,
|
| 83 |
+
PlatformId.LINUX_arm64,
|
| 84 |
+
PlatformId.OSX,
|
| 85 |
+
PlatformId.OSX_x64,
|
| 86 |
+
PlatformId.OSX_arm64,
|
| 87 |
+
PlatformId.WIN_x64,
|
| 88 |
+
PlatformId.WIN_arm64,
|
| 89 |
+
]
|
| 90 |
+
assert platform_id in valid_platforms, f"Platform {platform_id} is not supported for multilspy javascript/typescript at the moment"
|
| 91 |
+
|
| 92 |
+
deps = RuntimeDependencyCollection(
|
| 93 |
+
[
|
| 94 |
+
RuntimeDependency(
|
| 95 |
+
id="typescript",
|
| 96 |
+
description="typescript package",
|
| 97 |
+
command=["npm", "install", "--prefix", "./", "typescript@5.5.4"],
|
| 98 |
+
platform_id="any",
|
| 99 |
+
),
|
| 100 |
+
RuntimeDependency(
|
| 101 |
+
id="typescript-language-server",
|
| 102 |
+
description="typescript-language-server package",
|
| 103 |
+
command=["npm", "install", "--prefix", "./", "typescript-language-server@4.3.3"],
|
| 104 |
+
platform_id="any",
|
| 105 |
+
),
|
| 106 |
+
]
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
# Verify both node and npm are installed
|
| 110 |
+
is_node_installed = shutil.which("node") is not None
|
| 111 |
+
assert is_node_installed, "node is not installed or isn't in PATH. Please install NodeJS and try again."
|
| 112 |
+
is_npm_installed = shutil.which("npm") is not None
|
| 113 |
+
assert is_npm_installed, "npm is not installed or isn't in PATH. Please install npm and try again."
|
| 114 |
+
|
| 115 |
+
# Verify both node and npm are installed
|
| 116 |
+
is_node_installed = shutil.which("node") is not None
|
| 117 |
+
assert is_node_installed, "node is not installed or isn't in PATH. Please install NodeJS and try again."
|
| 118 |
+
is_npm_installed = shutil.which("npm") is not None
|
| 119 |
+
assert is_npm_installed, "npm is not installed or isn't in PATH. Please install npm and try again."
|
| 120 |
+
|
| 121 |
+
# Install typescript and typescript-language-server if not already installed
|
| 122 |
+
tsserver_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "ts-lsp")
|
| 123 |
+
tsserver_executable_path = os.path.join(tsserver_ls_dir, "node_modules", ".bin", "typescript-language-server")
|
| 124 |
+
if not os.path.exists(tsserver_executable_path):
|
| 125 |
+
logger.log(f"Typescript Language Server executable not found at {tsserver_executable_path}. Installing...", logging.INFO)
|
| 126 |
+
with LogTime("Installation of TypeScript language server dependencies", logger=logger.logger):
|
| 127 |
+
deps.install(logger, tsserver_ls_dir)
|
| 128 |
+
|
| 129 |
+
if not os.path.exists(tsserver_executable_path):
|
| 130 |
+
raise FileNotFoundError(
|
| 131 |
+
f"typescript-language-server executable not found at {tsserver_executable_path}, something went wrong with the installation."
|
| 132 |
+
)
|
| 133 |
+
return [tsserver_executable_path, "--stdio"]
|
| 134 |
+
|
| 135 |
+
@staticmethod
|
| 136 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 137 |
+
"""
|
| 138 |
+
Returns the initialize params for the TypeScript Language Server.
|
| 139 |
+
"""
|
| 140 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 141 |
+
initialize_params = {
|
| 142 |
+
"locale": "en",
|
| 143 |
+
"capabilities": {
|
| 144 |
+
"textDocument": {
|
| 145 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 146 |
+
"completion": {"dynamicRegistration": True, "completionItem": {"snippetSupport": True}},
|
| 147 |
+
"definition": {"dynamicRegistration": True},
|
| 148 |
+
"references": {"dynamicRegistration": True},
|
| 149 |
+
"documentSymbol": {
|
| 150 |
+
"dynamicRegistration": True,
|
| 151 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 152 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 153 |
+
},
|
| 154 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 155 |
+
"signatureHelp": {"dynamicRegistration": True},
|
| 156 |
+
"codeAction": {"dynamicRegistration": True},
|
| 157 |
+
},
|
| 158 |
+
"workspace": {
|
| 159 |
+
"workspaceFolders": True,
|
| 160 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 161 |
+
"symbol": {"dynamicRegistration": True},
|
| 162 |
+
},
|
| 163 |
+
},
|
| 164 |
+
"processId": os.getpid(),
|
| 165 |
+
"rootPath": repository_absolute_path,
|
| 166 |
+
"rootUri": root_uri,
|
| 167 |
+
"workspaceFolders": [
|
| 168 |
+
{
|
| 169 |
+
"uri": root_uri,
|
| 170 |
+
"name": os.path.basename(repository_absolute_path),
|
| 171 |
+
}
|
| 172 |
+
],
|
| 173 |
+
}
|
| 174 |
+
return initialize_params
|
| 175 |
+
|
| 176 |
+
def _start_server(self):
|
| 177 |
+
"""
|
| 178 |
+
Starts the TypeScript Language Server, waits for the server to be ready and yields the LanguageServer instance.
|
| 179 |
+
|
| 180 |
+
Usage:
|
| 181 |
+
```
|
| 182 |
+
async with lsp.start_server():
|
| 183 |
+
# LanguageServer has been initialized and ready to serve requests
|
| 184 |
+
await lsp.request_definition(...)
|
| 185 |
+
await lsp.request_references(...)
|
| 186 |
+
# Shutdown the LanguageServer on exit from scope
|
| 187 |
+
# LanguageServer has been shutdown
|
| 188 |
+
"""
|
| 189 |
+
|
| 190 |
+
def register_capability_handler(params):
|
| 191 |
+
assert "registrations" in params
|
| 192 |
+
for registration in params["registrations"]:
|
| 193 |
+
if registration["method"] == "workspace/executeCommand":
|
| 194 |
+
self.initialize_searcher_command_available.set()
|
| 195 |
+
# TypeScript doesn't have a direct equivalent to resolve_main_method
|
| 196 |
+
# You might want to set a different flag or remove this line
|
| 197 |
+
# self.resolve_main_method_available.set()
|
| 198 |
+
return
|
| 199 |
+
|
| 200 |
+
def execute_client_command_handler(params):
|
| 201 |
+
return []
|
| 202 |
+
|
| 203 |
+
def do_nothing(params):
|
| 204 |
+
return
|
| 205 |
+
|
| 206 |
+
def window_log_message(msg):
|
| 207 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 208 |
+
|
| 209 |
+
def check_experimental_status(params):
|
| 210 |
+
"""
|
| 211 |
+
Also listen for experimental/serverStatus as a backup signal
|
| 212 |
+
"""
|
| 213 |
+
if params.get("quiescent") == True:
|
| 214 |
+
self.server_ready.set()
|
| 215 |
+
self.completions_available.set()
|
| 216 |
+
|
| 217 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 218 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 219 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 220 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 221 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 222 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 223 |
+
|
| 224 |
+
self.logger.log("Starting TypeScript server process", logging.INFO)
|
| 225 |
+
self.server.start()
|
| 226 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 227 |
+
|
| 228 |
+
self.logger.log(
|
| 229 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 230 |
+
logging.INFO,
|
| 231 |
+
)
|
| 232 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 233 |
+
|
| 234 |
+
# TypeScript-specific capability checks
|
| 235 |
+
assert init_response["capabilities"]["textDocumentSync"] == 2
|
| 236 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 237 |
+
assert init_response["capabilities"]["completionProvider"] == {
|
| 238 |
+
"triggerCharacters": [".", '"', "'", "/", "@", "<"],
|
| 239 |
+
"resolveProvider": True,
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
self.server.notify.initialized({})
|
| 243 |
+
if self.server_ready.wait(timeout=1.0):
|
| 244 |
+
self.logger.log("TypeScript server is ready", logging.INFO)
|
| 245 |
+
else:
|
| 246 |
+
self.logger.log("Timeout waiting for TypeScript server to become ready, proceeding anyway", logging.INFO)
|
| 247 |
+
# Fallback: assume server is ready after timeout
|
| 248 |
+
self.server_ready.set()
|
| 249 |
+
self.completions_available.set()
|
| 250 |
+
|
| 251 |
+
@override
|
| 252 |
+
def _get_wait_time_for_cross_file_referencing(self) -> float:
|
| 253 |
+
return 1
|
projects/ui/serena-new/src/solidlsp/language_servers/vts_language_server.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Language Server implementation for TypeScript/JavaScript using https://github.com/yioneko/vtsls,
|
| 3 |
+
which provides TypeScript language server functionality via VSCode's TypeScript extension
|
| 4 |
+
(contrary to typescript-language-server, which uses the TypeScript compiler directly).
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import pathlib
|
| 10 |
+
import shutil
|
| 11 |
+
import threading
|
| 12 |
+
|
| 13 |
+
from overrides import override
|
| 14 |
+
|
| 15 |
+
from solidlsp.ls import SolidLanguageServer
|
| 16 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 17 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 18 |
+
from solidlsp.ls_utils import PlatformId, PlatformUtils
|
| 19 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 20 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 21 |
+
from solidlsp.settings import SolidLSPSettings
|
| 22 |
+
|
| 23 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class VtsLanguageServer(SolidLanguageServer):
|
| 27 |
+
"""
|
| 28 |
+
Provides TypeScript specific instantiation of the LanguageServer class using vtsls.
|
| 29 |
+
Contains various configurations and settings specific to TypeScript via vtsls wrapper.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def __init__(
|
| 33 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 34 |
+
):
|
| 35 |
+
"""
|
| 36 |
+
Creates a VtsLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 37 |
+
"""
|
| 38 |
+
vts_lsp_executable_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 39 |
+
super().__init__(
|
| 40 |
+
config,
|
| 41 |
+
logger,
|
| 42 |
+
repository_root_path,
|
| 43 |
+
ProcessLaunchInfo(cmd=vts_lsp_executable_path, cwd=repository_root_path),
|
| 44 |
+
"typescript",
|
| 45 |
+
solidlsp_settings,
|
| 46 |
+
)
|
| 47 |
+
self.server_ready = threading.Event()
|
| 48 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 49 |
+
|
| 50 |
+
@override
|
| 51 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 52 |
+
return super().is_ignored_dirname(dirname) or dirname in [
|
| 53 |
+
"node_modules",
|
| 54 |
+
"dist",
|
| 55 |
+
"build",
|
| 56 |
+
"coverage",
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def _setup_runtime_dependencies(
|
| 61 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 62 |
+
) -> str:
|
| 63 |
+
"""
|
| 64 |
+
Setup runtime dependencies for VTS Language Server and return the command to start the server.
|
| 65 |
+
"""
|
| 66 |
+
platform_id = PlatformUtils.get_platform_id()
|
| 67 |
+
|
| 68 |
+
valid_platforms = [
|
| 69 |
+
PlatformId.LINUX_x64,
|
| 70 |
+
PlatformId.LINUX_arm64,
|
| 71 |
+
PlatformId.OSX,
|
| 72 |
+
PlatformId.OSX_x64,
|
| 73 |
+
PlatformId.OSX_arm64,
|
| 74 |
+
PlatformId.WIN_x64,
|
| 75 |
+
PlatformId.WIN_arm64,
|
| 76 |
+
]
|
| 77 |
+
assert platform_id in valid_platforms, f"Platform {platform_id} is not supported for vtsls at the moment"
|
| 78 |
+
|
| 79 |
+
deps = RuntimeDependencyCollection(
|
| 80 |
+
[
|
| 81 |
+
RuntimeDependency(
|
| 82 |
+
id="vtsls",
|
| 83 |
+
description="vtsls language server package",
|
| 84 |
+
command="npm install --prefix ./ @vtsls/language-server@0.2.9",
|
| 85 |
+
platform_id="any",
|
| 86 |
+
),
|
| 87 |
+
]
|
| 88 |
+
)
|
| 89 |
+
vts_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "vts-lsp")
|
| 90 |
+
vts_executable_path = os.path.join(vts_ls_dir, "vtsls")
|
| 91 |
+
|
| 92 |
+
# Verify both node and npm are installed
|
| 93 |
+
is_node_installed = shutil.which("node") is not None
|
| 94 |
+
assert is_node_installed, "node is not installed or isn't in PATH. Please install NodeJS and try again."
|
| 95 |
+
is_npm_installed = shutil.which("npm") is not None
|
| 96 |
+
assert is_npm_installed, "npm is not installed or isn't in PATH. Please install npm and try again."
|
| 97 |
+
|
| 98 |
+
# Install vtsls if not already installed
|
| 99 |
+
if not os.path.exists(vts_ls_dir):
|
| 100 |
+
os.makedirs(vts_ls_dir, exist_ok=True)
|
| 101 |
+
deps.install(logger, vts_ls_dir)
|
| 102 |
+
|
| 103 |
+
vts_executable_path = os.path.join(vts_ls_dir, "node_modules", ".bin", "vtsls")
|
| 104 |
+
|
| 105 |
+
assert os.path.exists(vts_executable_path), "vtsls executable not found. Please install @vtsls/language-server and try again."
|
| 106 |
+
return f"{vts_executable_path} --stdio"
|
| 107 |
+
|
| 108 |
+
@staticmethod
|
| 109 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 110 |
+
"""
|
| 111 |
+
Returns the initialize params for the VTS Language Server.
|
| 112 |
+
"""
|
| 113 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 114 |
+
initialize_params = {
|
| 115 |
+
"locale": "en",
|
| 116 |
+
"capabilities": {
|
| 117 |
+
"textDocument": {
|
| 118 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 119 |
+
"definition": {"dynamicRegistration": True},
|
| 120 |
+
"references": {"dynamicRegistration": True},
|
| 121 |
+
"documentSymbol": {
|
| 122 |
+
"dynamicRegistration": True,
|
| 123 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 124 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 125 |
+
},
|
| 126 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 127 |
+
"signatureHelp": {"dynamicRegistration": True},
|
| 128 |
+
"codeAction": {"dynamicRegistration": True},
|
| 129 |
+
},
|
| 130 |
+
"workspace": {
|
| 131 |
+
"workspaceFolders": True,
|
| 132 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 133 |
+
"symbol": {"dynamicRegistration": True},
|
| 134 |
+
"configuration": True, # This might be needed for vtsls
|
| 135 |
+
},
|
| 136 |
+
},
|
| 137 |
+
"processId": os.getpid(),
|
| 138 |
+
"rootPath": repository_absolute_path,
|
| 139 |
+
"rootUri": root_uri,
|
| 140 |
+
"workspaceFolders": [
|
| 141 |
+
{
|
| 142 |
+
"uri": root_uri,
|
| 143 |
+
"name": os.path.basename(repository_absolute_path),
|
| 144 |
+
}
|
| 145 |
+
],
|
| 146 |
+
}
|
| 147 |
+
return initialize_params
|
| 148 |
+
|
| 149 |
+
def _start_server(self):
|
| 150 |
+
"""
|
| 151 |
+
Starts the VTS Language Server, waits for the server to be ready and yields the LanguageServer instance.
|
| 152 |
+
|
| 153 |
+
Usage:
|
| 154 |
+
```
|
| 155 |
+
async with lsp.start_server():
|
| 156 |
+
# LanguageServer has been initialized and ready to serve requests
|
| 157 |
+
await lsp.request_definition(...)
|
| 158 |
+
await lsp.request_references(...)
|
| 159 |
+
# Shutdown the LanguageServer on exit from scope
|
| 160 |
+
# LanguageServer has been shutdown
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
def register_capability_handler(params):
|
| 164 |
+
assert "registrations" in params
|
| 165 |
+
for registration in params["registrations"]:
|
| 166 |
+
if registration["method"] == "workspace/executeCommand":
|
| 167 |
+
self.initialize_searcher_command_available.set()
|
| 168 |
+
return
|
| 169 |
+
|
| 170 |
+
def execute_client_command_handler(params):
|
| 171 |
+
return []
|
| 172 |
+
|
| 173 |
+
def workspace_configuration_handler(params):
|
| 174 |
+
# VTS may request workspace configuration
|
| 175 |
+
# Return empty configuration for each requested item
|
| 176 |
+
if "items" in params:
|
| 177 |
+
return [{}] * len(params["items"])
|
| 178 |
+
return {}
|
| 179 |
+
|
| 180 |
+
def do_nothing(params):
|
| 181 |
+
return
|
| 182 |
+
|
| 183 |
+
def window_log_message(msg):
|
| 184 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 185 |
+
|
| 186 |
+
def check_experimental_status(params):
|
| 187 |
+
"""
|
| 188 |
+
Also listen for experimental/serverStatus as a backup signal
|
| 189 |
+
"""
|
| 190 |
+
if params.get("quiescent") is True:
|
| 191 |
+
self.server_ready.set()
|
| 192 |
+
self.completions_available.set()
|
| 193 |
+
|
| 194 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 195 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 196 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 197 |
+
self.server.on_request("workspace/configuration", workspace_configuration_handler)
|
| 198 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 199 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 200 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 201 |
+
|
| 202 |
+
self.logger.log("Starting VTS server process", logging.INFO)
|
| 203 |
+
self.server.start()
|
| 204 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 205 |
+
|
| 206 |
+
self.logger.log(
|
| 207 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 208 |
+
logging.INFO,
|
| 209 |
+
)
|
| 210 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 211 |
+
|
| 212 |
+
# VTS-specific capability checks
|
| 213 |
+
# Be more flexible with capabilities since vtsls might have different structure
|
| 214 |
+
self.logger.log(f"VTS init response capabilities: {init_response['capabilities']}", logging.DEBUG)
|
| 215 |
+
|
| 216 |
+
# Basic checks to ensure essential capabilities are present
|
| 217 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 218 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 219 |
+
|
| 220 |
+
# Log the actual values for debugging
|
| 221 |
+
self.logger.log(f"textDocumentSync: {init_response['capabilities']['textDocumentSync']}", logging.DEBUG)
|
| 222 |
+
self.logger.log(f"completionProvider: {init_response['capabilities']['completionProvider']}", logging.DEBUG)
|
| 223 |
+
|
| 224 |
+
self.server.notify.initialized({})
|
| 225 |
+
if self.server_ready.wait(timeout=1.0):
|
| 226 |
+
self.logger.log("VTS server is ready", logging.INFO)
|
| 227 |
+
else:
|
| 228 |
+
self.logger.log("Timeout waiting for VTS server to become ready, proceeding anyway", logging.INFO)
|
| 229 |
+
# Fallback: assume server is ready after timeout
|
| 230 |
+
self.server_ready.set()
|
| 231 |
+
self.completions_available.set()
|
| 232 |
+
|
| 233 |
+
@override
|
| 234 |
+
def _get_wait_time_for_cross_file_referencing(self) -> float:
|
| 235 |
+
return 1
|
projects/ui/serena-new/src/solidlsp/language_servers/zls.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Zig specific instantiation of the LanguageServer class using ZLS (Zig Language Server).
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import platform
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
import threading
|
| 12 |
+
|
| 13 |
+
from overrides import override
|
| 14 |
+
|
| 15 |
+
from solidlsp.ls import SolidLanguageServer
|
| 16 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 17 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 18 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 19 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 20 |
+
from solidlsp.settings import SolidLSPSettings
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class ZigLanguageServer(SolidLanguageServer):
|
| 24 |
+
"""
|
| 25 |
+
Provides Zig specific instantiation of the LanguageServer class using ZLS.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
@override
|
| 29 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 30 |
+
# For Zig projects, we should ignore:
|
| 31 |
+
# - zig-cache: build cache directory
|
| 32 |
+
# - zig-out: default build output directory
|
| 33 |
+
# - .zig-cache: alternative cache location
|
| 34 |
+
# - node_modules: if the project has JavaScript components
|
| 35 |
+
return super().is_ignored_dirname(dirname) or dirname in ["zig-cache", "zig-out", ".zig-cache", "node_modules", "build", "dist"]
|
| 36 |
+
|
| 37 |
+
@staticmethod
|
| 38 |
+
def _get_zig_version():
|
| 39 |
+
"""Get the installed Zig version or None if not found."""
|
| 40 |
+
try:
|
| 41 |
+
result = subprocess.run(["zig", "version"], capture_output=True, text=True, check=False)
|
| 42 |
+
if result.returncode == 0:
|
| 43 |
+
return result.stdout.strip()
|
| 44 |
+
except FileNotFoundError:
|
| 45 |
+
return None
|
| 46 |
+
return None
|
| 47 |
+
|
| 48 |
+
@staticmethod
|
| 49 |
+
def _get_zls_version():
|
| 50 |
+
"""Get the installed ZLS version or None if not found."""
|
| 51 |
+
try:
|
| 52 |
+
result = subprocess.run(["zls", "--version"], capture_output=True, text=True, check=False)
|
| 53 |
+
if result.returncode == 0:
|
| 54 |
+
return result.stdout.strip()
|
| 55 |
+
except FileNotFoundError:
|
| 56 |
+
return None
|
| 57 |
+
return None
|
| 58 |
+
|
| 59 |
+
@staticmethod
|
| 60 |
+
def _check_zls_installed():
|
| 61 |
+
"""Check if ZLS is installed in the system."""
|
| 62 |
+
return shutil.which("zls") is not None
|
| 63 |
+
|
| 64 |
+
@staticmethod
|
| 65 |
+
def _setup_runtime_dependency():
|
| 66 |
+
"""
|
| 67 |
+
Check if required Zig runtime dependencies are available.
|
| 68 |
+
Raises RuntimeError with helpful message if dependencies are missing.
|
| 69 |
+
"""
|
| 70 |
+
# Check for Windows and provide error message
|
| 71 |
+
if platform.system() == "Windows":
|
| 72 |
+
raise RuntimeError(
|
| 73 |
+
"Windows is not supported by ZLS in this integration. "
|
| 74 |
+
"Cross-file references don't work reliably on Windows. Reason unknown."
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
zig_version = ZigLanguageServer._get_zig_version()
|
| 78 |
+
if not zig_version:
|
| 79 |
+
raise RuntimeError(
|
| 80 |
+
"Zig is not installed. Please install Zig from https://ziglang.org/download/ and make sure it is added to your PATH."
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
if not ZigLanguageServer._check_zls_installed():
|
| 84 |
+
zls_version = ZigLanguageServer._get_zls_version()
|
| 85 |
+
if not zls_version:
|
| 86 |
+
raise RuntimeError(
|
| 87 |
+
"Found Zig but ZLS (Zig Language Server) is not installed.\n"
|
| 88 |
+
"Please install ZLS from https://github.com/zigtools/zls\n"
|
| 89 |
+
"You can install it via:\n"
|
| 90 |
+
" - Package managers (brew install zls, scoop install zls, etc.)\n"
|
| 91 |
+
" - Download pre-built binaries from GitHub releases\n"
|
| 92 |
+
" - Build from source with: zig build -Doptimize=ReleaseSafe\n\n"
|
| 93 |
+
"After installation, make sure 'zls' is added to your PATH."
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
return True
|
| 97 |
+
|
| 98 |
+
def __init__(
|
| 99 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 100 |
+
):
|
| 101 |
+
self._setup_runtime_dependency()
|
| 102 |
+
|
| 103 |
+
super().__init__(
|
| 104 |
+
config,
|
| 105 |
+
logger,
|
| 106 |
+
repository_root_path,
|
| 107 |
+
ProcessLaunchInfo(cmd="zls", cwd=repository_root_path),
|
| 108 |
+
"zig",
|
| 109 |
+
solidlsp_settings,
|
| 110 |
+
)
|
| 111 |
+
self.server_ready = threading.Event()
|
| 112 |
+
self.request_id = 0
|
| 113 |
+
|
| 114 |
+
@staticmethod
|
| 115 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 116 |
+
"""
|
| 117 |
+
Returns the initialize params for the Zig Language Server.
|
| 118 |
+
"""
|
| 119 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 120 |
+
initialize_params = {
|
| 121 |
+
"locale": "en",
|
| 122 |
+
"capabilities": {
|
| 123 |
+
"textDocument": {
|
| 124 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 125 |
+
"definition": {"dynamicRegistration": True},
|
| 126 |
+
"references": {"dynamicRegistration": True},
|
| 127 |
+
"documentSymbol": {
|
| 128 |
+
"dynamicRegistration": True,
|
| 129 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 130 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 131 |
+
},
|
| 132 |
+
"completion": {
|
| 133 |
+
"dynamicRegistration": True,
|
| 134 |
+
"completionItem": {
|
| 135 |
+
"snippetSupport": True,
|
| 136 |
+
"commitCharactersSupport": True,
|
| 137 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 138 |
+
"deprecatedSupport": True,
|
| 139 |
+
"preselectSupport": True,
|
| 140 |
+
},
|
| 141 |
+
},
|
| 142 |
+
"hover": {
|
| 143 |
+
"dynamicRegistration": True,
|
| 144 |
+
"contentFormat": ["markdown", "plaintext"],
|
| 145 |
+
},
|
| 146 |
+
},
|
| 147 |
+
"workspace": {
|
| 148 |
+
"workspaceFolders": True,
|
| 149 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 150 |
+
"configuration": True,
|
| 151 |
+
},
|
| 152 |
+
},
|
| 153 |
+
"processId": os.getpid(),
|
| 154 |
+
"rootPath": repository_absolute_path,
|
| 155 |
+
"rootUri": root_uri,
|
| 156 |
+
"workspaceFolders": [
|
| 157 |
+
{
|
| 158 |
+
"uri": root_uri,
|
| 159 |
+
"name": os.path.basename(repository_absolute_path),
|
| 160 |
+
}
|
| 161 |
+
],
|
| 162 |
+
"initializationOptions": {
|
| 163 |
+
# ZLS specific options based on schema.json
|
| 164 |
+
# Critical paths for ZLS to understand the project
|
| 165 |
+
"zig_exe_path": shutil.which("zig"), # Path to zig executable
|
| 166 |
+
"zig_lib_path": None, # Let ZLS auto-detect
|
| 167 |
+
"build_runner_path": None, # Let ZLS use its built-in runner
|
| 168 |
+
"global_cache_path": None, # Let ZLS use default cache
|
| 169 |
+
# Build configuration
|
| 170 |
+
"enable_build_on_save": True, # Enable to analyze project structure
|
| 171 |
+
"build_on_save_args": ["build"],
|
| 172 |
+
# Features
|
| 173 |
+
"enable_snippets": True,
|
| 174 |
+
"enable_argument_placeholders": True,
|
| 175 |
+
"semantic_tokens": "full",
|
| 176 |
+
"warn_style": False,
|
| 177 |
+
"highlight_global_var_declarations": False,
|
| 178 |
+
"skip_std_references": False,
|
| 179 |
+
"prefer_ast_check_as_child_process": True,
|
| 180 |
+
"completion_label_details": True,
|
| 181 |
+
# Inlay hints configuration
|
| 182 |
+
"inlay_hints_show_variable_type_hints": True,
|
| 183 |
+
"inlay_hints_show_struct_literal_field_type": True,
|
| 184 |
+
"inlay_hints_show_parameter_name": True,
|
| 185 |
+
"inlay_hints_show_builtin": True,
|
| 186 |
+
"inlay_hints_exclude_single_argument": True,
|
| 187 |
+
"inlay_hints_hide_redundant_param_names": False,
|
| 188 |
+
"inlay_hints_hide_redundant_param_names_last_token": False,
|
| 189 |
+
},
|
| 190 |
+
}
|
| 191 |
+
return initialize_params
|
| 192 |
+
|
| 193 |
+
def _start_server(self):
|
| 194 |
+
"""Start ZLS server process"""
|
| 195 |
+
|
| 196 |
+
def register_capability_handler(params):
|
| 197 |
+
return
|
| 198 |
+
|
| 199 |
+
def window_log_message(msg):
|
| 200 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 201 |
+
|
| 202 |
+
def do_nothing(params):
|
| 203 |
+
return
|
| 204 |
+
|
| 205 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 206 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 207 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 208 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 209 |
+
|
| 210 |
+
self.logger.log("Starting ZLS server process", logging.INFO)
|
| 211 |
+
self.server.start()
|
| 212 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 213 |
+
|
| 214 |
+
self.logger.log(
|
| 215 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 216 |
+
logging.INFO,
|
| 217 |
+
)
|
| 218 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 219 |
+
|
| 220 |
+
# Verify server capabilities
|
| 221 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 222 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 223 |
+
assert "documentSymbolProvider" in init_response["capabilities"]
|
| 224 |
+
assert "referencesProvider" in init_response["capabilities"]
|
| 225 |
+
|
| 226 |
+
self.server.notify.initialized({})
|
| 227 |
+
self.completions_available.set()
|
| 228 |
+
|
| 229 |
+
# ZLS server is ready after initialization
|
| 230 |
+
self.server_ready.set()
|
| 231 |
+
self.server_ready.wait()
|
| 232 |
+
|
| 233 |
+
# Open build.zig if it exists to help ZLS understand project structure
|
| 234 |
+
build_zig_path = os.path.join(self.repository_root_path, "build.zig")
|
| 235 |
+
if os.path.exists(build_zig_path):
|
| 236 |
+
try:
|
| 237 |
+
with open(build_zig_path, encoding="utf-8") as f:
|
| 238 |
+
content = f.read()
|
| 239 |
+
uri = pathlib.Path(build_zig_path).as_uri()
|
| 240 |
+
self.server.notify.did_open_text_document(
|
| 241 |
+
{
|
| 242 |
+
"textDocument": {
|
| 243 |
+
"uri": uri,
|
| 244 |
+
"languageId": "zig",
|
| 245 |
+
"version": 1,
|
| 246 |
+
"text": content,
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
)
|
| 250 |
+
self.logger.log("Opened build.zig to provide project context to ZLS", logging.INFO)
|
| 251 |
+
except Exception as e:
|
| 252 |
+
self.logger.log(f"Failed to open build.zig: {e}", logging.WARNING)
|
projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_constants.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module contains constants used in the LSP protocol.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class LSPConstants:
|
| 7 |
+
"""
|
| 8 |
+
This class contains constants used in the LSP protocol.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
# the key for uri used to represent paths
|
| 12 |
+
URI = "uri"
|
| 13 |
+
|
| 14 |
+
# the key for range, which is a from and to position within a text document
|
| 15 |
+
RANGE = "range"
|
| 16 |
+
|
| 17 |
+
# A key used in LocationLink type, used as the span of the origin link
|
| 18 |
+
ORIGIN_SELECTION_RANGE = "originSelectionRange"
|
| 19 |
+
|
| 20 |
+
# A key used in LocationLink type, used as the target uri of the link
|
| 21 |
+
TARGET_URI = "targetUri"
|
| 22 |
+
|
| 23 |
+
# A key used in LocationLink type, used as the target range of the link
|
| 24 |
+
TARGET_RANGE = "targetRange"
|
| 25 |
+
|
| 26 |
+
# A key used in LocationLink type, used as the target selection range of the link
|
| 27 |
+
TARGET_SELECTION_RANGE = "targetSelectionRange"
|
| 28 |
+
|
| 29 |
+
# key for the textDocument field in the request
|
| 30 |
+
TEXT_DOCUMENT = "textDocument"
|
| 31 |
+
|
| 32 |
+
# key used to represent the language a document is in - "java", "csharp", etc.
|
| 33 |
+
LANGUAGE_ID = "languageId"
|
| 34 |
+
|
| 35 |
+
# key used to represent the version of a document (a shared value between the client and server)
|
| 36 |
+
VERSION = "version"
|
| 37 |
+
|
| 38 |
+
# key used to represent the text of a document being sent from the client to the server on open
|
| 39 |
+
TEXT = "text"
|
| 40 |
+
|
| 41 |
+
# key used to represent a position (line and colnum) within a text document
|
| 42 |
+
POSITION = "position"
|
| 43 |
+
|
| 44 |
+
# key used to represent the line number of a position
|
| 45 |
+
LINE = "line"
|
| 46 |
+
|
| 47 |
+
# key used to represent the column number of a position
|
| 48 |
+
CHARACTER = "character"
|
| 49 |
+
|
| 50 |
+
# key used to represent the changes made to a document
|
| 51 |
+
CONTENT_CHANGES = "contentChanges"
|
| 52 |
+
|
| 53 |
+
# key used to represent name of symbols
|
| 54 |
+
NAME = "name"
|
| 55 |
+
|
| 56 |
+
# key used to represent the kind of symbols
|
| 57 |
+
KIND = "kind"
|
| 58 |
+
|
| 59 |
+
# key used to represent children in document symbols
|
| 60 |
+
CHILDREN = "children"
|
| 61 |
+
|
| 62 |
+
# key used to represent the location in symbols
|
| 63 |
+
LOCATION = "location"
|
| 64 |
+
|
| 65 |
+
# Severity level of the diagnostic
|
| 66 |
+
SEVERITY = "severity"
|
| 67 |
+
|
| 68 |
+
# The message of the diagnostic
|
| 69 |
+
MESSAGE = "message"
|
projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_requests.py
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Code generated. DO NOT EDIT.
|
| 2 |
+
# LSP v3.17.0
|
| 3 |
+
# TODO: Look into use of https://pypi.org/project/ts2python/ to generate the types for https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
This file provides the python interface corresponding to the requests and notifications defined in Typescript in the language server protocol.
|
| 7 |
+
This file is obtained from https://github.com/predragnikolic/OLSP under the MIT License with the following terms:
|
| 8 |
+
|
| 9 |
+
MIT License
|
| 10 |
+
|
| 11 |
+
Copyright (c) 2023 Предраг Николић
|
| 12 |
+
|
| 13 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 14 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 15 |
+
in the Software without restriction, including without limitation the rights
|
| 16 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 17 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 18 |
+
furnished to do so, subject to the following conditions:
|
| 19 |
+
|
| 20 |
+
The above copyright notice and this permission notice shall be included in all
|
| 21 |
+
copies or substantial portions of the Software.
|
| 22 |
+
|
| 23 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 24 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 25 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 26 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 27 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 28 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 29 |
+
SOFTWARE.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
from typing import Union
|
| 33 |
+
|
| 34 |
+
from solidlsp.lsp_protocol_handler import lsp_types
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class LspRequest:
|
| 38 |
+
def __init__(self, send_request):
|
| 39 |
+
self.send_request = send_request
|
| 40 |
+
|
| 41 |
+
async def implementation(
|
| 42 |
+
self, params: lsp_types.ImplementationParams
|
| 43 |
+
) -> Union["lsp_types.Definition", list["lsp_types.LocationLink"], None]:
|
| 44 |
+
"""A request to resolve the implementation locations of a symbol at a given text
|
| 45 |
+
document position. The request's parameter is of type [TextDocumentPositionParams]
|
| 46 |
+
(#TextDocumentPositionParams) the response is of type {@link Definition} or a
|
| 47 |
+
Thenable that resolves to such.
|
| 48 |
+
"""
|
| 49 |
+
return await self.send_request("textDocument/implementation", params)
|
| 50 |
+
|
| 51 |
+
async def type_definition(
|
| 52 |
+
self, params: lsp_types.TypeDefinitionParams
|
| 53 |
+
) -> Union["lsp_types.Definition", list["lsp_types.LocationLink"], None]:
|
| 54 |
+
"""A request to resolve the type definition locations of a symbol at a given text
|
| 55 |
+
document position. The request's parameter is of type [TextDocumentPositionParams]
|
| 56 |
+
(#TextDocumentPositionParams) the response is of type {@link Definition} or a
|
| 57 |
+
Thenable that resolves to such.
|
| 58 |
+
"""
|
| 59 |
+
return await self.send_request("textDocument/typeDefinition", params)
|
| 60 |
+
|
| 61 |
+
async def document_color(self, params: lsp_types.DocumentColorParams) -> list["lsp_types.ColorInformation"]:
|
| 62 |
+
"""A request to list all color symbols found in a given text document. The request's
|
| 63 |
+
parameter is of type {@link DocumentColorParams} the
|
| 64 |
+
response is of type {@link ColorInformation ColorInformation[]} or a Thenable
|
| 65 |
+
that resolves to such.
|
| 66 |
+
"""
|
| 67 |
+
return await self.send_request("textDocument/documentColor", params)
|
| 68 |
+
|
| 69 |
+
async def color_presentation(self, params: lsp_types.ColorPresentationParams) -> list["lsp_types.ColorPresentation"]:
|
| 70 |
+
"""A request to list all presentation for a color. The request's
|
| 71 |
+
parameter is of type {@link ColorPresentationParams} the
|
| 72 |
+
response is of type {@link ColorInformation ColorInformation[]} or a Thenable
|
| 73 |
+
that resolves to such.
|
| 74 |
+
"""
|
| 75 |
+
return await self.send_request("textDocument/colorPresentation", params)
|
| 76 |
+
|
| 77 |
+
async def folding_range(self, params: lsp_types.FoldingRangeParams) -> list["lsp_types.FoldingRange"] | None:
|
| 78 |
+
"""A request to provide folding ranges in a document. The request's
|
| 79 |
+
parameter is of type {@link FoldingRangeParams}, the
|
| 80 |
+
response is of type {@link FoldingRangeList} or a Thenable
|
| 81 |
+
that resolves to such.
|
| 82 |
+
"""
|
| 83 |
+
return await self.send_request("textDocument/foldingRange", params)
|
| 84 |
+
|
| 85 |
+
async def declaration(
|
| 86 |
+
self, params: lsp_types.DeclarationParams
|
| 87 |
+
) -> Union["lsp_types.Declaration", list["lsp_types.LocationLink"], None]:
|
| 88 |
+
"""A request to resolve the type definition locations of a symbol at a given text
|
| 89 |
+
document position. The request's parameter is of type [TextDocumentPositionParams]
|
| 90 |
+
(#TextDocumentPositionParams) the response is of type {@link Declaration}
|
| 91 |
+
or a typed array of {@link DeclarationLink} or a Thenable that resolves
|
| 92 |
+
to such.
|
| 93 |
+
"""
|
| 94 |
+
return await self.send_request("textDocument/declaration", params)
|
| 95 |
+
|
| 96 |
+
async def selection_range(self, params: lsp_types.SelectionRangeParams) -> list["lsp_types.SelectionRange"] | None:
|
| 97 |
+
"""A request to provide selection ranges in a document. The request's
|
| 98 |
+
parameter is of type {@link SelectionRangeParams}, the
|
| 99 |
+
response is of type {@link SelectionRange SelectionRange[]} or a Thenable
|
| 100 |
+
that resolves to such.
|
| 101 |
+
"""
|
| 102 |
+
return await self.send_request("textDocument/selectionRange", params)
|
| 103 |
+
|
| 104 |
+
async def prepare_call_hierarchy(self, params: lsp_types.CallHierarchyPrepareParams) -> list["lsp_types.CallHierarchyItem"] | None:
|
| 105 |
+
"""A request to result a `CallHierarchyItem` in a document at a given position.
|
| 106 |
+
Can be used as an input to an incoming or outgoing call hierarchy.
|
| 107 |
+
|
| 108 |
+
@since 3.16.0
|
| 109 |
+
"""
|
| 110 |
+
return await self.send_request("textDocument/prepareCallHierarchy", params)
|
| 111 |
+
|
| 112 |
+
async def incoming_calls(
|
| 113 |
+
self, params: lsp_types.CallHierarchyIncomingCallsParams
|
| 114 |
+
) -> list["lsp_types.CallHierarchyIncomingCall"] | None:
|
| 115 |
+
"""A request to resolve the incoming calls for a given `CallHierarchyItem`.
|
| 116 |
+
|
| 117 |
+
@since 3.16.0
|
| 118 |
+
"""
|
| 119 |
+
return await self.send_request("callHierarchy/incomingCalls", params)
|
| 120 |
+
|
| 121 |
+
async def outgoing_calls(
|
| 122 |
+
self, params: lsp_types.CallHierarchyOutgoingCallsParams
|
| 123 |
+
) -> list["lsp_types.CallHierarchyOutgoingCall"] | None:
|
| 124 |
+
"""A request to resolve the outgoing calls for a given `CallHierarchyItem`.
|
| 125 |
+
|
| 126 |
+
@since 3.16.0
|
| 127 |
+
"""
|
| 128 |
+
return await self.send_request("callHierarchy/outgoingCalls", params)
|
| 129 |
+
|
| 130 |
+
async def semantic_tokens_full(self, params: lsp_types.SemanticTokensParams) -> Union["lsp_types.SemanticTokens", None]:
|
| 131 |
+
"""@since 3.16.0"""
|
| 132 |
+
return await self.send_request("textDocument/semanticTokens/full", params)
|
| 133 |
+
|
| 134 |
+
async def semantic_tokens_delta(
|
| 135 |
+
self, params: lsp_types.SemanticTokensDeltaParams
|
| 136 |
+
) -> Union["lsp_types.SemanticTokens", "lsp_types.SemanticTokensDelta", None]:
|
| 137 |
+
"""@since 3.16.0"""
|
| 138 |
+
return await self.send_request("textDocument/semanticTokens/full/delta", params)
|
| 139 |
+
|
| 140 |
+
async def semantic_tokens_range(self, params: lsp_types.SemanticTokensRangeParams) -> Union["lsp_types.SemanticTokens", None]:
|
| 141 |
+
"""@since 3.16.0"""
|
| 142 |
+
return await self.send_request("textDocument/semanticTokens/range", params)
|
| 143 |
+
|
| 144 |
+
async def linked_editing_range(self, params: lsp_types.LinkedEditingRangeParams) -> Union["lsp_types.LinkedEditingRanges", None]:
|
| 145 |
+
"""A request to provide ranges that can be edited together.
|
| 146 |
+
|
| 147 |
+
@since 3.16.0
|
| 148 |
+
"""
|
| 149 |
+
return await self.send_request("textDocument/linkedEditingRange", params)
|
| 150 |
+
|
| 151 |
+
async def will_create_files(self, params: lsp_types.CreateFilesParams) -> Union["lsp_types.WorkspaceEdit", None]:
|
| 152 |
+
"""The will create files request is sent from the client to the server before files are actually
|
| 153 |
+
created as long as the creation is triggered from within the client.
|
| 154 |
+
|
| 155 |
+
@since 3.16.0
|
| 156 |
+
"""
|
| 157 |
+
return await self.send_request("workspace/willCreateFiles", params)
|
| 158 |
+
|
| 159 |
+
async def will_rename_files(self, params: lsp_types.RenameFilesParams) -> Union["lsp_types.WorkspaceEdit", None]:
|
| 160 |
+
"""The will rename files request is sent from the client to the server before files are actually
|
| 161 |
+
renamed as long as the rename is triggered from within the client.
|
| 162 |
+
|
| 163 |
+
@since 3.16.0
|
| 164 |
+
"""
|
| 165 |
+
return await self.send_request("workspace/willRenameFiles", params)
|
| 166 |
+
|
| 167 |
+
async def will_delete_files(self, params: lsp_types.DeleteFilesParams) -> Union["lsp_types.WorkspaceEdit", None]:
|
| 168 |
+
"""The did delete files notification is sent from the client to the server when
|
| 169 |
+
files were deleted from within the client.
|
| 170 |
+
|
| 171 |
+
@since 3.16.0
|
| 172 |
+
"""
|
| 173 |
+
return await self.send_request("workspace/willDeleteFiles", params)
|
| 174 |
+
|
| 175 |
+
async def moniker(self, params: lsp_types.MonikerParams) -> list["lsp_types.Moniker"] | None:
|
| 176 |
+
"""A request to get the moniker of a symbol at a given text document position.
|
| 177 |
+
The request parameter is of type {@link TextDocumentPositionParams}.
|
| 178 |
+
The response is of type {@link Moniker Moniker[]} or `null`.
|
| 179 |
+
"""
|
| 180 |
+
return await self.send_request("textDocument/moniker", params)
|
| 181 |
+
|
| 182 |
+
async def prepare_type_hierarchy(self, params: lsp_types.TypeHierarchyPrepareParams) -> list["lsp_types.TypeHierarchyItem"] | None:
|
| 183 |
+
"""A request to result a `TypeHierarchyItem` in a document at a given position.
|
| 184 |
+
Can be used as an input to a subtypes or supertypes type hierarchy.
|
| 185 |
+
|
| 186 |
+
@since 3.17.0
|
| 187 |
+
"""
|
| 188 |
+
return await self.send_request("textDocument/prepareTypeHierarchy", params)
|
| 189 |
+
|
| 190 |
+
async def type_hierarchy_supertypes(
|
| 191 |
+
self, params: lsp_types.TypeHierarchySupertypesParams
|
| 192 |
+
) -> list["lsp_types.TypeHierarchyItem"] | None:
|
| 193 |
+
"""A request to resolve the supertypes for a given `TypeHierarchyItem`.
|
| 194 |
+
|
| 195 |
+
@since 3.17.0
|
| 196 |
+
"""
|
| 197 |
+
return await self.send_request("typeHierarchy/supertypes", params)
|
| 198 |
+
|
| 199 |
+
async def type_hierarchy_subtypes(self, params: lsp_types.TypeHierarchySubtypesParams) -> list["lsp_types.TypeHierarchyItem"] | None:
|
| 200 |
+
"""A request to resolve the subtypes for a given `TypeHierarchyItem`.
|
| 201 |
+
|
| 202 |
+
@since 3.17.0
|
| 203 |
+
"""
|
| 204 |
+
return await self.send_request("typeHierarchy/subtypes", params)
|
| 205 |
+
|
| 206 |
+
async def inline_value(self, params: lsp_types.InlineValueParams) -> list["lsp_types.InlineValue"] | None:
|
| 207 |
+
"""A request to provide inline values in a document. The request's parameter is of
|
| 208 |
+
type {@link InlineValueParams}, the response is of type
|
| 209 |
+
{@link InlineValue InlineValue[]} or a Thenable that resolves to such.
|
| 210 |
+
|
| 211 |
+
@since 3.17.0
|
| 212 |
+
"""
|
| 213 |
+
return await self.send_request("textDocument/inlineValue", params)
|
| 214 |
+
|
| 215 |
+
async def inlay_hint(self, params: lsp_types.InlayHintParams) -> list["lsp_types.InlayHint"] | None:
|
| 216 |
+
"""A request to provide inlay hints in a document. The request's parameter is of
|
| 217 |
+
type {@link InlayHintsParams}, the response is of type
|
| 218 |
+
{@link InlayHint InlayHint[]} or a Thenable that resolves to such.
|
| 219 |
+
|
| 220 |
+
@since 3.17.0
|
| 221 |
+
"""
|
| 222 |
+
return await self.send_request("textDocument/inlayHint", params)
|
| 223 |
+
|
| 224 |
+
async def resolve_inlay_hint(self, params: lsp_types.InlayHint) -> "lsp_types.InlayHint":
|
| 225 |
+
"""A request to resolve additional properties for an inlay hint.
|
| 226 |
+
The request's parameter is of type {@link InlayHint}, the response is
|
| 227 |
+
of type {@link InlayHint} or a Thenable that resolves to such.
|
| 228 |
+
|
| 229 |
+
@since 3.17.0
|
| 230 |
+
"""
|
| 231 |
+
return await self.send_request("inlayHint/resolve", params)
|
| 232 |
+
|
| 233 |
+
async def text_document_diagnostic(self, params: lsp_types.DocumentDiagnosticParams) -> "lsp_types.DocumentDiagnosticReport":
|
| 234 |
+
"""The document diagnostic request definition.
|
| 235 |
+
|
| 236 |
+
@since 3.17.0
|
| 237 |
+
"""
|
| 238 |
+
return await self.send_request("textDocument/diagnostic", params)
|
| 239 |
+
|
| 240 |
+
async def workspace_diagnostic(self, params: lsp_types.WorkspaceDiagnosticParams) -> "lsp_types.WorkspaceDiagnosticReport":
|
| 241 |
+
"""The workspace diagnostic request definition.
|
| 242 |
+
|
| 243 |
+
@since 3.17.0
|
| 244 |
+
"""
|
| 245 |
+
return await self.send_request("workspace/diagnostic", params)
|
| 246 |
+
|
| 247 |
+
async def initialize(self, params: lsp_types.InitializeParams) -> "lsp_types.InitializeResult":
|
| 248 |
+
"""The initialize request is sent from the client to the server.
|
| 249 |
+
It is sent once as the request after starting up the server.
|
| 250 |
+
The requests parameter is of type {@link InitializeParams}
|
| 251 |
+
the response if of type {@link InitializeResult} of a Thenable that
|
| 252 |
+
resolves to such.
|
| 253 |
+
"""
|
| 254 |
+
return await self.send_request("initialize", params)
|
| 255 |
+
|
| 256 |
+
async def shutdown(self) -> None:
|
| 257 |
+
"""A shutdown request is sent from the client to the server.
|
| 258 |
+
It is sent once when the client decides to shutdown the
|
| 259 |
+
server. The only notification that is sent after a shutdown request
|
| 260 |
+
is the exit event.
|
| 261 |
+
"""
|
| 262 |
+
return await self.send_request("shutdown")
|
| 263 |
+
|
| 264 |
+
async def will_save_wait_until(self, params: lsp_types.WillSaveTextDocumentParams) -> list["lsp_types.TextEdit"] | None:
|
| 265 |
+
"""A document will save request is sent from the client to the server before
|
| 266 |
+
the document is actually saved. The request can return an array of TextEdits
|
| 267 |
+
which will be applied to the text document before it is saved. Please note that
|
| 268 |
+
clients might drop results if computing the text edits took too long or if a
|
| 269 |
+
server constantly fails on this request. This is done to keep the save fast and
|
| 270 |
+
reliable.
|
| 271 |
+
"""
|
| 272 |
+
return await self.send_request("textDocument/willSaveWaitUntil", params)
|
| 273 |
+
|
| 274 |
+
async def completion(
|
| 275 |
+
self, params: lsp_types.CompletionParams
|
| 276 |
+
) -> Union[list["lsp_types.CompletionItem"], "lsp_types.CompletionList", None]:
|
| 277 |
+
"""Request to request completion at a given text document position. The request's
|
| 278 |
+
parameter is of type {@link TextDocumentPosition} the response
|
| 279 |
+
is of type {@link CompletionItem CompletionItem[]} or {@link CompletionList}
|
| 280 |
+
or a Thenable that resolves to such.
|
| 281 |
+
|
| 282 |
+
The request can delay the computation of the {@link CompletionItem.detail `detail`}
|
| 283 |
+
and {@link CompletionItem.documentation `documentation`} properties to the `completionItem/resolve`
|
| 284 |
+
request. However, properties that are needed for the initial sorting and filtering, like `sortText`,
|
| 285 |
+
`filterText`, `insertText`, and `textEdit`, must not be changed during resolve.
|
| 286 |
+
"""
|
| 287 |
+
return await self.send_request("textDocument/completion", params)
|
| 288 |
+
|
| 289 |
+
async def resolve_completion_item(self, params: lsp_types.CompletionItem) -> "lsp_types.CompletionItem":
|
| 290 |
+
"""Request to resolve additional information for a given completion item.The request's
|
| 291 |
+
parameter is of type {@link CompletionItem} the response
|
| 292 |
+
is of type {@link CompletionItem} or a Thenable that resolves to such.
|
| 293 |
+
"""
|
| 294 |
+
return await self.send_request("completionItem/resolve", params)
|
| 295 |
+
|
| 296 |
+
async def hover(self, params: lsp_types.HoverParams) -> Union["lsp_types.Hover", None]:
|
| 297 |
+
"""Request to request hover information at a given text document position. The request's
|
| 298 |
+
parameter is of type {@link TextDocumentPosition} the response is of
|
| 299 |
+
type {@link Hover} or a Thenable that resolves to such.
|
| 300 |
+
"""
|
| 301 |
+
return await self.send_request("textDocument/hover", params)
|
| 302 |
+
|
| 303 |
+
async def signature_help(self, params: lsp_types.SignatureHelpParams) -> Union["lsp_types.SignatureHelp", None]:
|
| 304 |
+
return await self.send_request("textDocument/signatureHelp", params)
|
| 305 |
+
|
| 306 |
+
async def definition(self, params: lsp_types.DefinitionParams) -> Union["lsp_types.Definition", list["lsp_types.LocationLink"], None]:
|
| 307 |
+
"""A request to resolve the definition location of a symbol at a given text
|
| 308 |
+
document position. The request's parameter is of type [TextDocumentPosition]
|
| 309 |
+
(#TextDocumentPosition) the response is of either type {@link Definition}
|
| 310 |
+
or a typed array of {@link DefinitionLink} or a Thenable that resolves
|
| 311 |
+
to such.
|
| 312 |
+
"""
|
| 313 |
+
return await self.send_request("textDocument/definition", params)
|
| 314 |
+
|
| 315 |
+
async def references(self, params: lsp_types.ReferenceParams) -> list["lsp_types.Location"] | None:
|
| 316 |
+
"""A request to resolve project-wide references for the symbol denoted
|
| 317 |
+
by the given text document position. The request's parameter is of
|
| 318 |
+
type {@link ReferenceParams} the response is of type
|
| 319 |
+
{@link Location Location[]} or a Thenable that resolves to such.
|
| 320 |
+
"""
|
| 321 |
+
return await self.send_request("textDocument/references", params)
|
| 322 |
+
|
| 323 |
+
async def document_highlight(self, params: lsp_types.DocumentHighlightParams) -> list["lsp_types.DocumentHighlight"] | None:
|
| 324 |
+
"""Request to resolve a {@link DocumentHighlight} for a given
|
| 325 |
+
text document position. The request's parameter is of type [TextDocumentPosition]
|
| 326 |
+
(#TextDocumentPosition) the request response is of type [DocumentHighlight[]]
|
| 327 |
+
(#DocumentHighlight) or a Thenable that resolves to such.
|
| 328 |
+
"""
|
| 329 |
+
return await self.send_request("textDocument/documentHighlight", params)
|
| 330 |
+
|
| 331 |
+
async def document_symbol(
|
| 332 |
+
self, params: lsp_types.DocumentSymbolParams
|
| 333 |
+
) -> list["lsp_types.SymbolInformation"] | list["lsp_types.DocumentSymbol"] | None:
|
| 334 |
+
"""A request to list all symbols found in a given text document. The request's
|
| 335 |
+
parameter is of type {@link TextDocumentIdentifier} the
|
| 336 |
+
response is of type {@link SymbolInformation SymbolInformation[]} or a Thenable
|
| 337 |
+
that resolves to such.
|
| 338 |
+
"""
|
| 339 |
+
return await self.send_request("textDocument/documentSymbol", params)
|
| 340 |
+
|
| 341 |
+
async def code_action(self, params: lsp_types.CodeActionParams) -> list[Union["lsp_types.Command", "lsp_types.CodeAction"]] | None:
|
| 342 |
+
"""A request to provide commands for the given text document and range."""
|
| 343 |
+
return await self.send_request("textDocument/codeAction", params)
|
| 344 |
+
|
| 345 |
+
async def resolve_code_action(self, params: lsp_types.CodeAction) -> "lsp_types.CodeAction":
|
| 346 |
+
"""Request to resolve additional information for a given code action.The request's
|
| 347 |
+
parameter is of type {@link CodeAction} the response
|
| 348 |
+
is of type {@link CodeAction} or a Thenable that resolves to such.
|
| 349 |
+
"""
|
| 350 |
+
return await self.send_request("codeAction/resolve", params)
|
| 351 |
+
|
| 352 |
+
async def workspace_symbol(
|
| 353 |
+
self, params: lsp_types.WorkspaceSymbolParams
|
| 354 |
+
) -> list["lsp_types.SymbolInformation"] | list["lsp_types.WorkspaceSymbol"] | None:
|
| 355 |
+
"""A request to list project-wide symbols matching the query string given
|
| 356 |
+
by the {@link WorkspaceSymbolParams}. The response is
|
| 357 |
+
of type {@link SymbolInformation SymbolInformation[]} or a Thenable that
|
| 358 |
+
resolves to such.
|
| 359 |
+
|
| 360 |
+
@since 3.17.0 - support for WorkspaceSymbol in the returned data. Clients
|
| 361 |
+
need to advertise support for WorkspaceSymbols via the client capability
|
| 362 |
+
`workspace.symbol.resolveSupport`.
|
| 363 |
+
"""
|
| 364 |
+
return await self.send_request("workspace/symbol", params)
|
| 365 |
+
|
| 366 |
+
async def resolve_workspace_symbol(self, params: lsp_types.WorkspaceSymbol) -> "lsp_types.WorkspaceSymbol":
|
| 367 |
+
"""A request to resolve the range inside the workspace
|
| 368 |
+
symbol's location.
|
| 369 |
+
|
| 370 |
+
@since 3.17.0
|
| 371 |
+
"""
|
| 372 |
+
return await self.send_request("workspaceSymbol/resolve", params)
|
| 373 |
+
|
| 374 |
+
async def code_lens(self, params: lsp_types.CodeLensParams) -> list["lsp_types.CodeLens"] | None:
|
| 375 |
+
"""A request to provide code lens for the given text document."""
|
| 376 |
+
return await self.send_request("textDocument/codeLens", params)
|
| 377 |
+
|
| 378 |
+
async def resolve_code_lens(self, params: lsp_types.CodeLens) -> "lsp_types.CodeLens":
|
| 379 |
+
"""A request to resolve a command for a given code lens."""
|
| 380 |
+
return await self.send_request("codeLens/resolve", params)
|
| 381 |
+
|
| 382 |
+
async def document_link(self, params: lsp_types.DocumentLinkParams) -> list["lsp_types.DocumentLink"] | None:
|
| 383 |
+
"""A request to provide document links"""
|
| 384 |
+
return await self.send_request("textDocument/documentLink", params)
|
| 385 |
+
|
| 386 |
+
async def resolve_document_link(self, params: lsp_types.DocumentLink) -> "lsp_types.DocumentLink":
|
| 387 |
+
"""Request to resolve additional information for a given document link. The request's
|
| 388 |
+
parameter is of type {@link DocumentLink} the response
|
| 389 |
+
is of type {@link DocumentLink} or a Thenable that resolves to such.
|
| 390 |
+
"""
|
| 391 |
+
return await self.send_request("documentLink/resolve", params)
|
| 392 |
+
|
| 393 |
+
async def formatting(self, params: lsp_types.DocumentFormattingParams) -> list["lsp_types.TextEdit"] | None:
|
| 394 |
+
"""A request to to format a whole document."""
|
| 395 |
+
return await self.send_request("textDocument/formatting", params)
|
| 396 |
+
|
| 397 |
+
async def range_formatting(self, params: lsp_types.DocumentRangeFormattingParams) -> list["lsp_types.TextEdit"] | None:
|
| 398 |
+
"""A request to to format a range in a document."""
|
| 399 |
+
return await self.send_request("textDocument/rangeFormatting", params)
|
| 400 |
+
|
| 401 |
+
async def on_type_formatting(self, params: lsp_types.DocumentOnTypeFormattingParams) -> list["lsp_types.TextEdit"] | None:
|
| 402 |
+
"""A request to format a document on type."""
|
| 403 |
+
return await self.send_request("textDocument/onTypeFormatting", params)
|
| 404 |
+
|
| 405 |
+
async def rename(self, params: lsp_types.RenameParams) -> Union["lsp_types.WorkspaceEdit", None]:
|
| 406 |
+
"""A request to rename a symbol."""
|
| 407 |
+
return await self.send_request("textDocument/rename", params)
|
| 408 |
+
|
| 409 |
+
async def prepare_rename(self, params: lsp_types.PrepareRenameParams) -> Union["lsp_types.PrepareRenameResult", None]:
|
| 410 |
+
"""A request to test and perform the setup necessary for a rename.
|
| 411 |
+
|
| 412 |
+
@since 3.16 - support for default behavior
|
| 413 |
+
"""
|
| 414 |
+
return await self.send_request("textDocument/prepareRename", params)
|
| 415 |
+
|
| 416 |
+
async def execute_command(self, params: lsp_types.ExecuteCommandParams) -> Union["lsp_types.LSPAny", None]:
|
| 417 |
+
"""A request send from the client to the server to execute a command. The request might return
|
| 418 |
+
a workspace edit which the client will apply to the workspace.
|
| 419 |
+
"""
|
| 420 |
+
return await self.send_request("workspace/executeCommand", params)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class LspNotification:
|
| 424 |
+
def __init__(self, send_notification):
|
| 425 |
+
self.send_notification = send_notification
|
| 426 |
+
|
| 427 |
+
def did_change_workspace_folders(self, params: lsp_types.DidChangeWorkspaceFoldersParams) -> None:
|
| 428 |
+
"""The `workspace/didChangeWorkspaceFolders` notification is sent from the client to the server when the workspace
|
| 429 |
+
folder configuration changes.
|
| 430 |
+
"""
|
| 431 |
+
return self.send_notification("workspace/didChangeWorkspaceFolders", params)
|
| 432 |
+
|
| 433 |
+
def cancel_work_done_progress(self, params: lsp_types.WorkDoneProgressCancelParams) -> None:
|
| 434 |
+
"""The `window/workDoneProgress/cancel` notification is sent from the client to the server to cancel a progress
|
| 435 |
+
initiated on the server side.
|
| 436 |
+
"""
|
| 437 |
+
return self.send_notification("window/workDoneProgress/cancel", params)
|
| 438 |
+
|
| 439 |
+
def did_create_files(self, params: lsp_types.CreateFilesParams) -> None:
|
| 440 |
+
"""The did create files notification is sent from the client to the server when
|
| 441 |
+
files were created from within the client.
|
| 442 |
+
|
| 443 |
+
@since 3.16.0
|
| 444 |
+
"""
|
| 445 |
+
return self.send_notification("workspace/didCreateFiles", params)
|
| 446 |
+
|
| 447 |
+
def did_rename_files(self, params: lsp_types.RenameFilesParams) -> None:
|
| 448 |
+
"""The did rename files notification is sent from the client to the server when
|
| 449 |
+
files were renamed from within the client.
|
| 450 |
+
|
| 451 |
+
@since 3.16.0
|
| 452 |
+
"""
|
| 453 |
+
return self.send_notification("workspace/didRenameFiles", params)
|
| 454 |
+
|
| 455 |
+
def did_delete_files(self, params: lsp_types.DeleteFilesParams) -> None:
|
| 456 |
+
"""The will delete files request is sent from the client to the server before files are actually
|
| 457 |
+
deleted as long as the deletion is triggered from within the client.
|
| 458 |
+
|
| 459 |
+
@since 3.16.0
|
| 460 |
+
"""
|
| 461 |
+
return self.send_notification("workspace/didDeleteFiles", params)
|
| 462 |
+
|
| 463 |
+
def did_open_notebook_document(self, params: lsp_types.DidOpenNotebookDocumentParams) -> None:
|
| 464 |
+
"""A notification sent when a notebook opens.
|
| 465 |
+
|
| 466 |
+
@since 3.17.0
|
| 467 |
+
"""
|
| 468 |
+
return self.send_notification("notebookDocument/didOpen", params)
|
| 469 |
+
|
| 470 |
+
def did_change_notebook_document(self, params: lsp_types.DidChangeNotebookDocumentParams) -> None:
|
| 471 |
+
return self.send_notification("notebookDocument/didChange", params)
|
| 472 |
+
|
| 473 |
+
def did_save_notebook_document(self, params: lsp_types.DidSaveNotebookDocumentParams) -> None:
|
| 474 |
+
"""A notification sent when a notebook document is saved.
|
| 475 |
+
|
| 476 |
+
@since 3.17.0
|
| 477 |
+
"""
|
| 478 |
+
return self.send_notification("notebookDocument/didSave", params)
|
| 479 |
+
|
| 480 |
+
def did_close_notebook_document(self, params: lsp_types.DidCloseNotebookDocumentParams) -> None:
|
| 481 |
+
"""A notification sent when a notebook closes.
|
| 482 |
+
|
| 483 |
+
@since 3.17.0
|
| 484 |
+
"""
|
| 485 |
+
return self.send_notification("notebookDocument/didClose", params)
|
| 486 |
+
|
| 487 |
+
def initialized(self, params: lsp_types.InitializedParams) -> None:
|
| 488 |
+
"""The initialized notification is sent from the client to the
|
| 489 |
+
server after the client is fully initialized and the server
|
| 490 |
+
is allowed to send requests from the server to the client.
|
| 491 |
+
"""
|
| 492 |
+
return self.send_notification("initialized", params)
|
| 493 |
+
|
| 494 |
+
def exit(self) -> None:
|
| 495 |
+
"""The exit event is sent from the client to the server to
|
| 496 |
+
ask the server to exit its process.
|
| 497 |
+
"""
|
| 498 |
+
return self.send_notification("exit")
|
| 499 |
+
|
| 500 |
+
def workspace_did_change_configuration(self, params: lsp_types.DidChangeConfigurationParams) -> None:
|
| 501 |
+
"""The configuration change notification is sent from the client to the server
|
| 502 |
+
when the client's configuration has changed. The notification contains
|
| 503 |
+
the changed configuration as defined by the language client.
|
| 504 |
+
"""
|
| 505 |
+
return self.send_notification("workspace/didChangeConfiguration", params)
|
| 506 |
+
|
| 507 |
+
def did_open_text_document(self, params: lsp_types.DidOpenTextDocumentParams) -> None:
|
| 508 |
+
"""The document open notification is sent from the client to the server to signal
|
| 509 |
+
newly opened text documents. The document's truth is now managed by the client
|
| 510 |
+
and the server must not try to read the document's truth using the document's
|
| 511 |
+
uri. Open in this sense means it is managed by the client. It doesn't necessarily
|
| 512 |
+
mean that its content is presented in an editor. An open notification must not
|
| 513 |
+
be sent more than once without a corresponding close notification send before.
|
| 514 |
+
This means open and close notification must be balanced and the max open count
|
| 515 |
+
is one.
|
| 516 |
+
"""
|
| 517 |
+
return self.send_notification("textDocument/didOpen", params)
|
| 518 |
+
|
| 519 |
+
def did_change_text_document(self, params: lsp_types.DidChangeTextDocumentParams) -> None:
|
| 520 |
+
"""The document change notification is sent from the client to the server to signal
|
| 521 |
+
changes to a text document.
|
| 522 |
+
"""
|
| 523 |
+
return self.send_notification("textDocument/didChange", params)
|
| 524 |
+
|
| 525 |
+
def did_close_text_document(self, params: lsp_types.DidCloseTextDocumentParams) -> None:
|
| 526 |
+
"""The document close notification is sent from the client to the server when
|
| 527 |
+
the document got closed in the client. The document's truth now exists where
|
| 528 |
+
the document's uri points to (e.g. if the document's uri is a file uri the
|
| 529 |
+
truth now exists on disk). As with the open notification the close notification
|
| 530 |
+
is about managing the document's content. Receiving a close notification
|
| 531 |
+
doesn't mean that the document was open in an editor before. A close
|
| 532 |
+
notification requires a previous open notification to be sent.
|
| 533 |
+
"""
|
| 534 |
+
return self.send_notification("textDocument/didClose", params)
|
| 535 |
+
|
| 536 |
+
def did_save_text_document(self, params: lsp_types.DidSaveTextDocumentParams) -> None:
|
| 537 |
+
"""The document save notification is sent from the client to the server when
|
| 538 |
+
the document got saved in the client.
|
| 539 |
+
"""
|
| 540 |
+
return self.send_notification("textDocument/didSave", params)
|
| 541 |
+
|
| 542 |
+
def will_save_text_document(self, params: lsp_types.WillSaveTextDocumentParams) -> None:
|
| 543 |
+
"""A document will save notification is sent from the client to the server before
|
| 544 |
+
the document is actually saved.
|
| 545 |
+
"""
|
| 546 |
+
return self.send_notification("textDocument/willSave", params)
|
| 547 |
+
|
| 548 |
+
def did_change_watched_files(self, params: lsp_types.DidChangeWatchedFilesParams) -> None:
|
| 549 |
+
"""The watched files notification is sent from the client to the server when
|
| 550 |
+
the client detects changes to file watched by the language client.
|
| 551 |
+
"""
|
| 552 |
+
return self.send_notification("workspace/didChangeWatchedFiles", params)
|
| 553 |
+
|
| 554 |
+
def set_trace(self, params: lsp_types.SetTraceParams) -> None:
|
| 555 |
+
return self.send_notification("$/setTrace", params)
|
| 556 |
+
|
| 557 |
+
def cancel_request(self, params: lsp_types.CancelParams) -> None:
|
| 558 |
+
return self.send_notification("$/cancelRequest", params)
|
| 559 |
+
|
| 560 |
+
def progress(self, params: lsp_types.ProgressParams) -> None:
|
| 561 |
+
return self.send_notification("$/progress", params)
|
projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/lsp_types.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
projects/ui/serena-new/src/solidlsp/lsp_protocol_handler/server.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This file provides the implementation of the JSON-RPC client, that launches and
|
| 3 |
+
communicates with the language server.
|
| 4 |
+
|
| 5 |
+
The initial implementation of this file was obtained from
|
| 6 |
+
https://github.com/predragnikolic/OLSP under the MIT License with the following terms:
|
| 7 |
+
|
| 8 |
+
MIT License
|
| 9 |
+
|
| 10 |
+
Copyright (c) 2023 Предраг Николић
|
| 11 |
+
|
| 12 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 13 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 14 |
+
in the Software without restriction, including without limitation the rights
|
| 15 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 16 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 17 |
+
furnished to do so, subject to the following conditions:
|
| 18 |
+
|
| 19 |
+
The above copyright notice and this permission notice shall be included in all
|
| 20 |
+
copies or substantial portions of the Software.
|
| 21 |
+
|
| 22 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 23 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 24 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 25 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 26 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 27 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 28 |
+
SOFTWARE.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
import dataclasses
|
| 32 |
+
import json
|
| 33 |
+
import logging
|
| 34 |
+
import os
|
| 35 |
+
from typing import Any, Union
|
| 36 |
+
|
| 37 |
+
from .lsp_types import ErrorCodes
|
| 38 |
+
|
| 39 |
+
StringDict = dict[str, Any]
|
| 40 |
+
PayloadLike = Union[list[StringDict], StringDict, None]
|
| 41 |
+
CONTENT_LENGTH = "Content-Length: "
|
| 42 |
+
ENCODING = "utf-8"
|
| 43 |
+
log = logging.getLogger(__name__)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@dataclasses.dataclass
|
| 47 |
+
class ProcessLaunchInfo:
|
| 48 |
+
"""
|
| 49 |
+
This class is used to store the information required to launch a process.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
# The command to launch the process
|
| 53 |
+
cmd: str | list[str]
|
| 54 |
+
|
| 55 |
+
# The environment variables to set for the process
|
| 56 |
+
env: dict[str, str] = dataclasses.field(default_factory=dict)
|
| 57 |
+
|
| 58 |
+
# The working directory for the process
|
| 59 |
+
cwd: str = os.getcwd()
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class LSPError(Exception):
|
| 63 |
+
def __init__(self, code: ErrorCodes, message: str) -> None:
|
| 64 |
+
super().__init__(message)
|
| 65 |
+
self.code = code
|
| 66 |
+
|
| 67 |
+
def to_lsp(self) -> StringDict:
|
| 68 |
+
return {"code": self.code, "message": super().__str__()}
|
| 69 |
+
|
| 70 |
+
@classmethod
|
| 71 |
+
def from_lsp(cls, d: StringDict) -> "LSPError":
|
| 72 |
+
return LSPError(d["code"], d["message"])
|
| 73 |
+
|
| 74 |
+
def __str__(self) -> str:
|
| 75 |
+
return f"{super().__str__()} ({self.code})"
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def make_response(request_id: Any, params: PayloadLike) -> StringDict:
|
| 79 |
+
return {"jsonrpc": "2.0", "id": request_id, "result": params}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def make_error_response(request_id: Any, err: LSPError) -> StringDict:
|
| 83 |
+
return {"jsonrpc": "2.0", "id": request_id, "error": err.to_lsp()}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def make_notification(method: str, params: PayloadLike) -> StringDict:
|
| 87 |
+
return {"jsonrpc": "2.0", "method": method, "params": params}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def make_request(method: str, request_id: Any, params: PayloadLike) -> StringDict:
|
| 91 |
+
return {"jsonrpc": "2.0", "method": method, "id": request_id, "params": params}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
class StopLoopException(Exception):
|
| 95 |
+
pass
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def create_message(payload: PayloadLike):
|
| 99 |
+
body = json.dumps(payload, check_circular=False, ensure_ascii=False, separators=(",", ":")).encode(ENCODING)
|
| 100 |
+
return (
|
| 101 |
+
f"Content-Length: {len(body)}\r\n".encode(ENCODING),
|
| 102 |
+
"Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n\r\n".encode(ENCODING),
|
| 103 |
+
body,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class MessageType:
|
| 108 |
+
error = 1
|
| 109 |
+
warning = 2
|
| 110 |
+
info = 3
|
| 111 |
+
log = 4
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def content_length(line: bytes) -> int | None:
|
| 115 |
+
if line.startswith(b"Content-Length: "):
|
| 116 |
+
_, value = line.split(b"Content-Length: ")
|
| 117 |
+
value = value.strip()
|
| 118 |
+
try:
|
| 119 |
+
return int(value)
|
| 120 |
+
except ValueError:
|
| 121 |
+
raise ValueError(f"Invalid Content-Length header: {value}")
|
| 122 |
+
return None
|