Skip to content

Commit cb1b908

Browse files
committed
Move the workaround to the root of the issue
1 parent f3e7288 commit cb1b908

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### (unreleased)
44

55
- Add ability to deactivate Kernel completions or LSP completion through the settings.
6+
- workaround url-parse issue causing problems when using JupyterLab 3.0.15 [#599]
7+
8+
[#599]: https://github.com/krassowski/jupyterlab-lsp/pull/599
69

710
### `jupyter-lsp 1.2.0` (2021-04-26)
811

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,18 @@ export namespace DocumentConnectionManager {
359359
throw `No language server installed for language ${language}`;
360360
}
361361

362+
// workaround url-parse bug (see https://github.com/krassowski/jupyterlab-lsp/issues/595)
363+
let documentUri = URLExt.join(baseUri, virtual_document.uri);
364+
if (
365+
!documentUri.startsWith('file:///') &&
366+
documentUri.startsWith('file://')
367+
) {
368+
documentUri = documentUri.replace('file://', 'file:///');
369+
}
370+
362371
return {
363372
base: baseUri,
364-
document: URLExt.join(baseUri, virtual_document.uri),
373+
document: documentUri,
365374
server: URLExt.join('ws://jupyter-lsp', language),
366375
socket: URLExt.join(
367376
wsBase,

python_packages/jupyter_lsp/jupyter_lsp/tests/test_virtual_documents_shadow.py

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

114113

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-
121114
@pytest.mark.asyncio
122115
async def test_shadow_failures(shadow_path):
123116

python_packages/jupyter_lsp/jupyter_lsp/virtual_documents_shadow.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ 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-
113104
def setup_shadow_filesystem(virtual_documents_uri):
114105

115106
if not virtual_documents_uri.startswith("file:/"):
@@ -126,8 +117,6 @@ def setup_shadow_filesystem(virtual_documents_uri):
126117
# create again
127118
shadow_filesystem.mkdir(parents=True, exist_ok=True)
128119

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

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

157144
path = file_uri_to_path(uri)

0 commit comments

Comments
 (0)