coc.nvm 升級後提示jedi版本太舊解決方案

coc.nvim升級後,大概是coc-python版本在1.2.10以上時,在使用函數功能跳轉時,會提示jedi version %s too old, requires >= 0.17.0。這個問題在github上顯示已解決,解決方案是安裝指定版本的coc-python

CocInstall [email protected]

但是這個方法並沒有解決我的問題。這個版本的coc-python也是要求jedi版本大於0.17.0的。

因此我將jedi版本更新到了要求版本。

pip3 install jedi
# conda 如果只能安裝0.16.0版本的話,可以先pip3安裝,然後copy到conda的site-package文件夾下

但是依然報錯,信息如下:

is_definition() got an unexpected keyword argument ‘include_setitem’, get_definition() got an unexpected keyword argument ‘include_setitem’

你只需要到你的conda的jedi庫文件夾中,找到syntax_tree.py,和filter.py這兩個文件,修改相應的is_definitionget_definition即可。

inference/syntax_tree.py
667:    node = tree_name.get_definition(import_name_always=True, include_setitem=True)

inference/filters.py
66:            name for name in names if name.is_definition(include_setitem=True)

刪除include_setitem=True即可。


此外,推薦一個python函數跳轉的插件jedi-vim
vim-plug安裝方法:

Plug 'davidhalter/jedi-vim'

相關配置如下:

let g:jedi#goto_command = "<leader>d"
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_stubs_command = "<leader>s"
"let g:jedi#goto_definitions_command = "gd"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#completions_command = "<C-Space>"
let g:jedi#rename_command = "<leader>r"

這個跳轉要比coc自帶的要好一些,coc函數跳轉默認你對文件進行了修改,當你使用Ctrl-O返回原文件時,需要保存一下跳轉文件或者返回一次修改(按一下u)。但是jedi-vim不會對跳轉文件進行修改。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章