mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(lsp): return table from lsp/ files on runtimepath (#31663)
Problem: LSP configs on the runtimepath must have the same name as the LSP server and must also explicitly set the name in vim.lsp.config. This is redundant and creates a footgun where a user may accidentally use the wrong name when assigning to the vim.lsp.config table. Solution: Return a table from lsp/ runtimepath files instead
This commit is contained in:
parent
382eb878bc
commit
130b5fd85f
@ -74,12 +74,8 @@ configurations, in increasing priority, from the following:
|
|||||||
|
|
||||||
1. Configuration defined for the `'*'` name.
|
1. Configuration defined for the `'*'` name.
|
||||||
|
|
||||||
2. Configuration from the result of sourcing all `lsp/<name>.lua` files
|
2. Configuration from the result of merging all tables returned by
|
||||||
in 'runtimepath' for a server of name `name`.
|
`lsp/<name>.lua` files in 'runtimepath' for a server of name `name`.
|
||||||
|
|
||||||
Note: because of this, calls to |vim.lsp.config()| in `lsp/*.lua` are
|
|
||||||
treated independently to other calls. This ensures configurations
|
|
||||||
defined in `lsp/*.lua` have a lower priority.
|
|
||||||
|
|
||||||
3. Configurations defined anywhere else.
|
3. Configurations defined anywhere else.
|
||||||
|
|
||||||
@ -102,11 +98,11 @@ Given: >lua
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- Defined in ../lsp/clangd.lua
|
-- Defined in ../lsp/clangd.lua
|
||||||
vim.lsp.config('clangd', {
|
return {
|
||||||
cmd = { 'clangd' },
|
cmd = { 'clangd' },
|
||||||
root_markers = { '.clangd', 'compile_commands.json' },
|
root_markers = { '.clangd', 'compile_commands.json' },
|
||||||
filetypes = { 'c', 'cpp' },
|
filetypes = { 'c', 'cpp' },
|
||||||
})
|
}
|
||||||
|
|
||||||
-- Defined in init.lua
|
-- Defined in init.lua
|
||||||
vim.lsp.config('clangd', {
|
vim.lsp.config('clangd', {
|
||||||
|
@ -22,6 +22,12 @@ EXPERIMENTS
|
|||||||
|
|
||||||
• Removed `vim.loader.disable()`. Use `vim.loader.enable(false)` instead.
|
• Removed `vim.loader.disable()`. Use `vim.loader.enable(false)` instead.
|
||||||
|
|
||||||
|
LSP
|
||||||
|
|
||||||
|
• `lsp/` runtimepath files should return a table instead of calling
|
||||||
|
|vim.lsp.config()| (or assigning to `vim.lsp.config`). See |lsp-config|
|
||||||
|
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
• 'jumpoptions' flag "unload" has been renamed to "clean".
|
• 'jumpoptions' flag "unload" has been renamed to "clean".
|
||||||
|
@ -450,16 +450,20 @@ function lsp._resolve_config(name)
|
|||||||
if not econfig.resolved_config then
|
if not econfig.resolved_config then
|
||||||
-- Resolve configs from lsp/*.lua
|
-- Resolve configs from lsp/*.lua
|
||||||
-- Calls to vim.lsp.config in lsp/* have a lower precedence than calls from other sites.
|
-- Calls to vim.lsp.config in lsp/* have a lower precedence than calls from other sites.
|
||||||
local orig_configs = lsp.config._configs
|
local rtp_config = {} ---@type vim.lsp.Config
|
||||||
lsp.config._configs = {}
|
for _, v in ipairs(api.nvim_get_runtime_file(('lsp/%s.lua'):format(name), true)) do
|
||||||
pcall(vim.cmd.runtime, { ('lsp/%s.lua'):format(name), bang = true })
|
local config = assert(loadfile(v))() ---@type any?
|
||||||
local rtp_configs = lsp.config._configs
|
if type(config) == 'table' then
|
||||||
lsp.config._configs = orig_configs
|
rtp_config = vim.tbl_deep_extend('force', rtp_config, config)
|
||||||
|
else
|
||||||
|
log.warn(string.format('%s does not return a table, ignoring', v))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local config = vim.tbl_deep_extend(
|
local config = vim.tbl_deep_extend(
|
||||||
'force',
|
'force',
|
||||||
lsp.config._configs['*'] or {},
|
lsp.config._configs['*'] or {},
|
||||||
rtp_configs[name] or {},
|
rtp_config,
|
||||||
lsp.config._configs[name] or {}
|
lsp.config._configs[name] or {}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user