From 6c5e295370cc949669923052601b35dbb47e1293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Fri, 6 Oct 2023 03:33:33 +0000 Subject: [PATCH] fix: prevent AttributeError root_path when no workspace fixes #395 --- pygls/workspace/workspace.py | 2 ++ tests/test_workspace.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/pygls/workspace/workspace.py b/pygls/workspace/workspace.py index 746c1bab..405a798c 100644 --- a/pygls/workspace/workspace.py +++ b/pygls/workspace/workspace.py @@ -52,6 +52,8 @@ def __init__( if root_path is None: raise Exception("Couldn't get `root_path` from `root_uri`") self._root_path = root_path + else: + self._root_path = None self._sync_kind = sync_kind self._text_documents: Dict[str, TextDocument] = {} self._notebook_documents: Dict[str, types.NotebookDocument] = {} diff --git a/tests/test_workspace.py b/tests/test_workspace.py index 53c5a52d..52d50f3e 100644 --- a/tests/test_workspace.py +++ b/tests/test_workspace.py @@ -433,3 +433,10 @@ def test_workspace_folders(): assert workspace.folders["/ws/f1"] is wf1 assert workspace.folders["/ws/f2"] is wf2 + + +def test_null_workspace(): + workspace = Workspace(None) + + assert workspace.root_uri is None + assert workspace.root_path is None