From d3019b57aee89422600cdec6854403d645c90a06 Mon Sep 17 00:00:00 2001 From: Ashkan Kiani Date: Wed, 13 Nov 2019 13:23:32 -0800 Subject: Improve skeleton --- lua/common_lsp/util.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lua/common_lsp/util.lua') diff --git a/lua/common_lsp/util.lua b/lua/common_lsp/util.lua index ee48b5d7..1aebbfb6 100644 --- a/lua/common_lsp/util.lua +++ b/lua/common_lsp/util.lua @@ -68,6 +68,27 @@ function M.lookup_section(settings, section) return settings end +function M.create_module_commands(module_name, commands) + for command_name, def in pairs(commands) do + local parts = {"command!"} + -- Insert attributes. + for k, v in pairs(def) do + if type(k) == 'string' and type(v) == 'boolean' and v then + table.insert(parts, "-"..k) + elseif type(k) == 'number' and type(v) == 'string' and v:match("^%-") then + table.insert(parts, v) + end + end + table.insert(parts, command_name) + -- The command definition. + table.insert(parts, + string.format("lua require'common_lsp/%s'.commands[%q][1]()", module_name, command_name)) + local command = table.concat(parts, " ") + print(command) + api.nvim_command(command) + end +end + return M -- vim:et ts=2 sw=2 -- cgit v1.2.3-70-g09d2