Skip to content

Commit 5da7299

Browse files
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]>
1 parent 4d8890e commit 5da7299

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

crates/ruff_server/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ listen for requests from the client, (in this case, the code editor of your choi
55
crates to create real-time diagnostics or formatted code, which is then sent back to the client. It also tracks configuration
66
files in your editor's workspace, and will refresh its in-memory configuration whenever those files are modified.
77

8+
### Setup
9+
10+
We have specific setup instructions depending on your editor. If you don't see your editor on this list and would like a setup guide, please open an issue.
11+
12+
- Visual Studio Code: Install the [Ruff extension from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff). The language server used by the extension will be, by default, the one in your actively-installed `ruff` binary. If you don't have `ruff` installed and haven't provided a path to the extension, it comes with a bundled `ruff` version that it will use instead. Since the new Ruff language server has not yet been stabilized, you will need to use the pre-release version of the extension and enable the `Experimental Server` setting.
13+
- Neovim: See the [Neovim setup guide](docs/setup/NEOVIM.md).
14+
815
### Contributing
916

1017
If you're interested in contributing to `ruff server` - well, first of all, thank you! Second of all, you might find the [**contribution guide**](CONTRIBUTING.md) to be a useful resource. Finally, don't hesitate to reach out on our [**Discord**](https://discord.com/invite/astral-sh) if you have questions.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Neovim Setup Guide for `ruff server`
2+
3+
### Using `nvim-lspconfig`
4+
5+
1. Install [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig).
6+
1. Setup `nvim-lspconfig` with the [suggested configuration](https://github.com/neovim/nvim-lspconfig/tree/master#suggested-configuration).
7+
1. Finally, add this to your `init.lua`:
8+
9+
```lua
10+
require('lspconfig').ruff.setup()
11+
```
12+
13+
See [`nvim-lspconfig`'s server configuration guide](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff) for more details
14+
on how to configure the server from there.
15+
16+
> \[!IMPORTANT\]
17+
>
18+
> If you have the older language server (`ruff-lsp`) configured in Neovim, make sure to disable it to prevent any conflicts.
19+
20+
#### Tips
21+
22+
If you're using Ruff alongside another LSP (like Pyright), you may want to defer to that LSP for certain capabilities, like `textDocument/hover`:
23+
24+
```lua
25+
local on_attach = function(client, bufnr)
26+
if client.name == 'ruff' then
27+
-- Disable hover in favor of Pyright
28+
client.server_capabilities.hoverProvider = false
29+
end
30+
end
31+
32+
require('lspconfig').ruff.setup {
33+
on_attach = on_attach,
34+
}
35+
```
36+
37+
If you'd like to use Ruff exclusively for linting, formatting, and import organization, you can disable those capabilities for Pyright:
38+
39+
```lua
40+
require('lspconfig').pyright.setup {
41+
settings = {
42+
pyright = {
43+
-- Using Ruff's import organizer
44+
disableOrganizeImports = true,
45+
},
46+
python = {
47+
analysis = {
48+
-- Ignore all files for analysis to exclusively use Ruff for linting
49+
ignore = { '*' },
50+
},
51+
},
52+
},
53+
}
54+
```

0 commit comments

Comments
 (0)