mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-21 02:55:09 +02:00
feat(lsp): make lsp buffer-mappings configurable (#1687)
This commit is contained in:
parent
76bee64f17
commit
5fe7b7ad4d
2 changed files with 39 additions and 18 deletions
|
@ -21,6 +21,23 @@ return {
|
||||||
on_attach_callback = nil,
|
on_attach_callback = nil,
|
||||||
on_init_callback = nil,
|
on_init_callback = nil,
|
||||||
automatic_servers_installation = true,
|
automatic_servers_installation = true,
|
||||||
|
buffer_mappings = {
|
||||||
|
normal_mode = {
|
||||||
|
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" },
|
||||||
|
["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>", "Goto Definition" },
|
||||||
|
["gD"] = { "<cmd>lua vim.lsp.buf.declaration()<CR>", "Goto declaration" },
|
||||||
|
["gr"] = { "<cmd>lua vim.lsp.buf.references()<CR>", "Goto references" },
|
||||||
|
["gI"] = { "<cmd>lua vim.lsp.buf.implementation()<CR>", "Goto Implementation" },
|
||||||
|
["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "show signature help" },
|
||||||
|
["gp"] = { "<cmd>lua require'lsp.peek'.Peek('definition')<CR>", "Peek definition" },
|
||||||
|
["gl"] = {
|
||||||
|
"<cmd>lua require'lsp.handlers'.show_line_diagnostics()<CR>",
|
||||||
|
"Show line diagnostics",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
insert_mode = {},
|
||||||
|
visual_mode = {},
|
||||||
|
},
|
||||||
null_ls = {
|
null_ls = {
|
||||||
setup = {},
|
setup = {},
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,25 +22,29 @@ local function lsp_highlight_document(client)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_lsp_buffer_keybindings(bufnr)
|
local function add_lsp_buffer_keybindings(bufnr)
|
||||||
local status_ok, wk = pcall(require, "which-key")
|
local mappings = {
|
||||||
if not status_ok then
|
normal_mode = "n",
|
||||||
return
|
insert_mode = "i",
|
||||||
end
|
visual_mode = "v",
|
||||||
|
|
||||||
local keys = {
|
|
||||||
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" },
|
|
||||||
["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>", "Goto Definition" },
|
|
||||||
["gD"] = { "<cmd>lua vim.lsp.buf.declaration()<CR>", "Goto declaration" },
|
|
||||||
["gr"] = { "<cmd>lua vim.lsp.buf.references()<CR>", "Goto references" },
|
|
||||||
["gI"] = { "<cmd>lua vim.lsp.buf.implementation()<CR>", "Goto Implementation" },
|
|
||||||
["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "show signature help" },
|
|
||||||
["gp"] = { "<cmd>lua require'lsp.peek'.Peek('definition')<CR>", "Peek definition" },
|
|
||||||
["gl"] = {
|
|
||||||
"<cmd>lua require'lsp.handlers'.show_line_diagnostics()<CR>",
|
|
||||||
"Show line diagnostics",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
wk.register(keys, { mode = "n", buffer = bufnr })
|
|
||||||
|
if lvim.builtin.which_key.active then
|
||||||
|
-- Remap using which_key
|
||||||
|
local status_ok, wk = pcall(require, "which-key")
|
||||||
|
if not status_ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for mode_name, mode_char in pairs(mappings) do
|
||||||
|
wk.register(lvim.lsp.buffer_mappings[mode_name], { mode = mode_char, buffer = bufnr })
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Remap using nvim api
|
||||||
|
for mode_name, mode_char in pairs(mappings) do
|
||||||
|
for key, remap in pairs(lvim.lsp.buffer_mappings[mode_name]) do
|
||||||
|
vim.api.nvim_buf_set_keymap(bufnr, mode_char, key, remap[1], { noremap = true, silent = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.common_capabilities()
|
function M.common_capabilities()
|
||||||
|
|
Loading…
Reference in a new issue