@@ -73,61 +73,21 @@ supports the Language Server Protocol, including [Neovim](https://github.com/ast
73
73
[Sublime Text](https://github.com/astral-sh/ruff-lsp#example-sublime-text), Emacs, and more.
74
74
75
75
For example, to use `ruff-lsp` with Neovim, install `ruff-lsp` from PyPI along with
76
- [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig). Then, add something like the following
77
- to your `init.lua` :
76
+ [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig). Then, set up the Neovim LSP client
77
+ using the [suggested configuration](https://github.com/neovim/nvim-lspconfig/tree/master#configuration)
78
+ (`:h lspconfig-keybindings`). Finally, configure `ruff-lsp` in your `init.lua` :
78
79
79
80
` ` ` lua
80
- -- See: https://github.com/neovim/nvim-lspconfig/tree/54eb2a070a4f389b1be0f98070f81d23e2b1a715#suggested-configuration
81
- local opts = { noremap=true, silent=true }
82
- vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
83
- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
84
- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
85
- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
86
-
87
- -- Use an on_attach function to only map the following keys
88
- -- after the language server attaches to the current buffer
89
- local on_attach = function(client, bufnr)
90
- -- Enable completion triggered by <c-x><c-o>
91
- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
92
-
93
- -- Mappings.
94
- -- See ` :help vim.lsp.*` for documentation on any of the below functions
95
- local bufopts = { noremap=true, silent=true, buffer=bufnr }
96
- vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
97
- vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
98
- vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
99
- vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
100
- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
101
- vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
102
- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
103
- vim.keymap.set('n', '<space>wl', function()
104
- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
105
- end, bufopts)
106
- vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
107
- vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
108
- vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
109
- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
110
- vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts)
111
- end
112
-
113
81
-- Configure ` ruff-lsp`.
114
- local configs = require 'lspconfig.configs'
115
- if not configs.ruff_lsp then
116
- configs.ruff_lsp = {
117
- default_config = {
118
- cmd = { 'ruff-lsp' },
119
- filetypes = { 'python' },
120
- root_dir = require('lspconfig').util.find_git_ancestor,
121
- init_options = {
122
- settings = {
123
- args = {}
124
- }
125
- }
82
+ -- See : https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff_lsp
83
+ -- For the default config, along with instructions on how to customize the settings
84
+ require('lspconfig').ruff_lsp.setup {
85
+ init_options = {
86
+ settings = {
87
+ -- Any extra CLI arguments for `ruff` go here.
88
+ args = {},
126
89
}
127
90
}
128
- end
129
- require('lspconfig').ruff_lsp.setup {
130
- on_attach = on_attach,
131
91
}
132
92
```
133
93
0 commit comments