diff options
| author | William Boman <william@redwill.se> | 2022-09-08 08:10:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-08 14:10:59 +0800 |
| commit | 932164a3cc87eafdd20c7d271037bea913b31c7b (patch) | |
| tree | 19a9ad09cc86fdf66744161ce07730ce0a9a7769 | |
| parent | fix(lua-language-server): check if root dir is home directory (#2110) (diff) | |
| download | nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar.gz nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar.bz2 nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar.lz nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar.xz nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.tar.zst nvim-lspconfig-932164a3cc87eafdd20c7d271037bea913b31c7b.zip | |
feat: pass user config to the on_setup hook (#2114)
This is to allow 3rd party plugins to discern between what is
lspconfig's vendored server config and what the user provided.
Currently, these are merged into a single table which is passed to the
on_setup hook. Passing user_config as a 2nd argument would allow 3rd
party plugins to apply a more sensible precedence of configs.
| -rw-r--r-- | lua/lspconfig/configs.lua | 22 | ||||
| -rw-r--r-- | test/lspconfig_spec.lua | 18 |
2 files changed, 29 insertions, 11 deletions
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index a0129776..b963e424 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -30,19 +30,19 @@ function configs.__newindex(t, config_name, config_def) -- Force this part. default_config.name = config_name - function M.setup(config) + function M.setup(user_config) local lsp_group = vim.api.nvim_create_augroup('lspconfig', { clear = false }) validate { - cmd = { config.cmd, 't', true }, - root_dir = { config.root_dir, 'f', true }, - filetypes = { config.filetype, 't', true }, - on_new_config = { config.on_new_config, 'f', true }, - on_attach = { config.on_attach, 'f', true }, - commands = { config.commands, 't', true }, + cmd = { user_config.cmd, 't', true }, + root_dir = { user_config.root_dir, 'f', true }, + filetypes = { user_config.filetype, 't', true }, + on_new_config = { user_config.on_new_config, 'f', true }, + on_attach = { user_config.on_attach, 'f', true }, + commands = { user_config.commands, 't', true }, } - if config.commands then - for k, v in pairs(config.commands) do + if user_config.commands then + for k, v in pairs(user_config.commands) do validate { ['command.name'] = { k, 's' }, ['command.fn'] = { v[1], 'f' }, @@ -50,10 +50,10 @@ function configs.__newindex(t, config_name, config_def) end end - config = tbl_deep_extend('keep', config, default_config) + local config = tbl_deep_extend('keep', user_config, default_config) if util.on_setup then - pcall(util.on_setup, config) + pcall(util.on_setup, config, user_config) end if config.autostart == true then diff --git a/test/lspconfig_spec.lua b/test/lspconfig_spec.lua index f98568c1..8cea4a54 100644 --- a/test/lspconfig_spec.lua +++ b/test/lspconfig_spec.lua @@ -324,5 +324,23 @@ describe('lspconfig', function() { 'rust_analyzer' } ) end) + + it('provides user_config to the on_setup hook', function() + eq( + exec_lua [[ + local lspconfig = require "lspconfig" + local util = require "lspconfig.util" + local user_config + util.on_setup = function (_, _user_config) + user_config = _user_config + end + lspconfig.rust_analyzer.setup { custom_user_config = "custom" } + return user_config + ]], + { + custom_user_config = 'custom', + } + ) + end) end) end) |
