mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-26 19:37:36 +00:00
plugins: better compatability with nullable keybinds
Mostly involves filtering keybinds that are null in cases where the keybind is the attrname, and optionalString for manual lua keybind registration.
This commit is contained in:
parent
1cda8228e9
commit
f040b4a943
8 changed files with 185 additions and 155 deletions
|
|
@ -21,11 +21,11 @@
|
||||||
'';
|
'';
|
||||||
|
|
||||||
mkLuaKeymap = mode: key: action: desc: opts:
|
mkLuaKeymap = mode: key: action: desc: opts:
|
||||||
opts
|
mkIf (key != null) (opts
|
||||||
// {
|
// {
|
||||||
inherit mode key action desc;
|
inherit mode key action desc;
|
||||||
lua = true;
|
lua = true;
|
||||||
};
|
});
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
vim = {
|
vim = {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.attrsets) optionalAttrs;
|
inherit (lib.attrsets) mapAttrs' optionalAttrs;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList;
|
inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList;
|
||||||
inherit (lib.lists) map optional optionals elem;
|
inherit (lib.lists) map optional optionals elem;
|
||||||
|
|
@ -98,14 +98,17 @@ in {
|
||||||
preset = "luasnip";
|
preset = "luasnip";
|
||||||
};
|
};
|
||||||
|
|
||||||
keymap = {
|
keymap =
|
||||||
${mappings.complete} = ["show" "fallback"];
|
mapAttrs' (mapping-name: action: {
|
||||||
${mappings.close} = ["hide" "fallback"];
|
name = mappings.${mapping-name};
|
||||||
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
value = action;
|
||||||
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) {
|
||||||
${mappings.confirm} = ["accept" "fallback"];
|
complete = ["show" "fallback"];
|
||||||
|
close = ["hide" "fallback"];
|
||||||
${mappings.next} = [
|
scrollDocsUp = ["scroll_documentation_up" "fallback"];
|
||||||
|
scrollDocsDown = ["scroll_documentation_down" "fallback"];
|
||||||
|
confirm = ["accept" "fallback"];
|
||||||
|
next = [
|
||||||
"select_next"
|
"select_next"
|
||||||
"snippet_forward"
|
"snippet_forward"
|
||||||
(mkLuaInline
|
(mkLuaInline
|
||||||
|
|
@ -122,27 +125,30 @@ in {
|
||||||
'')
|
'')
|
||||||
"fallback"
|
"fallback"
|
||||||
];
|
];
|
||||||
${mappings.previous} = [
|
previous = [
|
||||||
"select_prev"
|
"select_prev"
|
||||||
"snippet_backward"
|
"snippet_backward"
|
||||||
"fallback"
|
"fallback"
|
||||||
];
|
];
|
||||||
};
|
});
|
||||||
|
|
||||||
# cmdline is not enabled by default, we're just providing keymaps in
|
# cmdline is not enabled by default, we're just providing keymaps in
|
||||||
# case the user enables them
|
# case the user enables them
|
||||||
cmdline.keymap = {
|
cmdline.keymap =
|
||||||
${mappings.complete} = ["show" "fallback"];
|
mapAttrs' (mapping-name: action: {
|
||||||
${mappings.close} = ["hide" "fallback"];
|
name = mappings.${mapping-name};
|
||||||
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
value = action;
|
||||||
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) {
|
||||||
|
complete = ["show" "fallback"];
|
||||||
|
close = ["hide" "fallback"];
|
||||||
|
scrollDocsUp = ["scroll_documentation_up" "fallback"];
|
||||||
|
scrollDocsDown = ["scroll_documentation_down" "fallback"];
|
||||||
# NOTE: mappings.confirm is skipped because our default, <CR> would
|
# NOTE: mappings.confirm is skipped because our default, <CR> would
|
||||||
# lead to accidental triggers of blink.accept instead of executing
|
# lead to accidental triggers of blink.accept instead of executing
|
||||||
# the cmd
|
# the cmd
|
||||||
|
next = ["select_next" "show" "fallback"];
|
||||||
${mappings.next} = ["select_next" "show" "fallback"];
|
previous = ["select_prev" "fallback"];
|
||||||
${mappings.previous} = ["select_prev" "fallback"];
|
});
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
|
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
|
|
@ -72,14 +73,19 @@ in {
|
||||||
formatting.format = cfg.format;
|
formatting.format = cfg.format;
|
||||||
|
|
||||||
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
|
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
|
||||||
mapping = {
|
mapping =
|
||||||
${mappings.complete} = mkLuaInline "cmp.mapping.complete()";
|
mapAttrs' (mapping-name: action: {
|
||||||
${mappings.close} = mkLuaInline "cmp.mapping.abort()";
|
name = mappings.${mapping-name};
|
||||||
${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)";
|
value = action;
|
||||||
${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)";
|
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null)
|
||||||
${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })";
|
{
|
||||||
|
complete = mkLuaInline "cmp.mapping.complete()";
|
||||||
|
close = mkLuaInline "cmp.mapping.abort()";
|
||||||
|
scrollDocsUp = mkLuaInline "cmp.mapping.scroll_docs(-4)";
|
||||||
|
scrollDocsDown = mkLuaInline "cmp.mapping.scroll_docs(4)";
|
||||||
|
confirm = mkLuaInline "cmp.mapping.confirm({ select = true })";
|
||||||
|
|
||||||
${mappings.next} = mkLuaInline ''
|
next = mkLuaInline ''
|
||||||
cmp.mapping(function(fallback)
|
cmp.mapping(function(fallback)
|
||||||
local has_words_before = function()
|
local has_words_before = function()
|
||||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
|
@ -100,7 +106,7 @@ in {
|
||||||
end)
|
end)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
${mappings.previous} = mkLuaInline ''
|
previous = mkLuaInline ''
|
||||||
cmp.mapping(function(fallback)
|
cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
|
|
@ -113,7 +119,7 @@ in {
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
'';
|
'';
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -214,13 +214,20 @@ in {
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
default_on_attach(client, bufnr)
|
default_on_attach(client, bufnr)
|
||||||
local opts = { noremap=true, silent=true, buffer = bufnr }
|
local opts = { noremap=true, silent=true, buffer = bufnr }
|
||||||
|
|
||||||
|
${optionalString config.vim.vendoredKeymaps ''
|
||||||
vim.keymap.set("n", "<localleader>rr", ":RustLsp runnables<CR>", opts)
|
vim.keymap.set("n", "<localleader>rr", ":RustLsp runnables<CR>", opts)
|
||||||
vim.keymap.set("n", "<localleader>rp", ":RustLsp parentModule<CR>", opts)
|
vim.keymap.set("n", "<localleader>rp", ":RustLsp parentModule<CR>", opts)
|
||||||
vim.keymap.set("n", "<localleader>rm", ":RustLsp expandMacro<CR>", opts)
|
vim.keymap.set("n", "<localleader>rm", ":RustLsp expandMacro<CR>", opts)
|
||||||
vim.keymap.set("n", "<localleader>rc", ":RustLsp openCargo", opts)
|
vim.keymap.set("n", "<localleader>rc", ":RustLsp openCargo", opts)
|
||||||
vim.keymap.set("n", "<localleader>rg", ":RustLsp crateGraph x11", opts)
|
vim.keymap.set("n", "<localleader>rg", ":RustLsp crateGraph x11", opts)
|
||||||
${optionalString cfg.dap.enable ''
|
''}
|
||||||
|
|
||||||
|
${optionalString (cfg.dap.enable && config.vim.vendoredKeymaps) ''
|
||||||
vim.keymap.set("n", "<localleader>rd", ":RustLsp debuggables<cr>", opts)
|
vim.keymap.set("n", "<localleader>rd", ":RustLsp debuggables<cr>", opts)
|
||||||
|
''}
|
||||||
|
|
||||||
|
${optionalString (cfg.dap.enable && config.vim.debugger.nvim-dap.mappings.continue != null) ''
|
||||||
vim.keymap.set(
|
vim.keymap.set(
|
||||||
"n", "${config.vim.debugger.nvim-dap.mappings.continue}",
|
"n", "${config.vim.debugger.nvim-dap.mappings.continue}",
|
||||||
function()
|
function()
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,9 @@ in {
|
||||||
|
|
||||||
local attach_metals_keymaps = function(client, bufnr)
|
local attach_metals_keymaps = function(client, bufnr)
|
||||||
attach_keymaps(client, bufnr) -- from lsp-setup
|
attach_keymaps(client, bufnr) -- from lsp-setup
|
||||||
|
${optionalString (cfg.lsp.extraMappings.listCommands != null) ''
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', '<cmd>lua ${listCommandsAction}<CR>', {noremap=true, silent=true, desc='Show all Metals commands'})
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', '<cmd>lua ${listCommandsAction}<CR>', {noremap=true, silent=true, desc='Show all Metals commands'})
|
||||||
|
''}
|
||||||
end
|
end
|
||||||
|
|
||||||
metals_config = require('metals').bare_config()
|
metals_config = require('metals').bare_config()
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,9 @@ in {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
${optionalString (cfg.lazygit.mappings.open != null) ''
|
||||||
vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
|
vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
|
||||||
|
''}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
|
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.lists) optionals;
|
inherit (lib.lists) optionals;
|
||||||
|
|
@ -30,46 +31,51 @@ in {
|
||||||
];
|
];
|
||||||
|
|
||||||
vim.ui.breadcrumbs.navbuddy.setupOpts = {
|
vim.ui.breadcrumbs.navbuddy.setupOpts = {
|
||||||
mappings = {
|
mappings =
|
||||||
${cfg.navbuddy.mappings.close} = mkLuaInline "actions.close()";
|
mapAttrs' (mapping-name: action: {
|
||||||
${cfg.navbuddy.mappings.nextSibling} = mkLuaInline "actions.next_sibling()";
|
name = cfg.navbuddy.mappings.${mapping-name};
|
||||||
${cfg.navbuddy.mappings.previousSibling} = mkLuaInline "actions.previous_sibling()";
|
value = action;
|
||||||
${cfg.navbuddy.mappings.parent} = mkLuaInline "actions.parent()";
|
}) (filterAttrs (mapping-name: _action: cfg.navbuddy.mappings.${mapping-name} != null)
|
||||||
${cfg.navbuddy.mappings.children} = mkLuaInline "actions.children()";
|
{
|
||||||
${cfg.navbuddy.mappings.root} = mkLuaInline "actions.root()";
|
close = mkLuaInline "actions.close()";
|
||||||
|
nextSibling = mkLuaInline "actions.next_sibling()";
|
||||||
|
previousSibling = mkLuaInline "actions.previous_sibling()";
|
||||||
|
parent = mkLuaInline "actions.parent()";
|
||||||
|
children = mkLuaInline "actions.children()";
|
||||||
|
root = mkLuaInline "actions.root()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.visualName} = mkLuaInline "actions.visual_name()";
|
visualName = mkLuaInline "actions.visual_name()";
|
||||||
${cfg.navbuddy.mappings.visualScope} = mkLuaInline "actions.visual_scope()";
|
visualScope = mkLuaInline "actions.visual_scope()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.yankName} = mkLuaInline "actions.yank_name()";
|
yankName = mkLuaInline "actions.yank_name()";
|
||||||
${cfg.navbuddy.mappings.yankScope} = mkLuaInline "actions.yank_scope()";
|
yankScope = mkLuaInline "actions.yank_scope()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.insertName} = mkLuaInline "actions.insert_name()";
|
insertName = mkLuaInline "actions.insert_name()";
|
||||||
${cfg.navbuddy.mappings.insertScope} = mkLuaInline "actions.insert_scope()";
|
insertScope = mkLuaInline "actions.insert_scope()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.appendName} = mkLuaInline "actions.append_name()";
|
appendName = mkLuaInline "actions.append_name()";
|
||||||
${cfg.navbuddy.mappings.appendScope} = mkLuaInline "actions.append_scope()";
|
appendScope = mkLuaInline "actions.append_scope()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.rename} = mkLuaInline "actions.rename()";
|
rename = mkLuaInline "actions.rename()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.delete} = mkLuaInline "actions.delete()";
|
delete = mkLuaInline "actions.delete()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.foldCreate} = mkLuaInline "actions.fold_create()";
|
foldCreate = mkLuaInline "actions.fold_create()";
|
||||||
${cfg.navbuddy.mappings.foldDelete} = mkLuaInline "actions.fold_delete()";
|
foldDelete = mkLuaInline "actions.fold_delete()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.comment} = mkLuaInline "actions.comment()";
|
comment = mkLuaInline "actions.comment()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.select} = mkLuaInline "actions.select()";
|
select = mkLuaInline "actions.select()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.moveDown} = mkLuaInline "actions.move_down()";
|
moveDown = mkLuaInline "actions.move_down()";
|
||||||
${cfg.navbuddy.mappings.moveUp} = mkLuaInline "actions.move_up()";
|
moveUp = mkLuaInline "actions.move_up()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.togglePreview} = mkLuaInline "actions.toggle_preview()";
|
togglePreview = mkLuaInline "actions.toggle_preview()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.vsplit} = mkLuaInline "actions.vsplit()";
|
vsplit = mkLuaInline "actions.vsplit()";
|
||||||
${cfg.navbuddy.mappings.hsplit} = mkLuaInline "actions.hsplit()";
|
hsplit = mkLuaInline "actions.hsplit()";
|
||||||
|
|
||||||
${cfg.navbuddy.mappings.telescope} = mkLuaInline ''
|
telescope = mkLuaInline ''
|
||||||
actions.telescope({
|
actions.telescope({
|
||||||
layout_strategy = "horizontal",
|
layout_strategy = "horizontal",
|
||||||
layout_config = {
|
layout_config = {
|
||||||
|
|
@ -79,8 +85,8 @@ in {
|
||||||
preview_width = 0.50
|
preview_width = 0.50
|
||||||
},
|
},
|
||||||
})'';
|
})'';
|
||||||
${cfg.navbuddy.mappings.help} = mkLuaInline "actions.help()";
|
help = mkLuaInline "actions.help()";
|
||||||
};
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
vim.pluginRC.breadcrumbs = entryAfter ["lspconfig"] ''
|
vim.pluginRC.breadcrumbs = entryAfter ["lspconfig"] ''
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) mkOption;
|
inherit (lib.options) literalExpression mkOption;
|
||||||
inherit (lib.types) bool str;
|
inherit (lib.types) bool str;
|
||||||
inherit (lib.nvim.types) mkPluginSetupOption;
|
inherit (lib.nvim.types) mkPluginSetupOption;
|
||||||
|
|
||||||
|
|
@ -64,7 +64,8 @@ in {
|
||||||
|
|
||||||
useVendoredKeybindings = mkOption {
|
useVendoredKeybindings = mkOption {
|
||||||
type = bool;
|
type = bool;
|
||||||
default = true;
|
default = config.vim.vendoredKeymaps;
|
||||||
|
defaultText = literalExpression "config.vim.vendoredKeymaps";
|
||||||
description = ''
|
description = ''
|
||||||
Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap
|
Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue