From fe5daa722fb75ad85c24936cbb645018bb9d655b Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 31 Jul 2021 16:12:29 +0200 Subject: [Feature] Expose lsp config (#1156) --- lua/default-config.lua | 47 ++++++++++++++++++++++++++++++++++++++++++----- lua/keymappings.lua | 12 ++++++++++++ lua/lsp/handlers.lua | 2 +- lua/lsp/init.lua | 35 +++++++++++++++++------------------ lua/lsp/keybinds.lua | 27 --------------------------- lua/lsp/kind.lua | 33 --------------------------------- lua/lsp/signs.lua | 20 -------------------- lua/utils/init.lua | 8 -------- 8 files changed, 72 insertions(+), 112 deletions(-) delete mode 100644 lua/lsp/keybinds.lua delete mode 100644 lua/lsp/kind.lua delete mode 100644 lua/lsp/signs.lua (limited to 'lua') diff --git a/lua/default-config.lua b/lua/default-config.lua index 4e849688..6527ad77 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -34,19 +34,55 @@ lvim = { }, lsp = { + completion = { + item_kind = { + "  (Text) ", + "  (Method)", + "  (Function)", + "  (Constructor)", + " ﴲ (Field)", + "[] (Variable)", + "  (Class)", + " ﰮ (Interface)", + "  (Module)", + " 襁 (Property)", + "  (Unit)", + "  (Value)", + " 練 (Enum)", + "  (Keyword)", + "  (Snippet)", + "  (Color)", + "  (File)", + "  (Reference)", + "  (Folder)", + "  (EnumMember)", + " ﲀ (Constant)", + " ﳤ (Struct)", + "  (Event)", + "  (Operator)", + "  (TypeParameter)", + }, + }, diagnostics = { + signs = { + active = true, + values = { + { name = "LspDiagnosticsSignError", text = "" }, + { name = "LspDiagnosticsSignWarning", text = "" }, + { name = "LspDiagnosticsSignHint", text = "" }, + { name = "LspDiagnosticsSignInformation", text = "" }, + }, + }, virtual_text = { prefix = "", spacing = 0, }, - signs = true, underline = true, severity_sort = true, }, override = {}, document_highlight = true, popup_border = "single", - default_keybinds = true, on_attach_callback = nil, on_init_callback = nil, }, @@ -60,9 +96,10 @@ lvim = { } local schemas = nil -local common_on_attach = require("lsp").common_on_attach -local common_capabilities = require("lsp").common_capabilities() -local common_on_init = require("lsp").common_on_init +local lsp = require "lsp" +local common_on_attach = lsp.common_on_attach +local common_capabilities = lsp.common_capabilities() +local common_on_init = lsp.common_on_init local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") if status_ok then schemas = jsonls_settings.get_default_schemas() diff --git a/lua/keymappings.lua b/lua/keymappings.lua index 3cbe797a..34116023 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -49,6 +49,18 @@ local keymaps = { { "", ":call QuickFixToggle()" }, -- {'', 'compe#complete()', {noremap = true, silent = true, expr = true}}, + + -- LSP + { "gd", "lua vim.lsp.buf.definition()" }, + { "gD", "lua vim.lsp.buf.declaration()" }, + { "gr", "lua vim.lsp.buf.references()" }, + { "gi", "lua vim.lsp.buf.implementation()" }, + { "gl", "lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })" }, + { "gp", "lua require'lsp.peek'.Peek('definition')" }, + { "K", "lua vim.lsp.buf.hover()" }, + { "", "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" }, + { "", "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" }, + -- { "", "lua vim.lsp.buf.signature_help()" }, }, term_mode = { diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 3a467d42..a25db3c1 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -5,7 +5,7 @@ local M = {} function M.setup() vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = lvim.lsp.diagnostics.virtual_text, - signs = lvim.lsp.diagnostics.signs, + signs = lvim.lsp.diagnostics.signs.active, underline = lvim.lsp.document_highlight, }) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 1488aec0..13b64dac 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,9 +1,14 @@ local M = {} local u = require "utils" + function M.config() - require("lsp.kind").setup() + vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind + + for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) + end + require("lsp.handlers").setup() - require("lsp.signs").setup() end local function lsp_highlight_document(client) @@ -28,16 +33,6 @@ local function lsp_highlight_document(client) end end -local function formatter_handler(client) - local formatters = lvim.lang[vim.bo.filetype].formatters - if not vim.tbl_isempty(formatters) then - client.resolved_capabilities.document_formatting = false - u.lvim_log( - string.format("Overriding [%s] formatting if exists, Using provider [%s] instead", client.name, formatters[1].exe) - ) - end -end - function M.common_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -56,7 +51,12 @@ function M.common_on_init(client, bufnr) lvim.lsp.on_init_callback(client, bufnr) return end - formatter_handler(client) + + local formatters = lvim.lang[vim.bo.filetype].formatters + if not vim.tbl_isempty(formatters) then + client.resolved_capabilities.document_formatting = false + u.lvim_log(string.format("Overriding [%s] formatter with [%s]", client.name, formatters[1].exe)) + end end function M.common_on_attach(client, bufnr) @@ -64,18 +64,17 @@ function M.common_on_attach(client, bufnr) lvim.lsp.on_attach_callback(client, bufnr) end lsp_highlight_document(client) - require("lsp.keybinds").setup() require("lsp.null-ls").setup(vim.bo.filetype) end function M.setup(lang) - local lang_server = lvim.lang[lang].lsp - local provider = lang_server.provider - if require("utils").check_lsp_client_active(provider) then + local lsp = lvim.lang[lang].lsp + if require("utils").check_lsp_client_active(lsp.provider) then return end - require("lspconfig")[provider].setup(lang_server.setup) + local lspconfig = require "lspconfig" + lspconfig[lsp.provider].setup(lsp.setup) end return M diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua deleted file mode 100644 index 21f29994..00000000 --- a/lua/lsp/keybinds.lua +++ /dev/null @@ -1,27 +0,0 @@ -local M = {} - -function M.setup() - if lvim.lsp.default_keybinds then - vim.cmd "nnoremap gd lua vim.lsp.buf.definition()" - vim.cmd "nnoremap gD lua vim.lsp.buf.declaration()" - vim.cmd "nnoremap gr lua vim.lsp.buf.references()" - vim.cmd "nnoremap gi lua vim.lsp.buf.implementation()" - vim.api.nvim_set_keymap( - "n", - "gl", - 'lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })', - { noremap = true, silent = true } - ) - - vim.cmd "nnoremap gp lua require'lsp.peek'.Peek('definition')" - vim.cmd "nnoremap K :lua vim.lsp.buf.hover()" - vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})" - vim.cmd "nnoremap :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})" - -- vim.cmd "nnoremap gs lua vim.lsp.buf.signature_help()" - -- scroll down hover doc or scroll in definition preview - -- scroll up hover doc - -- vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()' - end -end - -return M diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua deleted file mode 100644 index e3b95ecb..00000000 --- a/lua/lsp/kind.lua +++ /dev/null @@ -1,33 +0,0 @@ -local M = {} - -function M.setup() - vim.lsp.protocol.CompletionItemKind = { - -- symbols for autocomplete - "  (Text) ", - "  (Method)", - "  (Function)", - "  (Constructor)", - " ﴲ (Field)", - "[] (Variable)", - "  (Class)", - " ﰮ (Interface)", - "  (Module)", - " 襁 (Property)", - "  (Unit)", - "  (Value)", - " 練 (Enum)", - "  (Keyword)", - "  (Snippet)", - "  (Color)", - "  (File)", - "  (Reference)", - "  (Folder)", - "  (EnumMember)", - " ﲀ (Constant)", - " ﳤ (Struct)", - "  (Event)", - "  (Operator)", - "  (TypeParameter)", - } -end -return M diff --git a/lua/lsp/signs.lua b/lua/lsp/signs.lua deleted file mode 100644 index fab6d302..00000000 --- a/lua/lsp/signs.lua +++ /dev/null @@ -1,20 +0,0 @@ -local M = {} -function M.setup() - vim.fn.sign_define( - "LspDiagnosticsSignError", - { texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError" } - ) - vim.fn.sign_define( - "LspDiagnosticsSignWarning", - { texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning" } - ) - vim.fn.sign_define( - "LspDiagnosticsSignHint", - { texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint" } - ) - vim.fn.sign_define( - "LspDiagnosticsSignInformation", - { texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation" } - ) -end -return M diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 1685c1ca..a404254b 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -102,14 +102,6 @@ function utils.check_lsp_client_active(name) return false end -function utils.is_table(t) - return type(t) == "table" -end - -function utils.is_string(t) - return type(t) == "string" -end - --- Extends a list-like table with the unique values of another list-like table. --- --- NOTE: This mutates dst! -- cgit v1.2.3