JSPM

  • Created
  • Published
  • Downloads 328
  • Score
    100M100P100Q67051F
  • License BSD-3-Clause

Language Server Protocol integration for JupyterLab

Package Exports

  • @krassowski/jupyterlab-lsp

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@krassowski/jupyterlab-lsp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Language Server Protocol integration for JupyterLab

This extension is in its early days, but you are welcome to check it out, leave feedback and/or a PR

Features overview:

Implemented

Examples below are for Python, but it works as well for R:

  • hover over any piece of code; if an underline appears, you can press Ctrl to get a tooltip with function/class signature, module documentation or any other piece of information that the language server provides

    hover

  • linting: critical errors have red underline, warnings are orange, etc. Hover over the underlined code to see the linter's message

    inspections

  • go to definition: use the context menu entries to jump to definitions

    jump

  • highlight usages: just place your cursor on a variable, function etc and all the usages will be highlighted (works only in the file editor or within a single cell)

  • auto invocation of completer on certain characters, for example '.' (dot) in Python

    invoke

  • automatic signature suggestions

    signature

  • advanced autocompletion (even when the kernel is off);

    autocompletion

    when a kernel is available the suggestions from the kernel (such as keys of a dict and columns of a DataFrame autocompletion) are merged with the suggestions from LSP (currently only in notebook).

Coming soon:

  • multiple LSP connections per notebook, e.g. SQL or R (using rpy2) embedded in Python notebook.
  • autocompleter with documentation and sorting based on LSP suggestions
  • unit tests
  • system of settings, including options:
    • to enable aggressive autocompletion (like in hinterland)
    • to change the verbosity of signature hints (whether to show documentation, number of lines to be shown)

If a feature you need is not on this list (or the lists below) please feel free to suggest it by opening an issue.

Planned:

  • "rename" action (PR welcome)

Low priority:

  • Gutter with linter results
  • Use the kernel session for autocompletion in FileEditor if available (PR welcome)

Hints

  • just like in old notebooks, you can still use the built-in Shift + Tab to get a signature in JupyterLab. This extension behaves well with this feature.

Under the hood

This would not be possible if not the fantastic work of https://github.com/wylieconlon/lsp-editor-adapter.

Prerequisites

  • JupyterLab

Installation

  1. install the extension:
jupyter labextension install @krassowski/jupyterlab-lsp
  1. install servers for languages of your choice. Below are examples for Python (with pyls) and R (with languageserver):
pip install python-language-server[all]
R -e 'install.packages("languageserver")'

For the full list of language servers see the Microsoft's list; it may also be good to visit the repository of each server as many provide some additional configuration options.

  1. create servers.yml file:
langservers:
  python:
    - pyls
  R:
    - R
    - --slave
    - -e
    - languageserver::run()
  1. Each time before starting JupyterLab, run:
node path_to_jupyterlab_staging/node_modules/jsonrpc-ws-proxy/dist/server.js --port 3000 --languageServers servers.yml

where path_to_jupyterlab_staging is the location of JupyterLab staging directory. Here are example locations on Ubuntu:

  • if you use pyenv it should be in ~/.pyenv/versions/YOUR_VERSION_OR_VENV/share/jupyter/lab/staging/
  • if you use local installation, it might be in ~/.local/lib/python3.6/site-packages/jupyterlab/staging/ (where instead of python3.6 you should use your Python3 version having JupyterLab installed)
  1. (Optional) to enable opening files outside of the root directory (the place where you start JupyterLab), create .lsp_symlink and symlink your home, usr, or any other location which include the files that you wish to make possible to open in there:
mkdir .lsp_symlink
cd .lsp_symlink
ln -s /home home
ln -s /usr usr

If your user does not have sufficient permissions to traverse the entire path, you will not be able to open the file.

Updatng the extension

To update already installed extension:

jupyter labextension update @krassowski/jupyterlab-lsp

Development

For a development install (requires npm version 4 or later), do the following in the repository directory:

npm install
npm run build
jupyter labextension link .

To rebuild the package and the JupyterLab app:

npm run build
jupyter lab build

To run tests suite:

npm test