A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: shelex paths for lsp (#6403)
Dylan Madisetti78fcd97f03dd
diff --git a/marimo/_cli/envinfo.py b/marimo/_cli/envinfo.pyindex 93a582e23e..15f06d98a6 100644--- a/marimo/_cli/envinfo.py+++ b/marimo/_cli/envinfo.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport platformimport sys+from pathlib import Pathfrom typing import Any, Union, castfrom marimo import _loggers@@ -50,9 +51,11 @@ def get_system_info() -> dict[str, Union[str, bool, dict[str, Any]]]:if platform.system() == "Windows" and is_win11():os_version = "11"+ location = Path(__file__).parent.parent.as_posix()info: dict[str, Union[str, bool, dict[str, Any]]] = {"marimo": __version__,"editable": is_editable("marimo"),+ "location": location,"OS": platform.system(),"OS Version": os_version,# e.g., x86 or armdiff --git a/marimo/_server/lsp.py b/marimo/_server/lsp.pyindex 3caa6f202b..3b9487c5aa 100644--- a/marimo/_server/lsp.py+++ b/marimo/_server/lsp.py@@ -189,6 +189,8 @@ class CopilotLspServer(BaseLspServer):return self._lsp_dir() / "index.cjs"def get_command(self) -> list[str]:+ import shlex+lsp_bin = self._lsp_bin()# Check if the LSP binary existsif not lsp_bin.exists():@@ -199,13 +201,16 @@ class CopilotLspServer(BaseLspServer):copilot_bin = self._lsp_dir() / "copilot" / "language-server.js"log_file = _loggers.get_log_directory() / "github-copilot-lsp.log"+ # Properly quote the copilot binary path to handle spaces and special characters+ copilot_command = f"node {shlex.quote(str(copilot_bin))} --stdio"+return ["node",str(lsp_bin),"--port",str(self.port),"--lsp",- f"node {copilot_bin} --stdio",+ copilot_command,"--log-file",str(log_file),]@@ -321,18 +326,23 @@ class TyServer(BaseLspServer):return Truedef get_command(self) -> list[str]:+ import shlex+from ty.__main__ import find_ty_bin # type: ignorelsp_bin = marimo_package_path() / "_lsp" / "index.cjs"log_file = _loggers.get_log_directory() / "ty-lsp.log"+ # Properly quote the ty binary path to handle spaces and special characters+ ty_command = f"{shlex.quote(find_ty_bin())} server"+return ["node",str(lsp_bin),"--port",str(self.port),"--lsp",- f"{find_ty_bin()} server",+ ty_command,"--log-file",str(log_file),]diff --git a/tests/_server/test_lsp.py b/tests/_server/test_lsp.pyindex 4125502526..0697b93dca 100644--- a/tests/_server/test_lsp.py+++ b/tests/_server/test_lsp.py@@ -27,6 +27,7 @@ from marimo._server.lsp import (if TYPE_CHECKING:from collections.abc import Iterator+ from pathlib import Path@pytest.fixture@@ -131,6 +132,45 @@ def test_copilot_server():assert "GitHub Copilot" in alert.title+def test_copilot_server_command_quotes_path(tmp_path: Path) -> None:+ """Test that paths with spaces are properly quoted in the copilot command."""+ from unittest import mock++ server = CopilotLspServer(port=8000)++ # Create LSP directory with spaces+ lsp_dir_with_spaces = tmp_path / "my folder with spaces"+ lsp_dir_with_spaces.mkdir(parents=True)++ # Create the required files+ lsp_bin = lsp_dir_with_spaces / "index.cjs"+ lsp_bin.touch()++ copilot_dir = lsp_dir_with_spaces / "copilot"+ copilot_dir.mkdir()+ copilot_bin = copilot_dir / "language-server.js"+ copilot_bin.touch()++ # Mock the _lsp_dir method to return our test directory+ with mock.patch.object(+ server, "_lsp_dir", return_value=lsp_dir_with_spaces+ ):+ command = server.get_command()++ # Find the --lsp argument+ lsp_arg_index = command.index("--lsp")+ lsp_command = command[lsp_arg_index + 1]++ # The command should contain the quoted path+ assert "node" in lsp_command+ assert (+ str(copilot_bin) in lsp_command+ or f"'{copilot_bin}'" in lsp_command+ or f'"{copilot_bin}"' in lsp_command+ )+ assert "--stdio" in lsp_command++def test_copilot_server_node_version_validation():server = CopilotLspServer(port=8000)