mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
modules/lsp/keymaps: init
Initial LSP keymaps option, inspired by `keymapsOnEvent` and `plugins.lsp.keymaps`. Users can define `lspBufAction` instead of `action` if they wish to use a `vim.lsp.buf.<action>` callback.
This commit is contained in:
parent
90eb4e681c
commit
552dec0e55
2 changed files with 127 additions and 0 deletions
|
@ -137,6 +137,10 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
./keymaps.nix
|
||||||
|
];
|
||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
enabledServers = lib.pipe cfg.servers [
|
enabledServers = lib.pipe cfg.servers [
|
||||||
|
|
123
modules/lsp/keymaps.nix
Normal file
123
modules/lsp/keymaps.nix
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
{ lib, config, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) types;
|
||||||
|
inherit (lib.nixvim.keymaps) mkMapOptionSubmodule;
|
||||||
|
|
||||||
|
cfg = config.lsp;
|
||||||
|
|
||||||
|
# An extra module to include in the keymap option submodule
|
||||||
|
# Declares and implements a specialised `lspBufAction` option
|
||||||
|
extraKeymapModule =
|
||||||
|
{ config, options, ... }:
|
||||||
|
{
|
||||||
|
options.lspBufAction = lib.mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
description = ''
|
||||||
|
LSP buffer action to use for `action`.
|
||||||
|
|
||||||
|
If non-null, the keymap's `action` will be defined as `vim.lsp.buf.<action>`.
|
||||||
|
|
||||||
|
See [`:h lsp-buf`](https://neovim.io/doc/user/lsp.html#lsp-buf)
|
||||||
|
'';
|
||||||
|
default = null;
|
||||||
|
example = "hover";
|
||||||
|
};
|
||||||
|
|
||||||
|
config.action = lib.mkIf (config.lspBufAction != null) (
|
||||||
|
lib.mkDerivedConfig options.lspBufAction (
|
||||||
|
action: lib.nixvim.mkRaw "vim.lsp.buf[${lib.nixvim.toLuaObject action}]"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.lsp = {
|
||||||
|
keymaps = lib.mkOption {
|
||||||
|
type = types.listOf (mkMapOptionSubmodule {
|
||||||
|
action.example = "<CMD>LspRestart<Enter>";
|
||||||
|
extraModules = [ extraKeymapModule ];
|
||||||
|
});
|
||||||
|
description = ''
|
||||||
|
Keymaps to register when a language server is attached.
|
||||||
|
'';
|
||||||
|
default = [ ];
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
key = "gd";
|
||||||
|
lspBufAction = "definition";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "gD";
|
||||||
|
lspBufAction = "references";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "gt";
|
||||||
|
lspBufAction = "type_definition";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "gi";
|
||||||
|
lspBufAction = "implementation";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "K";
|
||||||
|
lspBufAction = "hover";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
key = "<leader>k";
|
||||||
|
action = lib.nixvim.nestedLiteralLua "function() vim.diagnostic.jump({ count=-1, float=true }) end";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "<leader>j";
|
||||||
|
action = lib.nixvim.nestedLiteralLua "function() vim.diagnostic.jump({ count=1, float=true }) end";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "<leader>lx";
|
||||||
|
action = "<CMD>LspStop<Enter>";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "<leader>ls";
|
||||||
|
action = "<CMD>LspStart<Enter>";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "<leader>lr";
|
||||||
|
action = "<CMD>LspRestart<Enter>";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "gd";
|
||||||
|
action = lib.nixvim.nestedLiteralLua "require('telescope.builtin').lsp_definitions";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
key = "K";
|
||||||
|
action = "<CMD>Lspsaga hover_doc<Enter>";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf (cfg.keymaps != [ ]) {
|
||||||
|
autoGroups.nixvim_lsp_binds.clear = false;
|
||||||
|
|
||||||
|
autoCmd = [
|
||||||
|
{
|
||||||
|
event = "LspAttach";
|
||||||
|
group = "nixvim_lsp_binds";
|
||||||
|
callback = lib.nixvim.mkRaw ''
|
||||||
|
function(args)
|
||||||
|
${lib.concatMapStringsSep "\n" (
|
||||||
|
keymap:
|
||||||
|
# lua
|
||||||
|
''
|
||||||
|
do
|
||||||
|
local map = ${lib.nixvim.toLuaObject keymap}
|
||||||
|
local options = vim.tbl_extend("keep", map.options or {}, { buffer = args.buf })
|
||||||
|
vim.keymap.set(map.mode, map.key, map.action, options)
|
||||||
|
end
|
||||||
|
'') cfg.keymaps}
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
desc = "Load LSP keymaps";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue