diff --git a/python/tests/test_server.py b/python/tests/test_server.py index ba24166..632e30a 100644 --- a/python/tests/test_server.py +++ b/python/tests/test_server.py @@ -201,6 +201,24 @@ def test_multi_workspace_settings_include_defaults(self, mock_uris): assert "args" in ws_settings assert "importStrategy" in ws_settings + @patch("vscode_common_python_lsp.server.uris") + def test_workspace_without_filesystem_path_is_skipped(self, mock_uris): + mock_uris.to_fs_path.side_effect = lambda u: ( + "/local-workspace" if u == "file:///local-workspace" else None + ) + ts = _make_server() + ts.update_workspace_settings( + [ + {"workspace": "file:///local-workspace", "args": []}, + {"workspace": "pico:", "args": []}, + ] + ) + + assert len(ts.workspace_settings) == 1 + settings = next(iter(ts.workspace_settings.values())) + assert settings["workspace"] == "file:///local-workspace" + assert settings["workspaceFS"] + class TestGetSettingsByPath: def test_matches_closest_workspace(self): diff --git a/python/vscode_common_python_lsp/server.py b/python/vscode_common_python_lsp/server.py index c1eecb1..1b87762 100644 --- a/python/vscode_common_python_lsp/server.py +++ b/python/vscode_common_python_lsp/server.py @@ -149,8 +149,14 @@ def update_workspace_settings(self, settings: list[dict[str, Any]] | None) -> No return for setting in settings: + workspace_path = uris.to_fs_path(setting["workspace"]) + # Virtual workspace roots, such as "pico:", have no local + # filesystem path, so they cannot be registered here. + if workspace_path is None: + continue + key = normalize_path( - uris.to_fs_path(setting["workspace"]), + workspace_path, resolve_symlinks=self.config.resolve_symlinks, ) self.workspace_settings[key] = {