Refactoring, stage 1: move ls implementations one step up

Paths to jsons were adjusted in the modules, minimal change, tests run through
This commit is contained in:
Michael Panchenko
2025-07-05 12:46:37 +02:00
parent 6cd7f8155c
commit e8e417a18e
16 changed files with 37 additions and 34 deletions
+1
View File
@@ -204,6 +204,7 @@ pylint.html
# dynamic LS installations
/src/multilspy/language_servers/*/static
/src/solidlsp/language_servers/*/static
/src/solidlsp/language_servers/static
# clojure-lsp temporary files
.calva/
@@ -47,7 +47,7 @@ class ClangdLanguageServer(SolidLanguageServer):
"""
platform_id = PlatformUtils.get_platform_id()
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json")) as f:
with open(os.path.join(os.path.dirname(__file__), "clangd_language_server", "runtime_dependencies.json")) as f:
d = json.load(f)
del d["_description"]
@@ -90,7 +90,7 @@ class ClangdLanguageServer(SolidLanguageServer):
"""
Returns the initialize params for the clangd Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json")) as f:
with open(os.path.join(os.path.dirname(__file__), "clangd_language_server", "initialize_params.json")) as f:
d = json.load(f)
del d["_description"]
@@ -159,7 +159,7 @@ class EclipseJDTLS(SolidLanguageServer):
"""
platformId = PlatformUtils.get_platform_id()
with open(str(PurePath(os.path.dirname(__file__), "runtime_dependencies.json")), encoding="utf-8") as f:
with open(str(PurePath(os.path.dirname(__file__), "eclipse_jdtls", "runtime_dependencies.json")), encoding="utf-8") as f:
runtimeDependencies = json.load(f)
del runtimeDependencies["_description"]
@@ -252,7 +252,7 @@ class EclipseJDTLS(SolidLanguageServer):
Returns the initialize parameters for the EclipseJDTLS server.
"""
# Look into https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java to understand all the options available
with open(str(PurePath(os.path.dirname(__file__), "initialize_params.json")), encoding="utf-8") as f:
with open(str(PurePath(os.path.dirname(__file__), "eclipse_jdtls", "initialize_params.json")), encoding="utf-8") as f:
d: InitializeParams = json.load(f)
del d["_description"]
@@ -88,7 +88,7 @@ class Gopls(SolidLanguageServer):
"""
Returns the initialize params for the TypeScript Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "gopls", "initialize_params.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -50,7 +50,7 @@ class Intelephense(SolidLanguageServer):
]
assert platform_id in valid_platforms, f"Platform {platform_id} is not supported for multilspy PHP at the moment"
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "intelephense", "runtime_dependencies.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -108,7 +108,7 @@ class Intelephense(SolidLanguageServer):
"""
Returns the initialize params for the TypeScript Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "intelephense", "initialize_params.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -66,7 +66,7 @@ class KotlinLanguageServer(SolidLanguageServer):
), "Only Windows, Linux and macOS platforms are supported for Kotlin in multilspy at the moment"
# Load dependency information
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "kotlin_language_server", "runtime_dependencies.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -74,7 +74,7 @@ class KotlinLanguageServer(SolidLanguageServer):
java_dependency = d["java"][platform_id.value]
# Setup paths for dependencies
static_dir = os.path.join(os.path.dirname(__file__), "static")
static_dir = os.path.join(os.path.dirname(__file__), "static", "kotlin_language_server")
os.makedirs(static_dir, exist_ok=True)
# Setup Java paths
@@ -129,7 +129,9 @@ class KotlinLanguageServer(SolidLanguageServer):
"""
Returns the initialize params for the Kotlin Language Server.
"""
with open(str(pathlib.PurePath(os.path.dirname(__file__), "initialize_params.json")), encoding="utf-8") as f:
with open(
str(pathlib.PurePath(os.path.dirname(__file__), "kotlin_language_server", "initialize_params.json")), encoding="utf-8"
) as f:
d: InitializeParams = json.load(f)
del d["_description"]
@@ -51,7 +51,7 @@ class RustAnalyzer(SolidLanguageServer):
"""
platform_id = PlatformUtils.get_platform_id()
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "rust_analyzer", "runtime_dependencies.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -82,7 +82,7 @@ class RustAnalyzer(SolidLanguageServer):
"""
Returns the initialize params for the Rust Analyzer Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "rust_analyzer", "initialize_params.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -52,7 +52,7 @@ class Solargraph(SolidLanguageServer):
"""
Setup runtime dependencies for Solargraph.
"""
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "solargraph", "runtime_dependencies.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -97,7 +97,7 @@ class Solargraph(SolidLanguageServer):
"""
Returns the initialize params for the Solargraph Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json"), encoding="utf-8") as f:
with open(os.path.join(os.path.dirname(__file__), "solargraph", "initialize_params.json"), encoding="utf-8") as f:
d = json.load(f)
del d["_description"]
@@ -82,7 +82,7 @@ class TypeScriptLanguageServer(SolidLanguageServer):
]
assert platform_id in valid_platforms, f"Platform {platform_id} is not supported for multilspy javascript/typescript at the moment"
with open(os.path.join(os.path.dirname(__file__), "runtime_dependencies.json")) as f:
with open(os.path.join(os.path.dirname(__file__), "typescript_language_server", "runtime_dependencies.json")) as f:
d = json.load(f)
del d["_description"]
@@ -134,7 +134,7 @@ class TypeScriptLanguageServer(SolidLanguageServer):
"""
Returns the initialize params for the TypeScript Language Server.
"""
with open(os.path.join(os.path.dirname(__file__), "initialize_params.json")) as f:
with open(os.path.join(os.path.dirname(__file__), "typescript_language_server", "initialize_params.json")) as f:
d = json.load(f)
del d["_description"]
+12 -12
View File
@@ -108,28 +108,28 @@ class SolidLanguageServer(ABC):
ls: SolidLanguageServer
if config.code_language == Language.PYTHON:
from solidlsp.language_servers.pyright_language_server.pyright_server import (
from solidlsp.language_servers.pyright_server import (
PyrightServer,
)
ls = PyrightServer(config, logger, repository_root_path)
elif config.code_language == Language.JAVA:
from solidlsp.language_servers.eclipse_jdtls.eclipse_jdtls import (
from solidlsp.language_servers.eclipse_jdtls import (
EclipseJDTLS,
)
ls = EclipseJDTLS(config, logger, repository_root_path)
elif config.code_language == Language.KOTLIN:
from solidlsp.language_servers.kotlin_language_server.kotlin_language_server import (
from solidlsp.language_servers.kotlin_language_server import (
KotlinLanguageServer,
)
ls = KotlinLanguageServer(config, logger, repository_root_path)
elif config.code_language == Language.RUST:
from solidlsp.language_servers.rust_analyzer.rust_analyzer import (
from solidlsp.language_servers.rust_analyzer import (
RustAnalyzer,
)
@@ -141,44 +141,44 @@ class SolidLanguageServer(ABC):
# from solidlsp.language_servers.omnisharp.omnisharp import OmniSharp
# ls = OmniSharp(config, logger, repository_root_path)
from solidlsp.language_servers.csharp_language_server.csharp_language_server import CSharpLanguageServer
from solidlsp.language_servers.csharp_language_server import CSharpLanguageServer
ls = CSharpLanguageServer(config, logger, repository_root_path)
elif config.code_language == Language.TYPESCRIPT:
from solidlsp.language_servers.typescript_language_server.typescript_language_server import (
from solidlsp.language_servers.typescript_language_server import (
TypeScriptLanguageServer,
)
ls = TypeScriptLanguageServer(config, logger, repository_root_path)
elif config.code_language == Language.GO:
from solidlsp.language_servers.gopls.gopls import Gopls
from solidlsp.language_servers.gopls import Gopls
ls = Gopls(config, logger, repository_root_path)
elif config.code_language == Language.RUBY:
from solidlsp.language_servers.solargraph.solargraph import Solargraph
from solidlsp.language_servers.solargraph import Solargraph
ls = Solargraph(config, logger, repository_root_path)
elif config.code_language == Language.DART:
from solidlsp.language_servers.dart_language_server.dart_language_server import DartLanguageServer
from solidlsp.language_servers.dart_language_server import DartLanguageServer
ls = DartLanguageServer(config, logger, repository_root_path)
elif config.code_language == Language.CPP:
from solidlsp.language_servers.clangd_language_server.clangd_language_server import ClangdLanguageServer
from solidlsp.language_servers.clangd_language_server import ClangdLanguageServer
ls = ClangdLanguageServer(config, logger, repository_root_path)
elif config.code_language == Language.PHP:
from solidlsp.language_servers.intelephense.intelephense import Intelephense
from solidlsp.language_servers.intelephense import Intelephense
ls = Intelephense(config, logger, repository_root_path)
elif config.code_language == Language.CLOJURE:
from solidlsp.language_servers.clojure_lsp.clojure_lsp import ClojureLSP
from solidlsp.language_servers.clojure_lsp import ClojureLSP
ls = ClojureLSP(config, logger, repository_root_path)
+1 -1
View File
@@ -1,6 +1,6 @@
from pathlib import Path
from solidlsp.language_servers.clojure_lsp.clojure_lsp import verify_clojure_cli
from solidlsp.language_servers.clojure_lsp import verify_clojure_cli
def _test_clojure_cli() -> bool:
+5 -5
View File
@@ -6,7 +6,7 @@ from unittest.mock import Mock, patch
import pytest
from solidlsp import SolidLanguageServer
from solidlsp.language_servers.csharp_language_server.csharp_language_server import (
from solidlsp.language_servers.csharp_language_server import (
CSharpLanguageServer,
breadth_first_file_scan,
find_solution_or_project_file,
@@ -196,8 +196,8 @@ class TestCSharpSolutionProjectOpening:
# Should still prefer .sln file even though it's deeper
assert result == str(solution_file)
@patch("solidlsp.language_servers.csharp_language_server.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
@patch("solidlsp.language_servers.csharp_language_server.csharp_language_server.CSharpLanguageServer._start_server")
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server")
def test_csharp_language_server_logs_solution_discovery(self, mock_start_server, mock_ensure_server_installed):
"""Test that CSharpLanguageServer logs solution/project discovery during initialization."""
with tempfile.TemporaryDirectory() as cache_dir:
@@ -221,8 +221,8 @@ class TestCSharpSolutionProjectOpening:
# Verify that logger was called with solution file discovery
mock_logger.log.assert_any_call(f"Found solution/project file: {solution_file}", 20) # logging.INFO
@patch("solidlsp.language_servers.csharp_language_server.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
@patch("solidlsp.language_servers.csharp_language_server.csharp_language_server.CSharpLanguageServer._start_server")
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._ensure_server_installed")
@patch("solidlsp.language_servers.csharp_language_server.CSharpLanguageServer._start_server")
def test_csharp_language_server_logs_no_solution_warning(self, mock_start_server, mock_ensure_server_installed):
"""Test that CSharpLanguageServer logs warning when no solution/project files are found."""
with tempfile.TemporaryDirectory() as cache_dir: