JupyterLabでコード補完(jupyterlab-lsp)


JupyterLabとは

JupyterLabの課題

  • デフォルトではTabを押さないとコード補完(autocomplete)されない
  • そのため、いくつかコード補完のextentionが提案されている
  • ここでは、jupyterlab-lspについて紹介する

jupyterlab-lspとは

jupyterlab-lspのインストール方法

概要

  • 基本的に、開発元のGithubに従ってインストールすれば動作する
  • ただし、以下をやらないと動作しないので注意(ハマった)
    • "Note on pyls (python-language-server) issues: pyls is known to require specific versions of some dependencies such as ujson <= 1.35, jedi == 0.15.2 and parso == 0.5.2. If you experience any issues with LSP functions in Python, please check if you have the right version using pip freeze command."
    • つまり、「ujson」「jedi」「parso」のバージョンを上記にしなければならない。
    • バージョンが異なると以下のエラーメッセージが出る。
      • ERROR - pyls_jsonrpc.endpoint ...

検証環境

インストール方法

conda環境の準備

conda create -n jupyter_test python=3
conda activate jupyter_test

jupyterlab,jupyter-lspのインストール

conda install -c conda-forge jupyterlab=2.1 ujson=1.35 jedi=0.15.2 parso=0.5.2
pip install jupyter-lsp
conda install -c conda-forge nodejs
jupyter labextension install @krassowski/jupyterlab-lsp
conda install -c conda-forge python-language-server r-languageserver

jupyterlabの起動

jupyter lab