[Feature] Expose lsp config (#1156)

This commit is contained in:
Luc Sinet 2021-07-31 16:12:29 +02:00 committed by GitHub
parent cf16a2e826
commit fe5daa722f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 112 deletions

View file

@ -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()

View file

@ -49,6 +49,18 @@ local keymaps = {
{ "<C-q>", ":call QuickFixToggle()<CR>" },
-- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
-- LSP
{ "gd", "<cmd>lua vim.lsp.buf.definition()<CR>" },
{ "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>" },
{ "gr", "<cmd>lua vim.lsp.buf.references()<CR>" },
{ "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>" },
{ "gl", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })<CR>" },
{ "gp", "<cmd>lua require'lsp.peek'.Peek('definition')<CR>" },
{ "K", "<cmd>lua vim.lsp.buf.hover()<CR>" },
{ "<C-p>", "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
{ "<C-n>", "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
-- { "<tab>", "<cmd>lua vim.lsp.buf.signature_help()<CR>" },
},
term_mode = {

View file

@ -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,
})

View file

@ -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

View file

@ -1,27 +0,0 @@
local M = {}
function M.setup()
if lvim.lsp.default_keybinds then
vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>"
vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>"
vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>"
vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>"
vim.api.nvim_set_keymap(
"n",
"gl",
'<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })<CR>',
{ noremap = true, silent = true }
)
vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp.peek'.Peek('definition')<CR>"
vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>"
vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
-- vim.cmd "nnoremap <silent> gs <cmd>lua vim.lsp.buf.signature_help()<CR>"
-- 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

View file

@ -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

View file

@ -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

View file

@ -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!