Repository: openlawlibrary/pygls

Issue:
Bug: Workspace._root_path attribute not set if if self._root_uri is None
I believe this is incorrect behavior. Relevant code:

https://github.com/openlawlibrary/pygls/blob/571fd1c569603475475883c118b56ba4680ca023/pygls/workspace/workspace.py#L49C1-L49C1

`if self._root_uri is None`, then `self._root_path` is never set. This, in turn, raises an `AttributeError` when `self.root_path` is called: https://github.com/openlawlibrary/pygls/blob/571fd1c569603475475883c118b56ba4680ca023/pygls/workspace/workspace.py#L222

Related issue: https://github.com/pappasam/jedi-language-server/issues/287

Discussion:

Patch:
diff --git a/pygls/workspace/workspace.py b/pygls/workspace/workspace.py
index 746c1ba..405a798 100644
--- a/pygls/workspace/workspace.py
+++ b/pygls/workspace/workspace.py
@@ -52,6 +52,8 @@ class Workspace(object):
             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] = {}


Test patch:
diff --git a/tests/test_workspace.py b/tests/test_workspace.py
index 53c5a52..52d50f3 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