plugins/debugprint: switch to mkNeovimPlugin

This commit is contained in:
Gaetan Lepage 2024-04-07 14:27:25 +02:00 committed by Gaétan Lepage
parent 192b404e41
commit b9f211bbee
2 changed files with 175 additions and 69 deletions

View file

@ -5,33 +5,118 @@
pkgs, pkgs,
... ...
}: }:
with lib; let with lib;
cfg = config.plugins.debugprint; helpers.neovim-plugin.mkNeovimPlugin config {
in { name = "debugprint";
options.plugins.debugprint = originalName = "debugprint.nvim";
helpers.neovim-plugin.extraOptionsOptions defaultPackage = pkgs.vimPlugins.debugprint-nvim;
// {
enable = mkEnableOption "debugprint.nvim";
package = helpers.mkPackageOption "debugprint.nvim" pkgs.vimPlugins.debugprint-nvim; maintainers = [maintainers.GaetanLepage];
createCommands = helpers.defaultNullOpts.mkBool true '' # TODO introduced 2024-04-07: remove 2024-06-07
Creates default commands. deprecateExtraOptions = true;
''; optionsRenamedToSettings = [
"moveToDebugline"
"displayCounter"
"displaySnippet"
"ignoreTreesitter"
"printTag"
];
imports = let
basePluginPath = ["plugins" "debugprint"];
in [
(
mkRemovedOptionModule
(basePluginPath ++ ["createCommands"])
''
This option has been deprectaded upstream.
Learn more [here](https://github.com/andrewferrier/debugprint.nvim/blob/796d8d4528bc5882d287b26e69cc8d810a9147c8/doc/debugprint.nvim.txt#L203-L213).
''
)
(
mkRemovedOptionModule
(basePluginPath ++ ["createKeymaps"])
''
This option has been deprectaded upstream.
Learn more [here](https://github.com/andrewferrier/debugprint.nvim/blob/796d8d4528bc5882d287b26e69cc8d810a9147c8/doc/debugprint.nvim.txt#L203-L213).
''
)
(
mkRemovedOptionModule
(basePluginPath ++ ["filetypes"])
''
Please use `plugins.debugprint.settings.filetypes` instead.
The sub-module options for each filetype are `left`, `right`, `mid_var` and `right_var`.
''
)
];
createKeymaps = helpers.defaultNullOpts.mkBool true '' settingsOptions = {
Creates default keymappings. keymaps =
''; helpers.defaultNullOpts.mkAttrsOf
(with helpers.nixvimTypes; attrsOf (either str rawLua))
''
{
normal = {
plain_below = "g?p";
plain_above = "g?P";
variable_below = "g?v";
variable_above = "g?V";
variable_below_alwaysprompt.__raw = "nil";
variable_above_alwaysprompt.__raw = "nil";
textobj_below = "g?o";
textobj_above = "g?O";
toggle_comment_debug_prints.__raw = "nil";
delete_debug_prints.__raw = "nil";
};
visual = {
variable_below = "g?v";
variable_above = "g?V";
};
}
''
''
By default, the plugin will create some keymappings for use 'out of the box'.
There are also some function invocations which are not mapped to any keymappings by
default, but could be.
This can be overridden using this option.
moveToDebugline = helpers.defaultNullOpts.mkBool false '' You only need to include the keys which you wish to override, others will default as shown
in the documentation.
Setting any key to `nil` (warning: use `__raw`) will skip it.
The default keymappings are chosen specifically because ordinarily in NeoVim they are used
to convert sections to ROT-13, which most folks dont use.
'';
commands =
helpers.defaultNullOpts.mkAttrsOf types.str
''
{
toggle_comment_debug_prints = "ToggleCommentDebugPrints";
delete_debug_prints = "DeleteDebugPrints";
}
''
''
By default, the plugin will create some commands for use 'out of the box'.
There are also some function invocations which are not mapped to any commands by default,
but could be.
This can be overridden using this option.
You only need to include the commands which you wish to override, others will default as
shown in the documentation.
Setting any command to `nil` (warning: use `__raw`) will skip it.
'';
move_to_debugline = helpers.defaultNullOpts.mkBool false ''
When adding a debug line, moves the cursor to that line. When adding a debug line, moves the cursor to that line.
''; '';
displayCounter = helpers.defaultNullOpts.mkBool true '' display_counter = helpers.defaultNullOpts.mkBool true ''
Whether to display/include the monotonically increasing counter in each debug message. Whether to display/include the monotonically increasing counter in each debug message.
''; '';
displaySnippet = helpers.defaultNullOpts.mkBool true '' display_snippet = helpers.defaultNullOpts.mkBool true ''
Whether to include a snippet of the line above/below in plain debug lines. Whether to include a snippet of the line above/below in plain debug lines.
''; '';
@ -51,12 +136,12 @@ in {
description = "Right part of snippet to insert (plain debug line mode)."; description = "Right part of snippet to insert (plain debug line mode).";
}; };
midVar = mkOption { mid_var = mkOption {
type = str; type = str;
description = "Middle part of snippet to insert (variable debug line mode)."; description = "Middle part of snippet to insert (variable debug line mode).";
}; };
rightVar = mkOption { right_var = mkOption {
type = str; type = str;
description = "Right part of snippet to insert (variable debug line mode)."; description = "Right part of snippet to insert (variable debug line mode).";
}; };
@ -76,54 +161,53 @@ in {
python = { python = {
left = "print(f'"; left = "print(f'";
right = "')"; right = "')";
midVar = "{"; mid_var = "{";
rightVar = "}')"; right_var = "}')";
}; };
}; };
``` ```
''; '';
ignoreTreesitter = helpers.defaultNullOpts.mkBool false '' ignore_treesitter = helpers.defaultNullOpts.mkBool false ''
Never use treesitter to find a variable under the cursor, always prompt for it - overrides Never use treesitter to find a variable under the cursor, always prompt for it - overrides
the same setting on `debugprint()` if set to true. the same setting on `debugprint()` if set to true.
''; '';
printTag = helpers.defaultNullOpts.mkStr "DEBUGPRINT" '' print_tag = helpers.defaultNullOpts.mkStr "DEBUGPRINT" ''
The string inserted into each print statement, which can be used to uniquely identify The string inserted into each print statement, which can be used to uniquely identify
statements inserted by `debugprint`. statements inserted by `debugprint`.
''; '';
}; };
config = mkIf cfg.enable { settingsExample = {
extraPlugins = [cfg.package]; keymaps = {
normal = {
extraConfigLua = let variable_below = "g?v";
setupOptions = with cfg; variable_above = "g?V";
{ variable_below_alwaysprompt.__raw = "nil";
create_commands = createCommands; variable_above_alwaysprompt.__raw = "nil";
create_keymaps = createKeymaps; };
move_to_debugline = moveToDebugline; visual = {
display_counter = displayCounter; variable_below = "g?v";
display_snippet = displaySnippet; variable_above = "g?V";
filetypes = };
helpers.ifNonNull' filetypes };
( commands = {
mapAttrs toggle_comment_debug_prints = "ToggleCommentDebugPrints";
( delete_debug_prints = "DeleteDebugPrints";
_: ft: { };
inherit (ft) left right; move_to_debugline = false;
mid_var = ft.midVar; display_counter = true;
right_var = ft.rightVar; display_snippet = true;
} filetypes = {
) python = {
filetypes left = "print(f'";
); right = "')";
ignore_treesitter = ignoreTreesitter; mid_var = "{";
print_tag = printTag; right_var = "}')";
} };
// cfg.extraOptions; };
in '' ignore_treesitter = false;
require('debugprint').setup(${helpers.toLuaObject setupOptions}) print_tag = "DEBUGPRINT";
''; };
}; }
}

View file

@ -7,21 +7,43 @@
plugins.debugprint = { plugins.debugprint = {
enable = true; enable = true;
createKeymaps = true; settings = {
createCommands = true; keymaps = {
moveToDebugline = false; normal = {
displayCounter = true; plain_below = "g?p";
displaySnippet = true; plain_above = "g?P";
filetypes = { variable_below = "g?v";
python = { variable_above = "g?V";
left = "print(f'"; variable_below_alwaysprompt.__raw = "nil";
right = "')"; variable_above_alwaysprompt.__raw = "nil";
midVar = "{"; textobj_below = "g?o";
rightVar = "}')"; textobj_above = "g?O";
toggle_comment_debug_prints.__raw = "nil";
delete_debug_prints.__raw = "nil";
};
visual = {
variable_below = "g?v";
variable_above = "g?V";
};
}; };
commands = {
toggle_comment_debug_prints = "ToggleCommentDebugPrints";
delete_debug_prints = "DeleteDebugPrints";
};
move_to_debugline = false;
display_counter = true;
display_snippet = true;
filetypes = {
python = {
left = "print(f'";
right = "')";
mid_var = "{";
right_var = "}')";
};
};
ignore_treesitter = false;
print_tag = "DEBUGPRINT";
}; };
ignoreTreesitter = false;
printTag = "DEBUGPRINT";
}; };
}; };
} }