mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/todo-comments: migrate keymaps to mkMapOptionSubmodule
This commit is contained in:
parent
39081a4106
commit
cb413995e1
1 changed files with 39 additions and 40 deletions
|
@ -9,18 +9,12 @@ let
|
||||||
inherit (lib.nixvim)
|
inherit (lib.nixvim)
|
||||||
defaultNullOpts
|
defaultNullOpts
|
||||||
keymaps
|
keymaps
|
||||||
|
mkNullOrOption'
|
||||||
mkPackageOption
|
mkPackageOption
|
||||||
mkCompositeOption
|
|
||||||
transitionType
|
transitionType
|
||||||
;
|
;
|
||||||
types = lib.nixvim.nixvimTypes;
|
types = lib.nixvim.nixvimTypes;
|
||||||
|
|
||||||
keymapsActions = {
|
|
||||||
todoQuickFix = "TodoQuickFix";
|
|
||||||
todoLocList = "TodoLocList";
|
|
||||||
todoTrouble = "TodoTrouble";
|
|
||||||
todoTelescope = "TodoTelescope";
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
||||||
name = "todo-comments";
|
name = "todo-comments";
|
||||||
|
@ -372,37 +366,44 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
||||||
|
|
||||||
extraOptions = {
|
extraOptions = {
|
||||||
keymaps =
|
keymaps =
|
||||||
let
|
mapAttrs
|
||||||
mkKeymapOption =
|
(
|
||||||
optionName: funcName:
|
optionName: action:
|
||||||
mkCompositeOption "Keymap settings for the `:${funcName}` function." {
|
mkNullOrOption' {
|
||||||
key = mkOption {
|
type = keymaps.mkMapOptionSubmodule {
|
||||||
type = types.str;
|
defaults = {
|
||||||
default = null;
|
inherit action;
|
||||||
description = "Key for the `${funcName}` function.";
|
mode = "n";
|
||||||
};
|
};
|
||||||
|
|
||||||
cwd = mkOption {
|
extraOptions = {
|
||||||
type = types.nullOr types.str;
|
cwd = mkOption {
|
||||||
description = "Specify the directory to search for comments";
|
type = types.nullOr types.str;
|
||||||
default = null;
|
description = "Specify the directory to search for comments";
|
||||||
example = "~/projects/foobar";
|
default = null;
|
||||||
};
|
example = "~/projects/foobar";
|
||||||
|
};
|
||||||
|
|
||||||
keywords = mkOption {
|
keywords = mkOption {
|
||||||
type = with types; transitionType str (splitString ",") (nullOr (listOf str));
|
type = with types; transitionType str (splitString ",") (nullOr (listOf str));
|
||||||
description = ''
|
description = ''
|
||||||
Comma separated list of keywords to filter results by.
|
Comma separated list of keywords to filter results by.
|
||||||
Keywords are case-sensitive.
|
Keywords are case-sensitive.
|
||||||
'';
|
'';
|
||||||
default = null;
|
default = null;
|
||||||
example = "TODO,FIX";
|
example = "TODO,FIX";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
description = "Keymap for function ${action}";
|
||||||
options = keymaps.mapConfigOptions;
|
}
|
||||||
};
|
)
|
||||||
in
|
{
|
||||||
mapAttrs mkKeymapOption keymapsActions;
|
todoQuickFix = "TodoQuickFix";
|
||||||
|
todoLocList = "TodoLocList";
|
||||||
|
todoTrouble = "TodoTrouble";
|
||||||
|
todoTelescope = "TodoTelescope";
|
||||||
|
};
|
||||||
|
|
||||||
ripgrepPackage = mkPackageOption {
|
ripgrepPackage = mkPackageOption {
|
||||||
name = "ripgrep";
|
name = "ripgrep";
|
||||||
|
@ -431,20 +432,18 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin config {
|
||||||
extraPackages = [ cfg.ripgrepPackage ];
|
extraPackages = [ cfg.ripgrepPackage ];
|
||||||
|
|
||||||
keymaps = lib.pipe cfg.keymaps [
|
keymaps = lib.pipe cfg.keymaps [
|
||||||
(filterAttrs (n: v: v != null))
|
(filterAttrs (n: keymap: keymap != null))
|
||||||
(mapAttrsToList (
|
(mapAttrsToList (
|
||||||
name: keymap: {
|
name: keymap: {
|
||||||
inherit (keymap) key options;
|
inherit (keymap) key mode options;
|
||||||
mode = "n";
|
|
||||||
action =
|
action =
|
||||||
let
|
let
|
||||||
cmd = keymapsActions.${name};
|
|
||||||
cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
|
cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
|
||||||
keywords = optionalString (
|
keywords = optionalString (
|
||||||
keymap.keywords != null && keymap.keywords != [ ]
|
keymap.keywords != null && keymap.keywords != [ ]
|
||||||
) " keywords=${concatStringsSep "," keymap.keywords}";
|
) " keywords=${concatStringsSep "," keymap.keywords}";
|
||||||
in
|
in
|
||||||
"<cmd>${cmd}${cwd}${keywords}<cr>";
|
"<cmd>${keymap.action}${cwd}${keywords}<cr>";
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue