Package: jupyterlab-lsp
Language Server Protocol integration for Jupyter(Lab)Installation|Configuring|Changelog|Roadmap|Contributing|ExtendingFeaturesExamples show Python code, but most features also work in R, bash, typescript, andmany other languages.HoverHover over any piece of code; if an underline appears, you can pressCtrlto get a tooltip with function/class signature, module documentation or any other
piece of information that the language server providesDiagnosticsCritical errors have red underline, warnings are orange, etc. Hover
over the underlined code to see a more detailed messageJump to Definition and ReferencesUse the context menu entry, orAlt+ :computer_mouse: to jump to definitions/references (you can change it toCtrl/⌘in settings); useAlt+oto jump back.Highlight ReferencesPlace your cursor on a variable, function, etc and all the usages will be highlightedAutomatic Completion and Continuous HintingCertain characters, for example '.' (dot) in Python, will automatically trigger
completion.You can choose to receive the completion suggestions as you type by enablingcontinuousHintingsetting.Automatic Signature SuggestionsFunction signatures will automatically be displayedKernel-less AutocompletionAdvanced static-analysis autocompletion without a running kernelThe runtime kernel suggestions are still thereWhen a kernel is available the suggestions from the kernel (such as keys of a
dict and columns of a DataFrame) are merged with the suggestions
from the Language Server (in notebook).If the kernel is too slow to respond promptly only the Language Server suggestions will be shown (default threshold: 0.6s).
You can configure the completer to not attempt to fetch the kernel completions if the kernel is busy (skipping the 0.6s timeout).You can deactivate the kernel suggestions by adding"Kernel"to thedisableCompletionsFromin thecompletionsection
ofAdvanced Settings. Alternatively if youonlywant kernel completions you can add"LSP"to the same
setting; Or add both if you like to code in hardcore mode and get no completions, or if another provider has been added.RenameRename variables, functions and more, in both: notebooks and the file editor.
Use the context menu option or theF2shortcut to invoke.Diagnostics panelSort 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.PrerequisitesYou will need to have both of the following installed:JupyterLab >=4.1.0,<5.0.0a0Python 3.8+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 extensionversion 2.x.InstallationFor more extensive installation instructions, see thedocumentation.For the current stable version, the following steps are recommended.
Use of a pythonvirtualenvor a conda env is also recommended.install python 3condainstall-cconda-forgepython=3install JupyterLab and the extensionscondainstall-cconda-forge'jupyterlab>=4.1.0,<5.0.0a0'jupyterlab-lsp# orpipinstall'jupyterlab>=4.1.0,<5.0.0a0'jupyterlab-lspNote:jupyterlab-lspprovides both the server extension and the lab extension.Note: With conda, you could take advantage of the bundles:jupyter-lsp-pythonorjupyter-lsp-rto install both the server extension and the language server.install LSP servers for languages of your choice; for example, for Python
(pylsp) and
R (languageserver) servers:pipinstall'python-lsp-server[all]'R-e'install.packages("languageserver")'or fromconda-forgecondainstall-cconda-forgepython-lsp-serverr-languageserverPlease see our full list ofsupported language serverswhich includes installation hints for the common package managers (npm/pip/conda).
In general, any LSP server from theMicrosoft listshould work aftersome additional configuration.Note: it is worth visiting the repository of each server you install as
many provide additional configuration options.Restart JupyterLabIf JupyterLab is running when you installed the extension, a restart is required
for the server extension and any language servers to be recognized by JupyterLab.(Optional, IPython users only) to improve the performance of autocompletion,
disable Jedi in IPython (the LSP servers for Python use Jedi too).
You can do that temporarily with:%config Completer.use_jedi = Falseor permanently by settingc.Completer.use_jedi = Falsein youripython_config.pyfile.(Optional, Linux/OSX-only) As a security measure by default Jupyter server only allows
access to files under the Jupyter root directory (the place where you launch the Jupyter server).
Thus, in order to allowjupyterlab-lspto navigate to external files such as packages
installed system-wide or to libraries inside a virtual environment (conda,pip, ...) this access control mechanism needs to be circumvented: inside your Jupyter
root directory create a symlink named.lsp_symlinkpointing to your system root/.ln -s / .lsp_symlinkAs this symlink is a hidden file the Jupyter server must be instructed to
serve hidden files. Either use the appropriate command line flag:jupyter lab --ContentsManager.allow_hidden=Trueor, alternatively, set the corresponding setting inside yourjupyter_server_config.py.Help in implementing a customContentsManagerwhich will enable navigating to external files without the symlink is welcome.Configuring the serversServer configurations can be edited using the Advanced Settings editor in JupyterLab (Settings > Advanced Settings Editor). For settings specific to each server, please see thetable of language servers. Example settings might include:{"language_servers":{"pylsp":{"serverSettings":{"pylsp.plugins.pydocstyle.enabled":true,"pylsp.plugins.pyflakes.enabled":false,"pylsp.plugins.flake8.enabled":true}},"r-languageserver":{"serverSettings":{"r.lsp.debug":false,"r.lsp.diagnostics":false}}}}TheserverSettingskey 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":{"pylsp":{"serverSettings":{"pylsp":{"plugins":{"pydocstyle":{"enabled":true},"pyflakes":{"enabled":false},"flake8":{"enabled":true}}}}}}}Other configuration methodsSome language servers, such aspylsp, provide other configuration methodsin additionto language-server configuration messages (accessed using the Advanced Settings Editor). For example,pylspallows users to configure the server using a local configuration file. You can change the inspection/diagnostics for server plugins likepycodestylethere.The exact configuration details will vary between operating systems (please see theconfiguration 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, E703max-line-length=120In 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.AcknowledgementsThis would not be possible without the fantastic initial work atwylieconlon/lsp-editor-adapter.