Skip to main content

Language Server Protocol integration for JupyterLab

Project description

Language Server Protocol integration for Jupyter(Lab)

tests Documentation Status Binder

This project is still maturing, but you are welcome to check it out, leave feedback and/or a PR

Quick Links: Installation | Configuring | Updating | Changelog | Roadmap | Contributing | Extending

Features

Examples show Python code, but most features also work in R, bash, typescript, and many other languages.

Hover

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

Diagnostics

Critical errors have red underline, warnings are orange, etc. Hover over the underlined code to see a more detailed message

inspections

Jump to Definition

Use the context menu entry, or Alt + :computer_mouse: to jump to definitions (you can change it to Ctrl/ in settings); use Alt + o to jump back

jump

Highlight References

Place your cursor on a variable, function, etc and all the usages will be highlighted

Automatic Completion

Certain characters, for example '.' (dot) in Python, will automatically trigger completion

invoke

Automatic Signature Suggestions

Function signatures will automatically be displayed

signature

Kernel-less Autocompletion

Advanced static-analysis autocompletion without a running kernel

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 the Language Server (currently only in notebook).

Rename

Rename variables, functions and more, in both: notebooks and the file editor. Use the context menu option or the F2 shortcut to invoke.

rename

Diagnostics panel

Sort and jump between the diagnostics using the diagnostics panel. Open it searching for "Show diagnostics panel" in JupyterLab commands palette or from the context menu. Use context menu on rows in the panel to filter out diagnostics or copy their message.

panel

Prerequisites

You will need to have both of the following installed:

  • JupyterLab >=3.0.0,<4.0.0a0
  • Python 3.6+

In addition, if you wish to use javascript, html, markdown or any other NodeJS-based language server you will need to have appropriate NodeJS version installed.

Note: Installation for JupyterLab 2.x requires a different procedure, please consult the documentation for the extension version 2.x.

Installation

For more extensive installation instructions, see the documentation.

For the current stable version, the following steps are recommended. Use of a python virtualenv or a conda env is also recommended.

  1. install python 3

    conda install -c conda-forge python=3
    
  2. install JupyterLab and the extensions

    conda install -c conda-forge 'jupyterlab>=3.0.0,<4.0.0a0' jupyterlab-lsp
    # or
    pip install 'jupyterlab>=3.0.0,<4.0.0a0' jupyterlab-lsp
    

    Note: jupyterlab-lsp provides both the server extension and the lab extension.

    Note: With conda, you could take advantage of the bundles: jupyter-lsp-python or jupyter-lsp-r to install both the server extension and the language server.

  3. install LSP servers for languages of your choice; for example, for Python (pyls) and R (languageserver) servers:

    pip install python-language-server[all]
    R -e 'install.packages("languageserver")'
    

    or from conda-forge

    conda install -c conda-forge python-language-server r-languageserver
    

    Please see our full list of supported language servers which includes installation hints for the common package managers (npm/pip/conda). In general, any LSP server from the Microsoft list should work after some additional configuration.

    Note: it is worth visiting the repository of each server you install as many provide additional configuration options.

  4. (Optional, Linux/OSX-only) to enable opening files outside of the root directory (the place where you start JupyterLab), create .lsp_symlink and symlink your /home, or any other location which includes the files that you wish to make possible to open in there:

    mkdir .lsp_symlink
    cd .lsp_symlink
    ln -s /home home
    

    If your user does not have sufficient permissions to traverse the entire path, you will not be able to open the file. A more detailed guide on symlinking (written for a related jupyterlab-go-to-definition extension) is available here.

Configuring the servers

Server configurations can be edited using the Advanced Settings editor in JupyterLab (Settings > Advanced Settings Editor). For settings specific to each server, please see the table of language servers. Example settings might include:

{
  "language_servers": {
    "pyls": {
      "serverSettings": {
        "pyls.plugins.pydocstyle.enabled": true,
        "pyls.plugins.pyflakes.enabled": false,
        "pyls.plugins.flake8.enabled": true
      }
    },
    "r-languageserver": {
      "serverSettings": {
        "r.lsp.debug": false,
        "r.lsp.diagnostics": false
      }
    }
  }
}

The serverSettings key specifies the configurations sent to the language servers. These can be written using stringified dot accessors like above (in the VSCode style), or as nested JSON objects, e.g.:

{
  "language_servers": {
    "pyls": {
      "serverSettings": {
        "pyls": {
          "plugins": {
            "pydocstyle": {
              "enabled": true
            },
            "pyflakes": {
              "enabled": false
            },
            "flake8": {
              "enabled": true
            }
          }
        }
      }
    }
  }
}

Other configuration methods

Some language servers, such as pyls, provide other configuration methods in addition to language-server configuration messages (accessed using the Advanced Settings Editor). For example, pyls allows users to configure the server using a local configuration file. You can change the inspection/diagnostics for server plugins like pycodestyle there.

The exact configuration details will vary between operating systems (please see the configuration section of pycodestyle documentation), but as an example, on Linux you would simply need to create a file called ~/.config/pycodestyle, which may look like that:

[pycodestyle]
ignore = E402, E703
max-line-length = 120

In the example above:

  • ignoring E402 allows imports which are not on the very top of the file,
  • ignoring E703 allows terminating semicolon (useful for matplotlib plots),
  • the maximal allowed line length is increased to 120.

After changing the configuration you may need to restart the JupyterLab, and please be advised that the errors in configuration may prevent the servers from functioning properly.

Again, please do check the pycodestyle documentation for specific error codes, and check the configuration of other feature providers and language servers as needed.

Acknowledgements

This would not be possible without the fantastic initial work at wylieconlon/lsp-editor-adapter.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab-lsp-3.2.0.tar.gz (306.9 kB view details)

Uploaded Source

Built Distribution

jupyterlab_lsp-3.2.0-py3-none-any.whl (634.9 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab-lsp-3.2.0.tar.gz.

File metadata

  • Download URL: jupyterlab-lsp-3.2.0.tar.gz
  • Upload date:
  • Size: 306.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for jupyterlab-lsp-3.2.0.tar.gz
Algorithm Hash digest
SHA256 c6902623a0fc653d78e9c6c4ee10369bb85a056e4d8787842154976c446f5102
MD5 cf2198548281814943f7c738e1b3b475
BLAKE2b-256 bc1cd39b23b4a95b85b8754ab56a1557a0b7ef405078bf19c3b340bc342dab9a

See more details on using hashes here.

File details

Details for the file jupyterlab_lsp-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: jupyterlab_lsp-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 634.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

File hashes

Hashes for jupyterlab_lsp-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23190ca7e6bdaeefe5acdc934c28be1b1fc23e07de83e5faa46cb6753d3a1f68
MD5 6f01499bdbd9fb8b4a0875aa140868a7
BLAKE2b-256 07bc0b7c0fbe25a1a1a15d6e1d1dcf046fcd99766e5a7fe317e9e9eed50b3008

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page