-
Notifications
You must be signed in to change notification settings - Fork 165
Rope in Vim or Neovim
Lie Ryan edited this page Oct 4, 2021
·
25 revisions
There are a number of Vim integrations for using Rope:
Feature matrix (note: currently incomplete!):
Features | ropevim | python-mode | python-lsp-server (pylsp-rope) |
---|---|---|---|
Renaming | ✔️ | ✔️ | ❌ |
Extract method | ✔️ | ✔️ | ✔️ |
Extract variable | ✔️ | ✔️ | ✔️ |
Move module/global/method | ✔️ | buggy | ❌ |
Inlining | ✔️ | ✔️ | ✔️ |
Use function | ✔️ | ✔️ | ❌ |
Restructure | ✔️ | ❌ | ❌ |
Introduce Factory | ✔️ | ❌ | ❌ |
Change method signature | ✔️ | ✔️ | ❌ |
Transform module to package | ... | ... | ❌ |
Encapsulate Field | ... | ... | ❌ |
Method to method object | ... | ... | ❌ |
" To enable pylsp-rope logging:
" \ 'cmd': {server_info->['pylsp', '-v', '--log-file', '/tmp/vim-lsp-pylsp.log']},
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'pylsp',
\ 'cmd': {server_info->['pylsp']},
\ 'whitelist': ['python'],
\ })
function! s:on_lsp_buffer_enabled() abort
nmap <buffer> <Leader>ca <plug>(lsp-code-action)
endfunction
augroup lsp_install
autocmd!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" ALE LSP
let g:ale_linters = {
\ 'python': ['pylsp'],
\}
" To enable pylsp-rope logging:
" let g:ale_python_pylsp_options = '-v --log-file /tmp/ale-pylsp.log'
Note: currently very buggy, not recommended for now
lua << EOF
local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
local opts = { noremap=true, silent=true }
buf_set_keymap('n', '<Leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('v', '<Leader>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
end
require'lspconfig'.pylsp.setup{
-- To enable pylsp-rope logging
-- cmd = { "pylsp", "-v", "--log-file", "/tmp/nvim-pylsp.log" },
cmd = { "pylsp" },
on_attach = on_attach,
}
In :CocConfig
:
{
"languageserver": {
"python": {
"command": "python3",
"args": [
"-mpylsp"
// To enable pylsp-rope logging
// ,"-vv", "--log-file", "/tmp/coc-lsp.log"
],
"trace.server": "verbose",
"filetypes": [
"python"
],
"settings": {
"pyls": {
"enable": true,
"trace": {
"server": "verbose"
},
"commandPath": "",
"configurationSources": [
"pycodestyle"
],
"plugins": {
}
}
}
}
}
map <Leader>ca <Plug>(coc-codeaction-selected)