jupyter-lsp / jupyterlab-lsp

Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
https://jupyterlab-lsp.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.8k stars 148 forks source link

Detection of servers installed in kernel (but not server) environment #923

Closed jrouly closed 1 year ago

jrouly commented 1 year ago

I'm not 100% sure if this is the correct repository to file this issue so please forgive me in advance if I've bungled this.

What I am trying to do...

I'm trying to run JupyterHub with an R kernel, using Conda (micromamba) to manage environments, with an R language server.

The steps I've followed are essentially:

  1. Install jupyterlab, jupyterhub into the jupyter environment
  2. Install R, r-irkernel, r-languageserver into the R environment
  3. Activate the R environment and invoke IRkernel::installspec(user = FALSE, prefix = '$JUPYTER_HOME')

This works great and sets up an R kernel. However, despite having installed r-languageserver (which I can confirm by running library(languageserver) in a notebook), JupyterLab is unable to detect the R language server. It complains:

No language server for r detected

and recommends I troubleshoot finding Rscript on the PATH. It is on the PATH (in the R environment), and JupyterLab is clearly aware of this since it's able to run notebooks on the R kernel just fine. And yet, it cannot find the language server.

How I would like to learn how to do it...

I think the instructions in the documentation are pretty clear as-is, this was a very unexpected case. Having a section of documentation specifically for cross-environment kernels would potentially be helpful.

How the project might keep the docs accurate...

Having an additional section to the installation documentation to help with cross-account server scenarios could probably address this.

krassowski commented 1 year ago

It is on the PATH (in the R environment), and JupyterLab is clearly aware of this since it's able to run notebooks on the R kernel just fine

These are two different paths, so knowing that one works does not help with the other really.

  1. Install jupyterlab, jupyterhub into the jupyter environment
  2. Install R, r-irkernel, r-languageserver into the R environment

Currently detection of R language sever comes down to what Rscript -e cat(system.file(package='languageserver')) returns in the environment where jupyter-server gets spawned (in your case jupyter).

https://github.com/jupyter-lsp/jupyterlab-lsp/blob/ff8b6c44d5a81a7bc051604ea37a5bc4da6ec94a/python_packages/jupyter_lsp/jupyter_lsp/specs/r_languageserver.py#L21-L32

When you install kernelspec It would technically be possible to use path from kernel spec it creates a JSON file like this:

{
  "argv": ["/a/path/to/your/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
  "display_name": "R",
  "language": "R"
}

While we could potentially check for kernelspecs contents it is not currently implemented. We would need to extract /a/path/to/your/R bit and use it instead of Rscript. One would need to find a clean way to obtain it for currently running kernel (as you could have multiple different versions of IRKernel installed).

krassowski commented 1 year ago

Maybe of more use for now, you can create custom serverspecs pointing to any executable you would like, see https://jupyterlab-lsp.readthedocs.io/en/latest/Configuring.html#

krassowski commented 1 year ago

Let's consolidate the discussion in #533 which was opened earlier and has more replies.

While we could potentially check for kernelspecs contents it is not currently implemented. We would need to extract /a/path/to/your/R bit and use it instead of Rscript. One would need to find a clean way to obtain it for currently running kernel (as you could have multiple different versions of IRKernel installed).

A concrete idea for instead modifying the kernelspecs was proposed in https://github.com/jupyter-lsp/jupyterlab-lsp/issues/533#issuecomment-1763201392.