ruff/crates/ruff_server/docs/setup/VIM.md
JaRoSchm 7ce17b7736
Add Vim and Kate setup guide for ruff server (#11615)
## Summary

In the [roadmap for `ruff
server`](https://github.com/astral-sh/ruff/discussions/10581) support
for vim and kate is listed. Therefore I added setup guides for them
based on the neovim guide. As I don't use pyright I wasn't able to
translate the corresponding part from the neovim guide.

## Test Plan

Doesn't apply.
2024-05-31 19:06:55 +00:00

1.4 KiB

Vim Setup Guide for ruff server

Using vim-lsp

  1. Install vim-lsp.
  2. Setup vim-lsp as desired.
  3. Finally, add this to your .vimrc:
if executable('ruff')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'ruff',
        \ 'cmd': {server_info->['ruff', 'server', '--preview']},
        \ 'allowlist': ['python'],
        \ 'workspace_config': {},
        \ })
endif

See the vim-lsp documentation for more details on how to configure the language server.

!IMPORTANT

If Ruff's legacy language server (ruff-lsp) is configured in Vim, be sure to disable it to prevent any conflicts.

Tips

If you're using Ruff alongside another LSP (like Pyright), you may want to defer to that LSP for certain capabilities, like textDocument/hover by adding the following to the function s:on_lsp_buffer_enabled():

function! s:on_lsp_buffer_enabled() abort
    " add your keybindings here (see https://github.com/prabirshrestha/vim-lsp?tab=readme-ov-file#registering-servers)

    let l:capabilities = lsp#get_server_capabilities('ruff')
    if !empty(l:capabilities)
      let l:capabilities.hoverProvider = v:false
    endif
endfunction