Skip to content

Commit b2ab7de

Browse files
committed
feat(lsp)!: don't auto-register LSP client capabilities
Use `:h vim.lsp.config` instead.
1 parent 7b835e3 commit b2ab7de

File tree

4 files changed

+14
-61
lines changed

4 files changed

+14
-61
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,12 @@ vim.g.rustaceanvim = {
797797

798798
> [!TIP]
799799
>
800-
> `vim.g.rustaceanvim` can also be a function that returns
801-
> a table.
800+
> - `vim.g.rustaceanvim` can also be a function that returns
801+
> a table.
802+
>
803+
> - You can also use `:h vim.lsp.config` to configure `vim.g.rustaceanvim.server`
804+
> options.
805+
> For example, `vim.lsp.config("*", {})` or `vim.lsp.config("rust-analyzer", {})`.
802806
803807
### Using `codelldb` for debugging
804808

doc/rustaceanvim.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ rustaceanvim.Opts *rustaceanvim.Opts*
166166
Plugin options.
167167
{server?} (rustaceanvim.lsp.ClientOpts)
168168
Language server client options.
169-
In Neovim >= 0.11 (nightly), these can also be set using |vim.lsp.config()| for "rust-analyzer".
169+
These can also be set using |vim.lsp.config()| for "rust-analyzer" or "*".
170170
If both the `server` table and a `vim.lsp.config["rust-analyzer"]` are defined,
171-
the |vim.lsp.config()| settings are merged into the `server` table, taking precedence over
172-
existing settings.
171+
rustaceanvim merges |vim.lsp.config()| settings into the `server` table,
172+
giving them precedence over existing settings.
173173
{dap?} (rustaceanvim.dap.Opts)
174174
Debug adapter options
175175

lua/rustaceanvim/config/init.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ vim.g.rustaceanvim = vim.g.rustaceanvim
5555
---@field tools? rustaceanvim.tools.Opts
5656
---
5757
---Language server client options.
58-
---In Neovim >= 0.11 (nightly), these can also be set using |vim.lsp.config()| for "rust-analyzer".
58+
---These can also be set using |vim.lsp.config()| for "rust-analyzer" or "*".
5959
---If both the `server` table and a `vim.lsp.config["rust-analyzer"]` are defined,
60-
---the |vim.lsp.config()| settings are merged into the `server` table, taking precedence over
61-
---existing settings.
60+
---rustaceanvim merges |vim.lsp.config()| settings into the `server` table,
61+
---giving them precedence over existing settings.
6262
---@field server? rustaceanvim.lsp.ClientOpts
6363
---
6464
---Debug adapter options

lua/rustaceanvim/config/server.lua

+2-53
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,9 @@ function server.load_rust_analyzer_settings(_, opts)
4040
end
4141

4242
---@return lsp.ClientCapabilities
43-
local function make_rustaceanvim_capabilities()
43+
function server.create_client_capabilities()
4444
local capabilities = vim.lsp.protocol.make_client_capabilities()
4545

46-
if vim.fn.has('nvim-0.10.0') == 1 then
47-
-- snippets
48-
-- This will also be added if cmp_nvim_lsp is detected.
49-
capabilities.textDocument.completion.completionItem.snippetSupport = true
50-
end
51-
5246
-- send actions with hover request
5347
capabilities.experimental = {
5448
hoverActions = true,
@@ -76,57 +70,12 @@ local function make_rustaceanvim_capabilities()
7670
table.insert(experimental_commands, 'rust-analyzer.debugSingle')
7771
end
7872

73+
---@diagnostic disable-next-line: inject-field
7974
capabilities.experimental.commands = {
8075
commands = experimental_commands,
8176
}
8277

8378
return capabilities
8479
end
8580

86-
---@param mod_name string
87-
---@param callback fun(mod: table): lsp.ClientCapabilities
88-
---@return lsp.ClientCapabilities
89-
local function mk_capabilities_if_available(mod_name, callback)
90-
local available, mod = pcall(require, mod_name)
91-
if available and type(mod) == 'table' then
92-
local ok, capabilities = pcall(callback, mod)
93-
if ok then
94-
return capabilities
95-
end
96-
end
97-
return {}
98-
end
99-
100-
---@return lsp.ClientCapabilities
101-
function server.create_client_capabilities()
102-
local rs_capabilities = make_rustaceanvim_capabilities()
103-
local blink_capabilities = mk_capabilities_if_available('blink.cmp', function(blink)
104-
return blink.get_lsp_capabilities()
105-
end)
106-
local cmp_capabilities = mk_capabilities_if_available('cmp_nvim_lsp', function(cmp_nvim_lsp)
107-
return cmp_nvim_lsp.default_capabilities()
108-
end)
109-
local selection_range_capabilities = mk_capabilities_if_available('lsp-selection-range', function(lsp_selection_range)
110-
return lsp_selection_range.update_capabilities {}
111-
end)
112-
local folding_range_capabilities = mk_capabilities_if_available('ufo', function(_)
113-
return {
114-
textDocument = {
115-
foldingRange = {
116-
dynamicRegistration = false,
117-
lineFoldingOnly = true,
118-
},
119-
},
120-
}
121-
end)
122-
return vim.tbl_deep_extend(
123-
'force',
124-
rs_capabilities,
125-
blink_capabilities,
126-
cmp_capabilities,
127-
selection_range_capabilities,
128-
folding_range_capabilities
129-
)
130-
end
131-
13281
return server

0 commit comments

Comments
 (0)