From 12290821a0e089e2c25eb787455c978c163d2209 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sun, 9 Nov 2025 20:30:44 +0100 Subject: [PATCH] When creating LS launch command from a list, quote args containing spaces --- src/solidlsp/ls_handler.py | 4 ++-- src/solidlsp/util/subprocess_util.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/solidlsp/ls_handler.py b/src/solidlsp/ls_handler.py index 7dd0189c..ce7b48ac 100644 --- a/src/solidlsp/ls_handler.py +++ b/src/solidlsp/ls_handler.py @@ -33,7 +33,7 @@ from solidlsp.lsp_protocol_handler.server import ( make_request, make_response, ) -from solidlsp.util.subprocess_util import subprocess_kwargs +from solidlsp.util.subprocess_util import quote_arg, subprocess_kwargs log = logging.getLogger(__name__) @@ -189,7 +189,7 @@ class SolidLanguageServerHandler: if not isinstance(cmd, str) and not is_windows: # Since we are using the shell, we need to convert the command list to a single string # on Linux/macOS - cmd = " ".join(cmd) + cmd = " ".join(map(quote_arg, cmd)) log.info("Starting language server process via command: %s", self.process_launch_info.cmd) kwargs = subprocess_kwargs() kwargs["start_new_session"] = self.start_independent_lsp_process diff --git a/src/solidlsp/util/subprocess_util.py b/src/solidlsp/util/subprocess_util.py index ac6a4e2b..718d7afa 100644 --- a/src/solidlsp/util/subprocess_util.py +++ b/src/solidlsp/util/subprocess_util.py @@ -11,3 +11,12 @@ def subprocess_kwargs(): if platform.system() == "Windows": kwargs["creationflags"] = subprocess.CREATE_NO_WINDOW # type: ignore return kwargs + + +def quote_arg(arg: str) -> str: + """ + Adds quotes around an argument if it contains spaces. + """ + if " " not in arg: + return arg + return f'"{arg}"'