この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
coc.nvimを通したneovim上での非同期編集環境を整えていく中で、肝心のPythonに用いているExtensionがcoc-pythonでした。これは既にArchive入しており、メンテナンスがなされません。
coc.nvim用のPython Extensionでcoc-pythonの代打としてはcoc-pyrightとcoc-jediがあります。これまでjediを使っていたこともあり、coc-jediベースへと切り替えてみました。
coc-jediの追加
追加するExtensionはcoc-jediのみで完了です。
:CocInstall coc-jedi
が、これだけでは動作しません。 サーバ実装である jedi-language-server
も追加が必要です。今回の追加先はdense-analysis/ale用に作成しているvirtualenv環境にしています。
~/.anyenv/envs/pyenv/versions/neovim3/bin/pip3 install jedi-language-server
そして coc-settings.json にも設定を追加します。
{
"jedi": {
"enable": true,
"startupMessage": false,
"executable.command": "~/.anyenv/envs/pyenv/versions/neovim3/bin/jedi-language-server"
}
}
jedi-language-server が正常に動作しているかを確認する場合はlogを開きます。
:CocCommand workspace.showOutput
Choose by number:
1. git
2. prettier
3. snippets
4. highlight
5. jedi
Type number and <Enter> or click with the mouse (q or empty cancels): 5 # Select jedi
INFO:pygls.server:Starting IO server
INFO:pygls.feature_manager:Registered "textDocument/didOpen" with options "None"
INFO:pygls.feature_manager:Registered "textDocument/didChange" with options "None"
INFO:pygls.feature_manager:Registered "textDocument/didSave" with options "None"
INFO:pygls.feature_manager:Registered "textDocument/didClose" with options "None"
INFO:pygls.feature_manager:Registered "textDocument/hover" with options "None"
INFO:pygls.protocol:Language server initialized ...
実際の入力補完動作
正常に機能していると、以下のように補完動作が効いてくれます。
あとがき
coc-pyrightはmicrosoft/pyright(vscode/settings.json)を踏襲していることもあり、jediと大幅に違ったため見送りました。
coc.nvimのExtensionはサーバのインストール忘れ、あるいはパス指定忘れが原因で正常に動作していないケースがよくあります。困った時には
:CocCommand workspace.showOutput
にて状況を確認してみましょう。