mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-28 13:58:27 +02:00
[Feature] Expose lsp config (#1156)
This commit is contained in:
parent
cf16a2e826
commit
fe5daa722f
8 changed files with 72 additions and 112 deletions
|
@ -34,19 +34,55 @@ lvim = {
|
||||||
},
|
},
|
||||||
|
|
||||||
lsp = {
|
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 = {
|
diagnostics = {
|
||||||
|
signs = {
|
||||||
|
active = true,
|
||||||
|
values = {
|
||||||
|
{ name = "LspDiagnosticsSignError", text = "" },
|
||||||
|
{ name = "LspDiagnosticsSignWarning", text = "" },
|
||||||
|
{ name = "LspDiagnosticsSignHint", text = "" },
|
||||||
|
{ name = "LspDiagnosticsSignInformation", text = "" },
|
||||||
|
},
|
||||||
|
},
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
prefix = "",
|
prefix = "",
|
||||||
spacing = 0,
|
spacing = 0,
|
||||||
},
|
},
|
||||||
signs = true,
|
|
||||||
underline = true,
|
underline = true,
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
},
|
},
|
||||||
override = {},
|
override = {},
|
||||||
document_highlight = true,
|
document_highlight = true,
|
||||||
popup_border = "single",
|
popup_border = "single",
|
||||||
default_keybinds = true,
|
|
||||||
on_attach_callback = nil,
|
on_attach_callback = nil,
|
||||||
on_init_callback = nil,
|
on_init_callback = nil,
|
||||||
},
|
},
|
||||||
|
@ -60,9 +96,10 @@ lvim = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local schemas = nil
|
local schemas = nil
|
||||||
local common_on_attach = require("lsp").common_on_attach
|
local lsp = require "lsp"
|
||||||
local common_capabilities = require("lsp").common_capabilities()
|
local common_on_attach = lsp.common_on_attach
|
||||||
local common_on_init = require("lsp").common_on_init
|
local common_capabilities = lsp.common_capabilities()
|
||||||
|
local common_on_init = lsp.common_on_init
|
||||||
local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
|
local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
|
||||||
if status_ok then
|
if status_ok then
|
||||||
schemas = jsonls_settings.get_default_schemas()
|
schemas = jsonls_settings.get_default_schemas()
|
||||||
|
|
|
@ -49,6 +49,18 @@ local keymaps = {
|
||||||
{ "<C-q>", ":call QuickFixToggle()<CR>" },
|
{ "<C-q>", ":call QuickFixToggle()<CR>" },
|
||||||
|
|
||||||
-- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
|
-- {'<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 = {
|
term_mode = {
|
||||||
|
|
|
@ -5,7 +5,7 @@ local M = {}
|
||||||
function M.setup()
|
function M.setup()
|
||||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||||
virtual_text = lvim.lsp.diagnostics.virtual_text,
|
virtual_text = lvim.lsp.diagnostics.virtual_text,
|
||||||
signs = lvim.lsp.diagnostics.signs,
|
signs = lvim.lsp.diagnostics.signs.active,
|
||||||
underline = lvim.lsp.document_highlight,
|
underline = lvim.lsp.document_highlight,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
local u = require "utils"
|
local u = require "utils"
|
||||||
|
|
||||||
function M.config()
|
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.handlers").setup()
|
||||||
require("lsp.signs").setup()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lsp_highlight_document(client)
|
local function lsp_highlight_document(client)
|
||||||
|
@ -28,16 +33,6 @@ local function lsp_highlight_document(client)
|
||||||
end
|
end
|
||||||
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()
|
function M.common_capabilities()
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
|
@ -56,7 +51,12 @@ function M.common_on_init(client, bufnr)
|
||||||
lvim.lsp.on_init_callback(client, bufnr)
|
lvim.lsp.on_init_callback(client, bufnr)
|
||||||
return
|
return
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function M.common_on_attach(client, bufnr)
|
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)
|
lvim.lsp.on_attach_callback(client, bufnr)
|
||||||
end
|
end
|
||||||
lsp_highlight_document(client)
|
lsp_highlight_document(client)
|
||||||
require("lsp.keybinds").setup()
|
|
||||||
require("lsp.null-ls").setup(vim.bo.filetype)
|
require("lsp.null-ls").setup(vim.bo.filetype)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(lang)
|
function M.setup(lang)
|
||||||
local lang_server = lvim.lang[lang].lsp
|
local lsp = lvim.lang[lang].lsp
|
||||||
local provider = lang_server.provider
|
if require("utils").check_lsp_client_active(lsp.provider) then
|
||||||
if require("utils").check_lsp_client_active(provider) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
require("lspconfig")[provider].setup(lang_server.setup)
|
local lspconfig = require "lspconfig"
|
||||||
|
lspconfig[lsp.provider].setup(lsp.setup)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -102,14 +102,6 @@ function utils.check_lsp_client_active(name)
|
||||||
return false
|
return false
|
||||||
end
|
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.
|
--- Extends a list-like table with the unique values of another list-like table.
|
||||||
---
|
---
|
||||||
--- NOTE: This mutates dst!
|
--- NOTE: This mutates dst!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue