LSP: Register keymaps on LspAttach

This commit is contained in:
Daniel 2024-03-25 21:39:21 +00:00 committed by Gaétan Lepage
parent 7baefc8aa5
commit 03009d0b99
2 changed files with 82 additions and 27 deletions

View file

@ -134,6 +134,35 @@ in {
};
default = {};
};
extra = mkOption {
type = with types; listOf helpers.keymaps.mapOptionSubmodule;
description = "Extra keymaps to register on 'LspAttach'.";
example = [
{
key = "<leader>lx";
action = "<CMD>LspStop<Enter>";
}
{
key = "<leader>ls";
action = "<CMD>LspStart<Enter>";
}
{
key = "<leader>lr";
action = "<CMD>LspRestart<Enter>";
}
{
key = "gd";
action = "require('telescope.builtin').lsp_definitions()";
lua = true;
}
{
key = "K";
action = "<CMD>Lspsaga hover_doc<Enter>";
}
];
default = [];
};
};
enabledServers = mkOption {
@ -231,7 +260,8 @@ in {
mkIf cfg.enable {
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
keymaps = let
keymapsOnEvents = {
"LspAttach" = let
mkMaps = prefix:
mapAttrsToList
(
@ -258,7 +288,9 @@ in {
);
in
(mkMaps "vim.diagnostic." cfg.keymaps.diagnostic)
++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf);
++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf)
++ cfg.keymaps.extra;
};
# Enable all LSP servers
extraConfigLua = ''

View file

@ -27,6 +27,29 @@
desc = "Hover";
};
};
extra = [
{
key = "<leader>li";
action = "<CMD>LspInfo<Enter>";
}
{
key = "<leader>lx";
action = "<CMD>LspStop<Enter>";
}
{
key = "<leader>ls";
action = "<CMD>LspStart<Enter>";
}
{
key = "<leader>lr";
action = "<CMD>LspRestart<Enter>";
}
{
key = "<leader>ll";
action = "<CMD>LspLog<Enter>";
}
];
};
servers = {