diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2023-08-22 12:20:46 +0100 |
|---|---|---|
| committer | Lewis Russell <lewis6991@gmail.com> | 2023-08-22 13:22:08 +0100 |
| commit | 28ec7b6e68bd139087e1c3db7e9e897c888d03ac (patch) | |
| tree | ede731d54bbae77537e2f956aa9d66bbeccb996c /lua/lspconfig/configs.lua | |
| parent | refactor: move manager to separate module (diff) | |
| download | nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar.gz nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar.bz2 nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar.lz nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar.xz nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.tar.zst nvim-lspconfig-28ec7b6e68bd139087e1c3db7e9e897c888d03ac.zip | |
refactor: add sanitize_cmd()
Diffstat (limited to 'lua/lspconfig/configs.lua')
| -rw-r--r-- | lua/lspconfig/configs.lua | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 453f79e1..532befd1 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -14,6 +14,17 @@ local configs = {} --- @field autostart? boolean --- @field package _on_attach? fun(client: lsp.Client, bufnr: integer) +--- @param cmd any +local function sanitize_cmd(cmd) + if cmd and type(cmd) == 'table' and not vim.tbl_isempty(cmd) then + local original = cmd[1] + cmd[1] = vim.fn.exepath(cmd[1]) + if #cmd[1] == 0 then + cmd[1] = original + end + end +end + function configs.__newindex(t, config_name, config_def) validate { name = { config_name, 's' }, @@ -78,14 +89,7 @@ function configs.__newindex(t, config_name, config_def) local config = tbl_deep_extend('keep', user_config, default_config) - local cmd = config.cmd - if cmd and type(cmd) == 'table' and not vim.tbl_isempty(cmd) then - local original = cmd[1] - cmd[1] = vim.fn.exepath(cmd[1]) - if #cmd[1] == 0 then - cmd[1] = original - end - end + sanitize_cmd(config.cmd) if util.on_setup then pcall(util.on_setup, config, user_config) |
