diff options
| author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-13 12:36:36 -0800 |
|---|---|---|
| committer | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-13 12:36:36 -0800 |
| commit | 38741041048dfdd821708a2f4f51aa0bb6a0213b (patch) | |
| tree | a6488a197a9383bdd5e7712581051a8940a922a8 /lua/common_lsp/skeleton.lua | |
| parent | Add hyperlinks to the examples. (diff) | |
| download | nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar.gz nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar.bz2 nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar.lz nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar.xz nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.tar.zst nvim-lspconfig-38741041048dfdd821708a2f4f51aa0bb6a0213b.zip | |
Improve the skeleton.
Diffstat (limited to 'lua/common_lsp/skeleton.lua')
| -rw-r--r-- | lua/common_lsp/skeleton.lua | 76 |
1 files changed, 48 insertions, 28 deletions
diff --git a/lua/common_lsp/skeleton.lua b/lua/common_lsp/skeleton.lua index b08307ca..72828474 100644 --- a/lua/common_lsp/skeleton.lua +++ b/lua/common_lsp/skeleton.lua @@ -1,7 +1,6 @@ -local api = vim.api -local validate = vim.validate local util = require 'common_lsp/util' -local lsp = vim.lsp +local api, validate, lsp = vim.api, vim.validate, vim.lsp +local inspect = vim.inspect local M = {} @@ -9,21 +8,20 @@ local default_config default_config = { name = "SKELETON"; cmd = {"SKELETON"}; - filetype = {"c", "cpp"}; - SKELETON_log_level = lsp.protocol.MessageType.Warning; - SKELETON_settings = {}; + filetype = {"SKELETON"}; + log_level = lsp.protocol.MessageType.Warning; + settings = {}; } local function setup_callbacks(config) config.callbacks = config.callbacks or {} config.callbacks["window/logMessage"] = function(err, method, params, client_id) - if params and params.type <= config.texlab_log_level then + if params and params.type <= config.log_level then lsp.builtin_callbacks[method](err, method, params, client_id) end end - -- TODO use existing callback? config.callbacks["workspace/configuration"] = function(err, method, params, client_id) if err then error(tostring(err)) end if not params.items then @@ -33,8 +31,8 @@ local function setup_callbacks(config) local result = {} for _, item in ipairs(params.items) do if item.section then - local value = util.lookup_section(config, item.section) or vim.NIL - print(string.format("config[%q] = %s", item.section, vim.inspect(value))) + local value = util.lookup_section(config.settings, item.section) or vim.NIL + print(string.format("config[%q] = %s", item.section, inspect(value))) table.insert(result, value) end end @@ -42,38 +40,46 @@ local function setup_callbacks(config) end end +M.name = "SKELETON" + +local function module_fn(fn_body) + validate { fn_body = {fn_body, 's'} } + return string.format("lua require 'common_lsp/%s'.%s", M.name, fn_body) +end + -- A function to set up SKELETON easier. -- -- Additionally, it sets up the following commands: --- - SKELETONCommand +-- - SKELETON_SPOOKY_COMMAND: This does something SPOOKY. +-- - SKELETON_OTHER_COMMAND: This does some OTHER thing. -- -- {config} is the same as |vim.lsp.add_filetype_config()|, but with some -- additions and changes: -- --- {SKELETON_log_level} +-- {name} +-- Defaults to "SKELETON" +-- +-- {cmd} +-- Defaults to {"SKELETON"} +-- +-- {filetype} +-- Defaults to {"SKELETON"} +-- +-- {log_level} -- controls the level of logs to show from build processes and other -- window/logMessage events. By default it is set to -- vim.lsp.protocol.MessageType.Warning instead of -- vim.lsp.protocol.MessageType.Log. -- --- {SKELETON_settings} +-- {settings} -- This is a table, and the keys are case sensitive. --- Example: `SKELETON_settings = { }` --- --- {filetype} --- Defaults to {"c", "cpp"} --- --- {cmd} --- Defaults to {"SKELETON"} --- --- {name} --- Defaults to "SKELETON" +-- Example: `settings = { }` function M.setup(config) config = vim.tbl_extend("keep", config, default_config) util.tbl_deep_extend(config.settings, default_config.settings) - config.capabilities = config.capabilities or vim.lsp.protocol.make_client_capabilities() + config.capabilities = config.capabilities or lsp.protocol.make_client_capabilities() util.tbl_deep_extend(config.capabilities, { workspace = { configuration = true; @@ -86,17 +92,31 @@ function M.setup(config) if bufnr == api.nvim_get_current_buf() then M._setup_buffer() else - util.nvim_multiline_command(string.format("autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/SKELETON'._setup_buffer()", bufnr)) + api.nvim_command(string.format( + "autocmd BufEnter <buffer=%d> ++once lua require'common_lsp/SKELETON'._setup_buffer()", + bufnr)) end end) - -- TODO should this find the project root instead? lsp.add_filetype_config(config) end function M._setup_buffer() - util.nvim_multiline_command [[ - ]] + local commands = { + "command! SKELETON_SPOOKY_COMMAND -buffer "..module_fn("buf_SPOOKY_FUNCTION(0)"); + "command! SKELETON_OTHER_COMMAND -buffer "..module_fn("buf_OTHER_FUNCTION(0)"); + } + for _, command in ipairs(commands) do + api.nvim_command(command) + end +end + +function M.buf_SPOOKY_FUNCTION(bufnr) + bufnr = util.validate_bufnr(bufnr) +end + +function M.buf_OTHER_FUNCTION(bufnr) + bufnr = util.validate_bufnr(bufnr) end return M |
