JupyterLab Language Server Protocol (LSP)
jupyterlab-lsp integrates Language Server Protocol (LSP) features directly into JupyterLab, providing coding assistance like autocompletion, hover documentation, linting, and refactoring. As of version 5.3.0, it supports JupyterLab 4.x and is actively maintained with regular updates focusing on compatibility and new LSP features.
Common errors
-
Language Server not found: python
cause The Python language server (e.g., `python-lsp-server`) is not installed or not discoverable by `jupyterlab-lsp`.fixInstall the `python-lsp-server` package in the same environment as JupyterLab: `pip install 'python-lsp-server[all]'`. -
Uncaught (in promise) Error: 404 Not Found
cause This error often indicates a problem with the JupyterLab server extension not being loaded correctly, an outdated frontend build, or an incorrect path for server components.fixFirst, try rebuilding JupyterLab assets: `jupyter lab build`. If the issue persists, verify that `jupyterlab-lsp` is enabled (`jupyter labextension list` and `jupyter server extension list`) and restart your JupyterLab server. Clear your browser cache. -
ModuleNotFoundError: No module named 'jupyterlab_lsp'
cause The `jupyterlab-lsp` Python package is not installed in the active Python environment where JupyterLab is running.fixInstall the package: `pip install jupyterlab-lsp`.
Warnings
- breaking Major versions of `jupyterlab-lsp` are tightly coupled to major versions of `JupyterLab`. For example, `jupyterlab-lsp` 4.x is for `JupyterLab` 4.x, and `jupyterlab-lsp` 3.x is for `JupyterLab` 3.x. Installing an incompatible version can lead to errors or the extension not loading.
- gotcha After installing `jupyterlab-lsp`, users often expect immediate coding assistance for all languages. However, `jupyterlab-lsp` itself only provides the framework; each language (e.g., Python, R, TypeScript) requires its own specific language server to be installed separately.
- gotcha Sometimes, after installing or upgrading `jupyterlab-lsp` or other JupyterLab extensions, the frontend assets might become stale or cached incorrectly, leading to features not appearing or errors in the browser console.
Install
-
pip install jupyterlab-lsp -
pip install 'python-lsp-server[all]'
Quickstart
# hello_lsp.py
import os
def greet(name: str) -> str:
"""
Returns a greeting message.
Hover over 'greet' for documentation.
Type 'greet(' to see signature help.
"""
message = f"Hello, {name}!"
# Type 'message.' to trigger autocompletion provided by LSP
return message.upper()
if __name__ == '__main__':
user_name = os.environ.get('USER_NAME', 'World')
print(greet(user_name))