plugins/harpoon: fix keymaps + test

This commit is contained in:
Gaetan Lepage 2023-10-03 16:09:56 +02:00 committed by Gaétan Lepage
parent 418bf5da17
commit 73f21c063d
2 changed files with 102 additions and 23 deletions

View file

@ -10,11 +10,11 @@ with lib; let
projectConfigModule = types.submodule { projectConfigModule = types.submodule {
options = { options = {
termCommands = helpers.mkNullOrOption (types.listOf types.str) '' termCommands = helpers.mkNullOrOption (with types; listOf str) ''
List of predefined terminal commands for this project. List of predefined terminal commands for this project.
''; '';
marks = helpers.mkNullOrOption (types.listOf types.str) '' marks = helpers.mkNullOrOption (with types; listOf str) ''
List of predefined marks (filenames) for this project. List of predefined marks (filenames) for this project.
''; '';
}; };
@ -42,7 +42,7 @@ in {
Keymap for toggling the quick menu."; Keymap for toggling the quick menu.";
''; '';
navFile = helpers.mkNullOrOption (types.attrsOf types.str) '' navFile = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to marks. Keymaps for navigating to marks.
Examples: Examples:
@ -62,7 +62,7 @@ in {
Keymap for navigating to previous mark."; Keymap for navigating to previous mark.";
''; '';
gotoTerminal = helpers.mkNullOrOption (types.attrsOf types.str) '' gotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to terminals. Keymaps for navigating to terminals.
Examples: Examples:
@ -78,7 +78,7 @@ in {
Keymap for toggling the cmd quick menu. Keymap for toggling the cmd quick menu.
''; '';
tmuxGotoTerminal = helpers.mkNullOrOption (types.attrsOf types.str) '' tmuxGotoTerminal = helpers.mkNullOrOption (with types; attrsOf str) ''
Keymaps for navigating to tmux windows/panes. Keymaps for navigating to tmux windows/panes.
Attributes can either be tmux window ids or pane identifiers. Attributes can either be tmux window ids or pane identifiers.
@ -107,9 +107,11 @@ in {
Closes any tmux windows harpoon that harpoon creates when you close Neovim. Closes any tmux windows harpoon that harpoon creates when you close Neovim.
''; '';
excludedFiletypes = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "['harpoon']" '' excludedFiletypes =
Filetypes that you want to prevent from adding to the harpoon list menu. helpers.defaultNullOpts.mkNullable
''; (with types; listOf str)
''["harpoon"]''
"Filetypes that you want to prevent from adding to the harpoon list menu.";
markBranch = helpers.defaultNullOpts.mkBool false '' markBranch = helpers.defaultNullOpts.mkBool false ''
Set marks specific to each git branch inside git repository. Set marks specific to each git branch inside git repository.
@ -124,7 +126,7 @@ in {
example = '' example = ''
projects = { projects = {
"$HOME/personal/vim-with-me/server" = { "$HOME/personal/vim-with-me/server" = {
term.cmds = [ termCommands = [
"./env && npx ts-node src/index.ts" "./env && npx ts-node src/index.ts"
]; ];
}; };
@ -143,8 +145,9 @@ in {
''; '';
borderChars = borderChars =
helpers.defaultNullOpts.mkNullable (types.listOf types.str) helpers.defaultNullOpts.mkNullable
"[ \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" ]" (with types; listOf str)
''["" "" "" "" "" "" "" ""]''
"Border characters"; "Border characters";
}; };
}; };
@ -155,27 +158,41 @@ in {
( (
name: value: { name: value: {
term.cmds = value.termCommands; term.cmds = value.termCommands;
mark.marks = map (mark: {filename = mark;}) value.marks; mark.marks =
helpers.ifNonNull' value.marks
(
map
(
mark: {
filename = mark;
}
)
value.marks
);
} }
) )
cfg.projects; cfg.projects;
options = setupOptions = with cfg;
{ {
global_settings = { global_settings = {
save_on_toggle = cfg.saveOnToggle; save_on_toggle = saveOnToggle;
save_on_change = cfg.saveOnChange; save_on_change = saveOnChange;
enter_on_sendcmd = cfg.enterOnSendcmd; enter_on_sendcmd = enterOnSendcmd;
tmux_autoclose_windows = cfg.tmuxAutocloseWindows; tmux_autoclose_windows = tmuxAutocloseWindows;
excluded_filetypes = cfg.excludedFiletypes; excluded_filetypes = excludedFiletypes;
mark_branch = cfg.markBranch; mark_branch = markBranch;
}; };
inherit projects; inherit projects;
menu = { menu = {
inherit (cfg.menu) width height; inherit
borderchars = cfg.menu.borderChars; (menu)
width
height
;
borderchars = menu.borderChars;
}; };
} }
// cfg.extraOptions; // cfg.extraOptions;
@ -184,7 +201,7 @@ in {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
extraConfigLua = '' extraConfigLua = ''
require('harpoon').setup(${helpers.toLuaObject options}) require('harpoon').setup(${helpers.toLuaObject setupOptions})
''; '';
keymaps = let keymaps = let
@ -247,7 +264,7 @@ in {
(id: "function() require('harpoon.tmux').gotoTerminal(${id}) end") (id: "function() require('harpoon.tmux').gotoTerminal(${id}) end")
); );
in in
helpers.mkKeymaps helpers.keymaps.mkKeymaps
{ {
mode = "n"; mode = "n";
lua = true; lua = true;

View file

@ -0,0 +1,62 @@
{
empty = {
# Harpoon expects to access `~/.local/share/nvim/harpoon.json` which is not available in the
# test environment
tests.dontRun = true;
plugins.harpoon.enable = true;
};
example = {
# Harpoon expects to access `~/.local/share/nvim/harpoon.json` which is not available in the
# test environment
tests.dontRun = true;
plugins.harpoon = {
enable = true;
keymapsSilent = true;
keymaps = {
addFile = "<leader>a";
navFile = {
"1" = "<C-j>";
"2" = "<C-k>";
"3" = "<C-l>";
"4" = "<C-m>";
};
navNext = "<leader>b";
navPrev = "<leader>c";
gotoTerminal = {
"1" = "J";
"2" = "K";
"3" = "L";
"4" = "M";
};
cmdToggleQuickMenu = "<leader>d";
tmuxGotoTerminal = {
"1" = "<C-1>";
"2" = "<C-2>";
"{down-of}" = "<leader>g";
};
};
saveOnToggle = false;
saveOnChange = true;
enterOnSendcmd = false;
tmuxAutocloseWindows = false;
excludedFiletypes = ["harpoon"];
markBranch = false;
projects = {
"$HOME/personal/vim-with-me/server" = {
termCommands = [
"./env && npx ts-node src/index.ts"
];
};
};
menu = {
width = 60;
height = 10;
borderChars = ["" "" "" "" "" "" "" ""];
};
};
};
}