Skip to content

Commit da2df99

Browse files
authored
Merge pull request #184 from Kaggle/lsp-dependencies
Install dependencies for LSP-based autocompletion in R kernels.
2 parents 84df82d + fc83579 commit da2df99

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ RUN apt-get install -y libzmq3-dev default-jdk && \
5151
touch /root/.jupyter/jupyter_nbconvert_config.py && touch /root/.jupyter/migrated && \
5252
# papermill can replace nbconvert for executing notebooks
5353
pip install papermill && \
54+
pip install jupyterlab-lsp && \
5455
/tmp/clean-layer.sh
5556

5657
# Miniconda

package_installs.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ library(torch)
5757
install_torch()
5858

5959
# The R Keras package must be reinstalled after installing it in the python virtualenv.
60-
install_version("keras", version = "2.6.0.0", ask=FALSE)
60+
install_version("keras", version = "2.6.0.0", ask=FALSE)
61+
62+
install.packages(c('collections', 'languageserver'), dependencies=FALSE)

tests/test_jupyterlab-lsp.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
context("jupyterlab-lsp")
2+
3+
library(httr)
4+
5+
test_that("jupyterlab-lsp is installed", {
6+
expect_error({
7+
# Start a jupyterlab server and wait for it to initialize
8+
system(
9+
"/usr/local/bin/jupyter server --allow-root --no-browser --port 9999 --notebook-dir /tmp",
10+
wait=FALSE)
11+
Sys.sleep(5)
12+
13+
# Ping LSP endpoint, verify 200 response
14+
response <- GET("http://127.0.0.1:9999/lsp/status")
15+
expect_equal(status_code(response), 200)
16+
17+
# Kill the server
18+
pid <- system("ps -ef | grep jupyter | grep 9999 | awk '{print $2}'")
19+
tools::pskill(pid)
20+
}, NA) # expect no error to be thrown
21+
})

tests/test_languageserver.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
context("languageserver")
2+
3+
test_that("languageserver responds to commands", {
4+
expect_error({
5+
result <- system(
6+
"R -e 'languageserver::run()'",
7+
input="Content-Length: 38\n\n{ \"id\": \"123\", \"method\": \"shutdown\" }\n",
8+
intern=TRUE)
9+
10+
found_response <- FALSE
11+
for (line in result) {
12+
if (grepl("\"id\":\"123\"", line, fixed=TRUE) & grepl("\"result\":[]", line, fixed=TRUE)) {
13+
found_response <- TRUE
14+
}
15+
}
16+
17+
expect_true(found_response)
18+
}, NA) # expect no error to be thrown
19+
})

0 commit comments

Comments
 (0)