Skip to content

Commit

Permalink
plugins/todo-comments: migrate keymaps to mkMapOptionSubmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Aug 20, 2024
1 parent 39081a4 commit cb41399
Showing 1 changed file with 41 additions and 42 deletions.
83 changes: 41 additions & 42 deletions plugins/utils/todo-comments.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ let
inherit (lib.nixvim)
defaultNullOpts
keymaps
mkNullOrOption'
mkPackageOption
mkCompositeOption
transitionType
;
types = lib.nixvim.nixvimTypes;

keymapsActions = {
todoQuickFix = "TodoQuickFix";
todoLocList = "TodoLocList";
todoTrouble = "TodoTrouble";
todoTelescope = "TodoTelescope";
};
in
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
name = "todo-comments";
Expand Down Expand Up @@ -372,37 +366,44 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config {

extraOptions = {
keymaps =
let
mkKeymapOption =
optionName: funcName:
mkCompositeOption "Keymap settings for the `:${funcName}` function." {
key = mkOption {
type = types.str;
default = null;
description = "Key for the `${funcName}` function.";
};

cwd = mkOption {
type = types.nullOr types.str;
description = "Specify the directory to search for comments";
default = null;
example = "~/projects/foobar";
};

keywords = mkOption {
type = with types; transitionType str (splitString ",") (nullOr (listOf str));
description = ''
Comma separated list of keywords to filter results by.
Keywords are case-sensitive.
'';
default = null;
example = "TODO,FIX";
mapAttrs
(
optionName: action:
mkNullOrOption' {
type = keymaps.mkMapOptionSubmodule {
defaults = {
inherit action;
mode = "n";
};

extraOptions = {
cwd = mkOption {
type = types.nullOr types.str;
description = "Specify the directory to search for comments";
default = null;
example = "~/projects/foobar";
};

keywords = mkOption {
type = with types; transitionType str (splitString ",") (nullOr (listOf str));
description = ''
Comma separated list of keywords to filter results by.
Keywords are case-sensitive.
'';
default = null;
example = "TODO,FIX";
};
};
};

options = keymaps.mapConfigOptions;
};
in
mapAttrs mkKeymapOption keymapsActions;
description = "Keymap for function ${action}";
}
)
{
todoQuickFix = "TodoQuickFix";
todoLocList = "TodoLocList";
todoTrouble = "TodoTrouble";
todoTelescope = "TodoTelescope";
};

ripgrepPackage = mkPackageOption {
name = "ripgrep";
Expand Down Expand Up @@ -431,20 +432,18 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config {
extraPackages = [ cfg.ripgrepPackage ];

keymaps = lib.pipe cfg.keymaps [
(filterAttrs (n: v: v != null))
(filterAttrs (n: keymap: keymap != null))
(mapAttrsToList (
name: keymap: {
inherit (keymap) key options;
mode = "n";
inherit (keymap) key mode options;
action =
let
cmd = keymapsActions.${name};
cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
keywords = optionalString (
keymap.keywords != null && keymap.keywords != [ ]
) " keywords=${concatStringsSep "," keymap.keywords}";
in
"<cmd>${cmd}${cwd}${keywords}<cr>";
"<cmd>${keymap.action}${cwd}${keywords}<cr>";
}
))
];
Expand Down

0 comments on commit cb41399

Please sign in to comment.