plugins/todo-comments: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2024-08-16 22:14:24 -05:00
parent 78fc4be6a8
commit 379ae77a76
No known key found for this signature in database
2 changed files with 551 additions and 371 deletions

View file

@ -1,22 +1,35 @@
{ {
lib, lib,
helpers,
config, config,
pkgs, pkgs,
... ...
}: }:
with lib; with lib;
let let
cfg = config.plugins.todo-comments; inherit (lib.nixvim)
defaultNullOpts
keymaps
mkPackageOption
mkCompositeOption
transitionType
;
types = lib.nixvim.nixvimTypes;
commands = { keymapsActions = {
todoQuickFix = "TodoQuickFix"; todoQuickFix = "TodoQuickFix";
todoLocList = "TodoLocList"; todoLocList = "TodoLocList";
todoTrouble = "TodoTrouble"; todoTrouble = "TodoTrouble";
todoTelescope = "TodoTelescope"; todoTelescope = "TodoTelescope";
}; };
in in
{ lib.nixvim.neovim-plugin.mkNeovimPlugin config {
name = "todo-comments";
originalName = "todo-comments.nvim";
defaultPackage = pkgs.vimPlugins.todo-comments-nvim;
maintainers = [ lib.maintainers.khaneliman ];
# TODO: Added 2023-11-06, remove after 24.11
imports = [ imports = [
(mkRemovedOptionModule [ (mkRemovedOptionModule [
"plugins" "plugins"
@ -24,267 +37,416 @@ in
"keymapsSilent" "keymapsSilent"
] "Use `plugins.todo-comments.keymaps.<COMMAND>.options.silent`.") ] "Use `plugins.todo-comments.keymaps.<COMMAND>.options.silent`.")
]; ];
options = {
plugins.todo-comments = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "todo-comments";
package = helpers.mkPluginPackageOption "todo-comments" pkgs.vimPlugins.todo-comments-nvim; # TODO: Added 2024-08-16, remove after 24.11
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"signs"
"signPriority"
"keywords"
[
"guiStyle"
"bg"
]
[
"guiStyle"
"fg"
]
"mergeKeywords"
[
"highlight"
"multiline"
]
[
"highlight"
"multilinePattern"
]
[
"highlight"
"multilineContext"
]
[
"highlight"
"before"
]
[
"highlight"
"keyword"
]
[
"highlight"
"after"
]
[
"highlight"
"pattern"
]
[
"highlight"
"commentsOnly"
]
[
"highlight"
"maxLineLen"
]
[
"highlight"
"exclude"
]
[
"colors"
"error"
]
[
"colors"
"warning"
]
[
"colors"
"info"
]
[
"colors"
"hint"
]
[
"colors"
"default"
]
[
"colors"
"test"
]
[
"search"
"command"
]
[
"search"
"args"
]
[
"search"
"pattern"
]
];
ripgrepPackage = helpers.mkPackageOption { settingsOptions = {
default = pkgs.ripgrep; signs = defaultNullOpts.mkBool true "Show icons in the signs column.";
description = "Which package (if any) to be added for file search support in todo-comments.";
};
signs = helpers.defaultNullOpts.mkBool true "Show icons in the signs column."; sign_priority = defaultNullOpts.mkInt 8 "Sign priority.";
signPriority = helpers.defaultNullOpts.mkInt 8 "Sign priority."; keywords =
defaultNullOpts.mkAttrsOf
(
with types;
submodule {
freeformType = attrsOf anything;
options = {
icon = defaultNullOpts.mkStr null ''
Icon used for the sign, and in search results.
'';
keywords = color = defaultNullOpts.mkStr null ''
helpers.mkNullOrOption Can be a hex color, or a named color.
(types.attrsOf ( '';
types.submodule {
options = {
icon = helpers.mkNullOrOption types.str ''
Icon used for the sign, and in search results.
'';
color = helpers.mkNullOrOption types.str '' alt = defaultNullOpts.mkListOf types.str null ''
Can be a hex color, or a named color. A set of other keywords that all map to this FIX keywords.
''; '';
alt = helpers.mkNullOrOption (types.listOf types.str) '' signs = defaultNullOpts.mkBool null ''
A set of other keywords that all map to this FIX keywords. Configure signs for some keywords individually.
''; '';
signs = helpers.mkNullOrOption types.bool ''
Configure signs for some keywords individually.
'';
};
}
))
''
Configurations for keywords to be recognized as todo comments.
Default:
```nix
{
FIX = {
icon = " "; # Icon used for the sign, and in search results.
color = "error"; # Can be a hex color, or a named color.
alt = [ "FIXME" "BUG" "FIXIT" "ISSUE" ]; # A set of other keywords that all map to this FIX keywords.
};
TODO = { icon = " "; color = "info"; };
HACK = { icon = " "; color = "warning"; };
WARN = { icon = " "; color = "warning"; alt = [ "WARNING" "XXX" ]; };
PERF = { icon = " "; alt = [ "OPTIM" "PERFORMANCE" "OPTIMIZE" ]; };
NOTE = { icon = " "; color = "hint"; alt = [ "INFO" ]; };
TEST = { icon = " "; color = "test"; alt = [ "TESTING" "PASSED" "FAILED" ]; };
}; };
``` }
)
{
FIX = {
icon = " ";
color = "error";
alt = [
"FIXME"
"BUG"
"FIXIT"
"ISSUE"
];
};
TODO = {
icon = " ";
color = "info";
};
HACK = {
icon = " ";
color = "warning";
};
WARN = {
icon = " ";
color = "warning";
alt = [
"WARNING"
"XXX"
];
};
PERF = {
icon = " ";
alt = [
"OPTIM"
"PERFORMANCE"
"OPTIMIZE"
];
};
NOTE = {
icon = " ";
color = "hint";
alt = [ "INFO" ];
};
TEST = {
icon = " ";
color = "test";
alt = [
"TESTING"
"PASSED"
"FAILED"
];
};
}
''
Configurations for keywords to be recognized as todo comments.
'';
gui_style = {
fg = defaultNullOpts.mkStr "NONE" ''
The gui style to use for the fg highlight group.
'';
bg = defaultNullOpts.mkStr "BOLD" ''
The gui style to use for the bg highlight group.
'';
};
merge_keywords = defaultNullOpts.mkBool true ''
When true, custom keywords will be merged with the default.
'';
highlight = {
multiline = defaultNullOpts.mkBool true ''
Enable multiline todo comments.
'';
multiline_pattern = defaultNullOpts.mkStr "^." ''
Lua pattern to match the next multiline from the start of the
matched keyword.
'';
multiline_context = defaultNullOpts.mkInt 10 ''
Extra lines that will be re-evaluated when changing a line.
'';
before =
defaultNullOpts.mkEnumFirstDefault
[
""
"fg"
"bg"
]
''
Whether to apply the before highlight to the foreground or background.
''; '';
guiStyle = { keyword =
fg = helpers.defaultNullOpts.mkStr "NONE" '' defaultNullOpts.mkEnumFirstDefault
The gui style to use for the fg highlight group. [
''; "wide"
"fg"
"bg"
"wide_bg"
"wide_fg"
""
]
''
How highlighting is applied to the keyword.
bg = helpers.defaultNullOpts.mkStr "BOLD" '' `wide` and `wide_bg` are the same as `bg`, but will also highlight
The gui style to use for the bg highlight group. surrounding characters, `wide_fg` acts accordingly but with `fg`.
'';
after =
defaultNullOpts.mkEnumFirstDefault
[
"fg"
"bg"
""
]
''
Whether to apply the after highlight to the foreground or background.
'';
pattern = defaultNullOpts.mkNullable' {
type = with types; either str (listOf str);
pluginDefault = ".*<(KEYWORDS)\\s*:";
description = ''
Pattern or list of patterns, used for highlighting (vim regex).
''; '';
}; };
mergeKeywords = helpers.defaultNullOpts.mkBool true '' comments_only = defaultNullOpts.mkBool true ''
When true, custom keywords will be merged with the default Uses treesitter to match keywords in comments only.
''; '';
highlight = { max_line_len = defaultNullOpts.mkInt 400 ''
multiline = helpers.defaultNullOpts.mkBool true '' Ignore lines longer than this.
Enable multiline todo comments. '';
'';
multilinePattern = helpers.defaultNullOpts.mkStr "^." '' exclude = defaultNullOpts.mkListOf types.str [ ] ''
Lua pattern to match the next multiline from the start of the List of file types to exclude highlighting.
matched keyword. '';
''; };
multilineContext = helpers.defaultNullOpts.mkInt 10 '' colors =
Extra lines that will be re-evaluated when changing a line. defaultNullOpts.mkAttrsOf (types.listOf types.str)
'';
before = helpers.defaultNullOpts.mkStr "" ''
"fg" or "bg" or empty.
'';
keyword = helpers.defaultNullOpts.mkStr "wide" ''
"fg", "bg", "wide", "wide_bg", "wide_fg" or empty.
(wide and wide_bg is the same as bg, but will also highlight
surrounding characters, wide_fg acts accordingly but with fg).
'';
after = helpers.defaultNullOpts.mkStr "fg" ''
"fg" or "bg" or empty.
'';
pattern =
helpers.defaultNullOpts.mkNullable (with types; either str (listOf str)) ".*<(KEYWORDS)\\s*:"
''
Pattern or list of patterns, used for highlighting (vim regex)
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
'';
commentsOnly = helpers.defaultNullOpts.mkBool true ''
Uses treesitter to match keywords in comments only.
'';
maxLineLen = helpers.defaultNullOpts.mkInt 400 ''
Ignore lines longer than this.
'';
exclude = helpers.mkNullOrOption (types.listOf types.str) ''
List of file types to exclude highlighting.
'';
};
colors = helpers.mkNullOrOption (types.attrsOf (types.listOf types.str)) ''
List of named colors where we try to extract the guifg from the list
of highlight groups or use the hex color if hl not found as a fallback.
Default:
```nix
{ {
error = [ "DiagnosticError" "ErrorMsg" "#DC2626" ]; error = [
warning = [ "DiagnosticWarn" "WarningMsg" "#FBBF24" ]; "DiagnosticError"
info = [ "DiagnosticInfo" "#2563EB" ]; "ErrorMsg"
hint = [ "DiagnosticHint" "#10B981" ]; "#DC2626"
default = [ "Identifier" "#7C3AED" ]; ];
test = [ "Identifier" "#FF00FF" ]; warning = [
}; "DiagnosticWarn"
``` "WarningMsg"
''; "#FBBF24"
];
info = [
"DiagnosticInfo"
"#2563EB"
];
hint = [
"DiagnosticHint"
"#10B981"
];
default = [
"Identifier"
"#7C3AED"
];
test = [
"Identifier"
"#FF00FF"
];
}
''
List of named colors where we try to extract the guifg from the list
of highlight groups or use the hex color if hl not found as a fallback.
'';
search = { search = {
command = helpers.defaultNullOpts.mkStr "rg" "Command to use for searching for keywords."; command = defaultNullOpts.mkStr "rg" "Command to use for searching for keywords.";
args = helpers.mkNullOrOption (types.listOf types.str) '' args =
Arguments to use for the search command in list form. defaultNullOpts.mkListOf types.str
Default:
```nix
[ [
"--color=never" "--color=never"
"--no-heading" "--no-heading"
"--with-filename" "--with-filename"
"--line-number" "--line-number"
"--column" "--column"
]; ]
``` ''
''; Arguments to use for the search command in list form.
'';
pattern = helpers.defaultNullOpts.mkStr "\\b(KEYWORDS):" '' pattern = defaultNullOpts.mkStr "\\b(KEYWORDS):" ''
Regex that will be used to match keywords. Regex that will be used to match keywords.
Don't replace the (KEYWORDS) placeholder. Don't replace the (KEYWORDS) placeholder.
'';
Note: the provided pattern will be embedded as such: `[[PATTERN]]`.
'';
};
keymaps =
let
mkKeymapOption =
optionName: funcName:
helpers.mkCompositeOption "Keymap settings for the `:${funcName}` function." {
key = mkOption {
type = types.str;
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 = types.nullOr types.str;
description = ''
Comma separated list of keywords to filter results by.
Keywords are case-sensitive.
'';
default = null;
example = "TODO,FIX";
};
options = helpers.keymaps.mapConfigOptions;
};
in
mapAttrs mkKeymapOption commands;
}; };
}; };
config = settingsExample = {
let highlight = {
setupOptions = { pattern = [
inherit (cfg) signs; ".*<(KEYWORDS)\s*:"
sign_priority = cfg.signPriority; ".*<(KEYWORDS)\s*"
inherit (cfg) keywords;
gui_style = cfg.guiStyle;
merge_keywords = cfg.mergeKeywords;
highlight = {
inherit (cfg.highlight)
multiline
before
keyword
after
exclude
;
pattern = helpers.ifNonNull' cfg.highlight.pattern (helpers.mkRaw "[[${cfg.highlight.pattern}]]");
multiline_pattern = cfg.highlight.multilinePattern;
multiline_context = cfg.highlight.multilineContext;
comments_only = cfg.highlight.commentsOnly;
max_line_len = cfg.highlight.maxLineLen;
};
inherit (cfg) colors;
search = {
inherit (cfg.search) command args;
pattern = helpers.ifNonNull' cfg.search.pattern (
if isList cfg.search.pattern then
(map helpers.mkRaw cfg.search.pattern)
else
helpers.mkRaw "[[${cfg.search.pattern}]]"
);
};
} // cfg.extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraPackages = [ cfg.ripgrepPackage ];
extraConfigLua = ''
require("todo-comments").setup${helpers.toLuaObject setupOptions}
'';
keymaps = flatten (
mapAttrsToList (
optionName: funcName:
let
keymap = cfg.keymaps.${optionName};
cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}";
in
optional (keymap != null) {
mode = "n";
inherit (keymap) key options;
action = ":${funcName}${cwd}${keywords}<CR>";
}
) commands
);
# Automatically enable plugins if keymaps have been set
plugins = mkMerge [
(mkIf (cfg.keymaps.todoTrouble != null) { trouble.enable = true; })
(mkIf (cfg.keymaps.todoTelescope != null) { telescope.enable = true; })
]; ];
}; };
};
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";
};
options = keymaps.mapConfigOptions;
};
in
mapAttrs mkKeymapOption keymapsActions;
ripgrepPackage = mkPackageOption {
name = "ripgrep";
default = pkgs.ripgrep;
};
};
extraConfig = cfg: {
assertions = [
{
assertion = cfg.keymaps.todoTelescope.key or null != null -> config.plugins.telescope.enable;
message = ''
Nixvim(plugins.todo-comments): You have enabled todo-comment's `telescope` integration.
However, you have not enabled the `telescope` plugin itself (`plugins.telescope.enable = true`).
'';
}
{
assertion = cfg.keymaps.todoTrouble.key or null != null -> config.plugins.trouble.enable;
message = ''
Nixvim(plugins.todo-comments): You have enabled todo-comment's `trouble` integration.
However, you have not enabled the `trouble` plugin itself (`plugins.trouble.enable = true`).
'';
}
];
extraPackages = [ cfg.ripgrepPackage ];
keymaps = lib.pipe cfg.keymaps [
(filterAttrs (n: v: v != null))
(mapAttrsToList (
name: keymap: {
inherit (keymap) key options;
mode = "n";
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>";
}
))
];
};
} }

View file

@ -7,164 +7,182 @@
plugins.todo-comments = { plugins.todo-comments = {
enable = true; enable = true;
signs = true; settings = {
signPriority = 8; signs = true;
sign_priority = 8;
keywords = { keywords = {
FIX = { FIX = {
icon = " "; icon = " ";
color = "error"; color = "error";
alt = [ alt = [
"FIXME" "FIXME"
"BUG" "BUG"
"FIXIT" "FIXIT"
"ISSUE" "ISSUE"
];
signs = false;
};
TODO = {
icon = " ";
color = "info";
};
HACK = {
icon = " ";
color = "warning";
};
WARN = {
icon = " ";
color = "warning";
alt = [
"WARNING"
"XXX"
];
};
PERF = {
icon = " ";
alt = [
"OPTIM"
"PERFORMANCE"
"OPTIMIZE"
];
};
NOTE = {
icon = " ";
color = "hint";
alt = [ "INFO" ];
};
TEST = {
icon = " ";
color = "test";
alt = [
"TESTING"
"PASSED"
"FAILED"
];
};
};
gui_style = {
fg = "NONE";
bg = "BOLD";
};
merge_keywords = true;
highlight = {
multiline = true;
multiline_pattern = "^.";
multiline_context = 10;
before = "";
keyword = "wide";
after = "fg";
pattern = ''.*<(KEYWORDS)\s*:'';
comments_only = true;
max_line_len = 400;
exclude = [ ];
};
colors = {
error = [
"DiagnosticError"
"ErrorMsg"
"#DC2626"
]; ];
signs = false; warning = [
}; "DiagnosticWarn"
TODO = { "WarningMsg"
icon = " "; "#FBBF24"
color = "info"; ];
}; info = [
HACK = { "DiagnosticInfo"
icon = " "; "#2563EB"
color = "warning"; ];
}; hint = [
WARN = { "DiagnosticHint"
icon = " "; "#10B981"
color = "warning"; ];
alt = [ default = [
"WARNING" "Identifier"
"XXX" "#7C3AED"
];
test = [
"Identifier"
"#FF00FF"
]; ];
}; };
PERF = {
icon = " "; search = {
alt = [ command = "rg";
"OPTIM" args = [
"PERFORMANCE" "--color=never"
"OPTIMIZE" "--no-heading"
"--with-filename"
"--line-number"
"--column"
]; ];
}; pattern = ''\b(KEYWORDS):'';
NOTE = {
icon = " ";
color = "hint";
alt = [ "INFO" ];
};
TEST = {
icon = " ";
color = "test";
alt = [
"TESTING"
"PASSED"
"FAILED"
];
};
};
guiStyle = {
fg = "NONE";
bg = "BOLD";
};
mergeKeywords = true;
highlight = {
multiline = true;
multilinePattern = "^.";
multilineContext = 10;
before = "";
keyword = "wide";
after = "fg";
pattern = ''.*<(KEYWORDS)\s*:'';
commentsOnly = true;
maxLineLen = 400;
exclude = [ ];
};
colors = {
error = [
"DiagnosticError"
"ErrorMsg"
"#DC2626"
];
warning = [
"DiagnosticWarn"
"WarningMsg"
"#FBBF24"
];
info = [
"DiagnosticInfo"
"#2563EB"
];
hint = [
"DiagnosticHint"
"#10B981"
];
default = [
"Identifier"
"#7C3AED"
];
test = [
"Identifier"
"#FF00FF"
];
};
search = {
command = "rg";
args = [
"--color=never"
"--no-heading"
"--with-filename"
"--line-number"
"--column"
];
pattern = ''\b(KEYWORDS):'';
};
keymaps = {
todoQuickFix.key = "<C-a>";
todoLocList = {
key = "<C-f>";
cwd = "~/projects/foobar";
keywords = "TODO,FIX";
options.silent = true;
};
todoTrouble = {
key = "<C-t>";
keywords = "TODO,FIX";
};
todoTelescope = {
key = "<C-e>";
cwd = "~/projects/foobar";
}; };
}; };
}; };
}; };
keymapsOptions = { keymaps-options = {
plugins.todo-comments = { plugins = {
enable = true; trouble.enable = true;
telescope.enable = true;
keymaps = { todo-comments = {
todoTrouble = { enable = true;
key = "<C-f>";
keywords = "TODO,FIX"; keymaps = {
options = { todoQuickFix.key = "<C-a>";
desc = "Description for todoTrouble"; todoLocList = {
silent = true; key = "<C-f>";
cwd = "~/projects/foobar";
keywords = [
"TODO"
"FIX"
];
options.silent = true;
};
todoTrouble = {
key = "<C-f>";
keywords = [
"TODO"
"FIX"
];
options = {
desc = "Description for todoTrouble";
silent = true;
};
};
todoTelescope = {
key = "<C-e>";
cwd = "~/projects/foobar";
}; };
}; };
}; };
}; };
}; };
withoutRipgrep = { without-ripgrep = {
plugins.todo-comments = { plugins.todo-comments = {
enable = true; enable = true;
ripgrepPackage = null; ripgrepPackage = null;
}; };
}; };
highlight-pattern-list = {
plugins.todo-comments = {
enable = true;
settings = {
highlight = {
pattern = [ ".*<(KEYWORDS)\s*:" ];
};
};
};
};
} }