-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruff server
: Write a setup guide for Neovim (#10987)
## Summary A setup guide has been written for NeoVim under a new `crates/ruff_server/docs/setup` folder, where future setup guides will also go. This setup guide was adapted from the [`ruff-lsp` guide](https://github.com/astral-sh/ruff-lsp?tab=readme-ov-file#example-neovim). --------- Co-authored-by: Dhruv Manilawala <[email protected]>
- Loading branch information
1 parent
4d8890e
commit 5da7299
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Neovim Setup Guide for `ruff server` | ||
|
||
### Using `nvim-lspconfig` | ||
|
||
1. Install [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig). | ||
1. Setup `nvim-lspconfig` with the [suggested configuration](https://github.com/neovim/nvim-lspconfig/tree/master#suggested-configuration). | ||
1. Finally, add this to your `init.lua`: | ||
|
||
```lua | ||
require('lspconfig').ruff.setup() | ||
``` | ||
|
||
See [`nvim-lspconfig`'s server configuration guide](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff) 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`: | ||
|
||
```lua | ||
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: | ||
|
||
```lua | ||
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 = { '*' }, | ||
}, | ||
}, | ||
}, | ||
} | ||
``` |