Skip to content

Commit

Permalink
fix: prevent AttributeError root_path when no workspace
Browse files Browse the repository at this point in the history
fixes #395
  • Loading branch information
perrinjerome authored and tombh committed Oct 6, 2023
1 parent 571fd1c commit 6c5e295
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pygls/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6c5e295

Please sign in to comment.