LoginSignup
1
0

neovim で venv 環境の pyright LSP を使う

Last updated at Posted at 2024-05-23

概要

venv 環境 (pipenv や Rye で作成した環境など) にインストールした pyright の language server を使って支援を受ける方法を探していたので書き残します。

環境

  • neovim v0.10.0 (Release)
  • nvim-cmp, lspconfig

設定

bash -c.venv/bin/activate を呼び出して仮想環境に入り、.venv/bin/pyright-langserver のバイナリを呼び出します。

require("lspconfig").pyright.setup {
    on_attach = on_attach,
    capabilities = capabilities,
    filetypes = { "python" },
    root_dir = util.root_pattern(".venv"),
    cmd = { "bash", "-c", "source .venv/bin/activate && .venv/bin/pyright-langserver --stdio" },
}

うまくいかなかった方法

  • .venv/bin/pyright-langserver を直接呼び出す
    • 仮想環境が有効になっていないのでグローバルのモジュールを参照してしまう
  • .venv/bin/pytyon -m pyright のような方法で呼び出す
    • この方法で LSP を呼び出す方法が不明
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0