Skip to content

Commit f3e7288

Browse files
committed
Workaround file URI matching issue for now
See https://github.com/krassowski/jupyterlab-lsp/issues/595
1 parent 309b3fa commit f3e7288

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

python_packages/jupyter_lsp/jupyter_lsp/tests/test_virtual_documents_shadow.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ..virtual_documents_shadow import (
77
EditableFile,
88
ShadowFilesystemError,
9+
_strip_file_protocol_prefix,
910
extract_or_none,
1011
setup_shadow_filesystem,
1112
)
@@ -111,6 +112,12 @@ async def test_shadow(shadow_path, message_func, content, expected_content):
111112
assert f.read() == expected_content
112113

113114

115+
def test_strip_file_prefix():
116+
assert _strip_file_protocol_prefix("file:///test") == "test"
117+
assert _strip_file_protocol_prefix("file://test") == "test"
118+
assert _strip_file_protocol_prefix("http://test") == "http://test"
119+
120+
114121
@pytest.mark.asyncio
115122
async def test_shadow_failures(shadow_path):
116123

python_packages/jupyter_lsp/jupyter_lsp/virtual_documents_shadow.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ class ShadowFilesystemError(ValueError):
101101
"""Error in the shadow file system."""
102102

103103

104+
# TODO: remove once https://github.com/unshiftio/url-parse/pull/204 gets merged and released
105+
def _strip_file_protocol_prefix(uri):
106+
if uri.startswith("file:///"):
107+
return uri[8:]
108+
if uri.startswith("file://"):
109+
return uri[7:]
110+
return uri
111+
112+
104113
def setup_shadow_filesystem(virtual_documents_uri):
105114

106115
if not virtual_documents_uri.startswith("file:/"):
@@ -117,6 +126,8 @@ def setup_shadow_filesystem(virtual_documents_uri):
117126
# create again
118127
shadow_filesystem.mkdir(parents=True, exist_ok=True)
119128

129+
stripped_virtual_documents_uri = _strip_file_protocol_prefix(virtual_documents_uri)
130+
120131
@lsp_message_listener("client")
121132
async def shadow_virtual_documents(scope, message, language_server, manager):
122133
"""Intercept a message with document contents creating a shadow file for it.
@@ -138,7 +149,9 @@ async def shadow_virtual_documents(scope, message, language_server, manager):
138149
if not uri:
139150
raise ShadowFilesystemError("Could not get URI from: {}".format(message))
140151

141-
if not uri.startswith(virtual_documents_uri):
152+
if not _strip_file_protocol_prefix(uri).startswith(
153+
stripped_virtual_documents_uri
154+
):
142155
return
143156

144157
path = file_uri_to_path(uri)

0 commit comments

Comments
 (0)