Skip to content

Commit 4d79daa

Browse files
authored
Add dependencies necessary for LSP-based autocomplete. (#1144)
* Add jupyterlab-lsp dependency. This is required for making LSP-based autocompletion work in the Notebook Editor. The tsfresh test had to be changed to single-threaded, as the multi-threaded cleanup process was hanging trying to kill the jupyter server that was initialized but not running. http://b/211487924 * Add python-lsp-server. This is required for LSP-based autocomplete. b/211487924
1 parent 98ca09f commit 4d79daa

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

Dockerfile.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,15 @@ RUN pip install bleach && \
395395
pip install jupyter-client && \
396396
pip install jupyter-console && \
397397
pip install jupyter-core && \
398+
pip install jupyterlab-lsp && \
398399
pip install MarkupSafe && \
399400
pip install mistune && \
400401
# b/227194111 install latest version of nbconvert until the base image includes nbconvert >= 6.4.5
401402
pip install --upgrade nbconvert Jinja2 && \
402403
pip install nbformat && \
403404
pip install notebook && \
404405
pip install papermill && \
406+
pip install python-lsp-server[all] && \
405407
pip install olefile && \
406408
# b/198300835 kornia 0.5.10 is not compatible with our version of numpy.
407409
pip install kornia==0.5.8 && \

tests/test_jupyterlab_lsp.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import unittest
3+
4+
from jupyter_server.serverapp import ServerApp
5+
6+
# Adapted from:
7+
# https://github.com/jupyter-lsp/jupyterlab-lsp/blob/ce76fab170feea506faf9ef47e4bd6a468c24313/python_packages/jupyter_lsp/jupyter_lsp/tests/test_extension.py
8+
class TestJupyterLabLsp(unittest.TestCase):
9+
def test_serverextension_path(self):
10+
import jupyter_lsp
11+
paths = jupyter_lsp._jupyter_server_extension_paths()
12+
for path in paths:
13+
self.assertTrue(__import__(path["module"]))
14+
15+
16+
def test_serverextension(self):
17+
app = ServerApp()
18+
app.initialize(
19+
["--ServerApp.jpserver_extensions={'jupyter_lsp.serverextension': True}"],
20+
new_httpserver=False,
21+
)
22+
self.assertTrue(app.language_server_manager)
23+
24+
found_lsp = False
25+
for r in app.web_app.default_router.rules:
26+
for rr in r.target.rules:
27+
if "/lsp/" in str(rr.matcher.regex):
28+
found_lsp = True
29+
30+
self.assertTrue(found_lsp, "didn't install the /lsp/ route")
31+

tests/test_python_lsp_server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import subprocess
2+
import unittest
3+
4+
5+
class TestPythonLspServer(unittest.TestCase):
6+
def test_initialize(self):
7+
server = subprocess.Popen(
8+
'python -m pylsp --check-parent-process',
9+
shell=True,
10+
stdin=subprocess.PIPE,
11+
stdout=subprocess.PIPE)
12+
13+
response = server.communicate(input=
14+
b'Content-Length: 67\r\n'
15+
b'Content-Type: application/vscode-jsonrpc; charset=utf8\r\n'
16+
b'\r\n'
17+
b'{"id": "a", "jsonrpc": "2.0", "method": "initialize", "params": {}}')[0]
18+
assert 'capabilities' in response.decode('utf-8')

tests/test_tsfresh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_extract_feature(self):
1212
'time': np.array([0,1,2,0,1,2]),
1313
'x': np.array([3,4,5,7,8,10])
1414
})
15-
extracted_features = extract_features(ts, column_id='id', column_sort='time')
15+
extracted_features = extract_features(ts, column_id='id', column_sort='time', n_jobs=1)
1616
self.assertEqual(2, len(extracted_features))
1717

1818

0 commit comments

Comments
 (0)