diff options
Diffstat (limited to 'lua/lspconfig/configs.lua')
| -rw-r--r-- | lua/lspconfig/configs.lua | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/lua/lspconfig/configs.lua b/lua/lspconfig/configs.lua index 087b9ddf..e8ad78f0 100644 --- a/lua/lspconfig/configs.lua +++ b/lua/lspconfig/configs.lua @@ -1,4 +1,4 @@ -local util = require 'lspconfig/util' +local util = require "lspconfig/util" local api, validate, lsp = vim.api, vim.validate, vim.lsp local tbl_extend = vim.tbl_extend @@ -6,17 +6,17 @@ local configs = {} function configs.__newindex(t, config_name, config_def) validate { - name = {config_name, 's'}; - default_config = {config_def.default_config, 't'}; - on_new_config = {config_def.on_new_config, 'f', true}; - on_attach = {config_def.on_attach, 'f', true}; - commands = {config_def.commands, 't', true}; + name = { config_name, "s" }, + default_config = { config_def.default_config, "t" }, + on_new_config = { config_def.on_new_config, "f", true }, + on_attach = { config_def.on_attach, "f", true }, + commands = { config_def.commands, "t", true }, } if config_def.commands then for k, v in pairs(config_def.commands) do validate { - ['command.name'] = {k, 's'}; - ['command.fn'] = {v[1], 'f'}; + ["command.name"] = { k, "s" }, + ["command.fn"] = { v[1], "f" }, } end else @@ -32,18 +32,18 @@ function configs.__newindex(t, config_name, config_def) function M.setup(config) validate { - cmd = {config.cmd, 't', default_config.cmd ~= nil}; - root_dir = {config.root_dir, 'f', default_config.root_dir ~= nil}; - 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 = { config.cmd, "t", default_config.cmd ~= nil }, + root_dir = { config.root_dir, "f", default_config.root_dir ~= nil }, + 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 }, } if config.commands then for k, v in pairs(config.commands) do validate { - ['command.name'] = {k, 's'}; - ['command.fn'] = {v[1], 'f'}; + ["command.name"] = { k, "s" }, + ["command.fn"] = { v[1], "f" }, } end end @@ -52,16 +52,12 @@ function configs.__newindex(t, config_name, config_def) local trigger if config.filetypes then - trigger = "FileType "..table.concat(config.filetypes, ',') + trigger = "FileType " .. table.concat(config.filetypes, ",") else trigger = "BufReadPost *" end if not (config.autostart == false) then - api.nvim_command(string.format( - "autocmd %s lua require'lspconfig'[%q].manager.try_add()" - , trigger - , config.name - )) + api.nvim_command(string.format("autocmd %s lua require'lspconfig'[%q].manager.try_add()", trigger, config.name)) end local get_root_dir = config.root_dir @@ -72,11 +68,13 @@ function configs.__newindex(t, config_name, config_def) vim.notify(string.format("Autostart for %s failed: matching root directory not detected.", config_name)) return end - api.nvim_command(string.format( - "autocmd %s lua require'lspconfig'[%q].manager.try_add_wrapper()" - , "BufReadPost " .. root_dir .. "/*" - , config.name - )) + api.nvim_command( + string.format( + "autocmd %s lua require'lspconfig'[%q].manager.try_add_wrapper()", + "BufReadPost " .. root_dir .. "/*", + config.name + ) + ) for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do local buf_dir = api.nvim_buf_get_name(bufnr) if buf_dir:sub(1, root_dir:len()) == root_dir then @@ -103,12 +101,12 @@ function configs.__newindex(t, config_name, config_def) local make_config = function(_root_dir) local new_config = vim.tbl_deep_extend("keep", vim.empty_dict(), config) - new_config = vim.tbl_deep_extend('keep', new_config, default_config) + new_config = vim.tbl_deep_extend("keep", new_config, default_config) new_config.capabilities = new_config.capabilities or lsp.protocol.make_client_capabilities() - new_config.capabilities = vim.tbl_deep_extend('keep', new_config.capabilities, { + new_config.capabilities = vim.tbl_deep_extend("keep", new_config.capabilities, { workspace = { - configuration = true; - } + configuration = true, + }, }) if config_def.on_new_config then @@ -120,12 +118,14 @@ function configs.__newindex(t, config_name, config_def) new_config.on_init = util.add_hook_after(new_config.on_init, function(client, _result) function client.workspace_did_change_configuration(settings) - if not settings then return end + if not settings then + return + end if vim.tbl_isempty(settings) then - settings = {[vim.type_idx]=vim.types.dictionary} + settings = { [vim.type_idx] = vim.types.dictionary } end - return client.notify('workspace/didChangeConfiguration', { - settings = settings; + return client.notify("workspace/didChangeConfiguration", { + settings = settings, }) end if not vim.tbl_isempty(new_config.settings) then @@ -139,13 +139,15 @@ function configs.__newindex(t, config_name, config_def) if bufnr == api.nvim_get_current_buf() then M._setup_buffer(client.id, bufnr) else - api.nvim_command(string.format( - "autocmd BufEnter <buffer=%d> ++once lua require'lspconfig'[%q]._setup_buffer(%d,%d)" - , bufnr - , config_name - , client.id - , bufnr - )) + api.nvim_command( + string.format( + "autocmd BufEnter <buffer=%d> ++once lua require'lspconfig'[%q]._setup_buffer(%d,%d)", + bufnr, + config_name, + client.id, + bufnr + ) + ) end end) @@ -159,7 +161,7 @@ function configs.__newindex(t, config_name, config_def) function manager.try_add(bufnr) bufnr = bufnr or api.nvim_get_current_buf() - if vim.api.nvim_buf_get_option(bufnr, 'filetype') == 'nofile' then + if vim.api.nvim_buf_get_option(bufnr, "filetype") == "nofile" then return end local root_dir = get_root_dir(api.nvim_buf_get_name(bufnr), bufnr) @@ -170,7 +172,7 @@ function configs.__newindex(t, config_name, config_def) end function manager.try_add_wrapper(bufnr) - local buftype = vim.api.nvim_buf_get_option(bufnr, 'filetype') + local buftype = vim.api.nvim_buf_get_option(bufnr, "filetype") for _, filetype in ipairs(config.filetypes) do if buftype == filetype then manager.try_add(bufnr) |
