ruff/crates/ruff_server/docs/setup/NEOVIM.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.5 KiB

Neovim Setup Guide for ruff server

Using nvim-lspconfig

  1. Install nvim-lspconfig.
  2. Setup nvim-lspconfig with the suggested configuration.
  3. Finally, add this to your init.lua:
require('lspconfig').ruff.setup {}

See nvim-lspconfig's server configuration guide for more details on how to configure the server from there.

!IMPORTANT

If you have the older language server (ruff-lsp) configured in Neovim, make 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:

local on_attach = function(client, bufnr)
  if client.name == 'ruff' then
    -- Disable hover in favor of Pyright
    client.server_capabilities.hoverProvider = false
  end
end

require('lspconfig').ruff.setup {
  on_attach = on_attach,
}

If you'd like to use Ruff exclusively for linting, formatting, and import organization, you can disable those capabilities for Pyright:

require('lspconfig').pyright.setup {
  settings = {
    pyright = {
      -- Using Ruff's import organizer
      disableOrganizeImports = true,
    },
    python = {
      analysis = {
        -- Ignore all files for analysis to exclusively use Ruff for linting
        ignore = { '*' },
      },
    },
  },
}