Description
When opening a Jupyter notebook (or any file) stored on a Windows UNC network share (e.g. \\server\share\...) in JupyterLab with jupyter-lsp active, pylsp crashes on every textDocument/didOpen and textDocument/didChange notification. This makes language features (completions, diagnostics, etc.) unavailable for any file on a network drive.
Root Cause
In pylsp/_utils.py, find_parents() calls:
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
On Windows, os.path.relpath(path, start) raises ValueError when path and start are on different mounts e.g. when the workspace root is a UNC path (\ldnwifilep002\Department...) and the resolved document path lands on a local drive (C:), or vice versa.
The existing guard at line 90 using os.path.commonprefix() is insufficient it does a naïve character-by-character comparison and does not reliably detect all cross-mount cases.
Error Log
ERROR - pylsp_jsonrpc.endpoint - Failed to handle notification textDocument/didOpen
Traceback (most recent call last):
File ".../pylsp/workspace.py", line 341, in source_roots
_utils.find_parents(
File ".../pylsp/_utils.py", line 97, in find_parents
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
File "<frozen ntpath>", line 791, in relpath
ValueError: path is on mount 'C:', start on mount '\\unc\share'
All subsequent textDocument/didChange notifications then raise KeyError because put_document (didOpen) never completed, leaving the document unregistered in the workspace.
Environment
- OS: Windows 11 Enterprise
- python-lsp-server: 1.12.2
- Python: 3.12
- Triggered by: opening a notebook on \unc\share... via
JupyterLab + jupyter-lsp
Proposed Fix
Wrap the relpath call in a try/except ValueError and return early, matching the intent of the existing commonprefix guard:
try:
dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)
except ValueError:
# On Windows, relpath raises ValueError when path and root are on different
# mounts (e.g. UNC share vs local drive letter). Nothing to search.
log.warning("Path %r not in %r (different mounts)", path, root)
return []
This is the minimal safe fix that mirrors the behaviour of the existing commonprefix guard and avoids any functional regression on non-Windows platforms.
Description
When opening a Jupyter notebook (or any file) stored on a Windows UNC network share (e.g.
\\server\share\...) in JupyterLab with jupyter-lsp active,pylspcrashes on everytextDocument/didOpenandtextDocument/didChangenotification. This makes language features (completions, diagnostics, etc.) unavailable for any file on a network drive.Root Cause
In
pylsp/_utils.py,find_parents()calls:On Windows, os.path.relpath(path, start) raises ValueError when path and start are on different mounts e.g. when the workspace root is a UNC path (\ldnwifilep002\Department...) and the resolved document path lands on a local drive (C:), or vice versa.
The existing guard at line 90 using os.path.commonprefix() is insufficient it does a naïve character-by-character comparison and does not reliably detect all cross-mount cases.
Error Log
All subsequent textDocument/didChange notifications then raise KeyError because put_document (didOpen) never completed, leaving the document unregistered in the workspace.
Environment
JupyterLab + jupyter-lsp
Proposed Fix
Wrap the relpath call in a try/except ValueError and return early, matching the intent of the existing commonprefix guard:
This is the minimal safe fix that mirrors the behaviour of the existing commonprefix guard and avoids any functional regression on non-Windows platforms.