aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/util.lua
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2022-08-26 21:25:39 +0800
committerGitHub <noreply@github.com>2022-08-26 21:25:39 +0800
commitb89530f9f8783f19a172ed3a94fca2ba993c653b (patch)
tree2a9055c08a510645684ea521e9c7142f41fb89dd /lua/lspconfig/util.lua
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar.gz
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar.bz2
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar.lz
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar.xz
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.tar.zst
nvim-lspconfig-b89530f9f8783f19a172ed3a94fca2ba993c653b.zip
Revert "fix: remove the config.commands (#2092)" (#2093)
This reverts commit 99e0dc9937b124dee7d8107185e804ff96466279.
Diffstat (limited to 'lua/lspconfig/util.lua')
-rw-r--r--lua/lspconfig/util.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index 41855fc2..0729430f 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -60,6 +60,41 @@ function M.add_hook_after(func, new_fn)
end
end
+-- Maps lspconfig-style command options to nvim_create_user_command (i.e. |command-attributes|) option names.
+local opts_aliases = {
+ ['description'] = 'desc',
+}
+
+---@param command_definition table<string | integer, any>
+function M._parse_user_command_options(command_definition)
+ ---@type table<string, string | boolean | number>
+ local opts = {}
+ for k, v in pairs(command_definition) do
+ if type(k) == 'string' then
+ local attribute = k.gsub(k, '^%-+', '')
+ opts[opts_aliases[attribute] or attribute] = v
+ elseif type(k) == 'number' and type(v) == 'string' and v:match '^%-' then
+ -- Splits strings like "-nargs=* -complete=customlist,v:lua.something" into { "-nargs=*", "-complete=customlist,v:lua.something" }
+ for _, command_attribute in ipairs(vim.split(v, '%s')) do
+ -- Splits attribute into a key-value pair, like "-nargs=*" to { "-nargs", "*" }
+ local attribute, value = unpack(vim.split(command_attribute, '=', { plain = true }))
+ attribute = attribute.gsub(attribute, '^%-+', '')
+ opts[opts_aliases[attribute] or attribute] = value or true
+ end
+ end
+ end
+ return opts
+end
+
+function M.create_module_commands(module_name, commands)
+ for command_name, def in pairs(commands) do
+ local opts = M._parse_user_command_options(def)
+ api.nvim_create_user_command(command_name, function(info)
+ require('lspconfig')[module_name].commands[command_name][1](unpack(info.fargs))
+ end, opts)
+ end
+end
+
-- Some path utilities
M.path = (function()
local is_windows = uv.os_uname().version:match 'Windows'