plugins/inc-rename: convert to mkNeovimPlugin and add option

Add example

Co-authored-by: Gaétan Lepage
<33058747+GaetanLepage@users.noreply.github.com>

Add example to test as well
This commit is contained in:
Johan Larsson 2025-01-08 15:22:48 +01:00 committed by nix-infra-bot
parent 092a46a1ca
commit 592e9eaff0
2 changed files with 81 additions and 53 deletions

View file

@ -1,61 +1,69 @@
{ { lib, ... }:
lib, let
helpers, inherit (lib) types;
config, inherit (lib.nixvim) defaultNullOpts;
pkgs, in
... lib.nixvim.plugins.mkNeovimPlugin {
}: name = "inc-rename";
with lib; moduleName = "inc_rename";
{ packPathName = "inc-rename.nvim";
options.plugins.inc-rename = { package = "inc-rename-nvim";
enable = mkEnableOption "inc-rename, a plugin previewing LSP renaming"; description = ''
A small Neovim plugin that provides a command for LSP renaming with
immediate visual feedback thanks to Neovim's command preview feature.
'';
package = lib.mkPackageOption pkgs "inc-rename" { maintainers = [ lib.maintainers.jolars ];
default = [
"vimPlugins"
"inc-rename-nvim"
];
};
cmdName = helpers.defaultNullOpts.mkStr "IncRename" "the name of the command"; # TODO: introduced 2025-01-08: remove after 25.05
optionsRenamedToSettings = [
"cmdName"
"hlGroup"
"previewEmptyName"
"showMessage"
"inputBufferType"
"postHook"
];
hlGroup = helpers.defaultNullOpts.mkStr "Substitute" "the highlight group used for highlighting the identifier's new name"; settingsOptions = {
cmd_name = defaultNullOpts.mkStr "IncRename" "The name of the command.";
previewEmptyName = helpers.defaultNullOpts.mkBool false '' hl_group = defaultNullOpts.mkStr "Substitute" ''
whether an empty new name should be previewed; if false the command preview will be cancelled The highlight group used for highlighting the identifier's new name.
instead
''; '';
showMessage = helpers.defaultNullOpts.mkBool true '' preview_empty_name = defaultNullOpts.mkBool false ''
whether to display a `Renamed m instances in n files` message after a rename operation Whether an empty new name should be previewed; if false the command
preview will be cancelled instead.
''; '';
inputBufferType = helpers.defaultNullOpts.mkNullable (types.enum [ "dressing" ]) null '' show_message = defaultNullOpts.mkBool true ''
the type of the external input buffer to use Whether to display a `Renamed m instances in n files` message after a rename operation.
''; '';
postHook = helpers.defaultNullOpts.mkLuaFn null '' save_in_cmdline_history = defaultNullOpts.mkBool true ''
callback to run after renaming, receives the result table (from LSP handler) as an argument Whether to save the `IncRename` command in the commandline history. Set to
false to prevent issues with navigating to older entries that may arise due to
the behavior of command preview).
'';
input_buffer_type = defaultNullOpts.mkNullable (types.enum [ "dressing" ]) null ''
The type of the external input buffer to use.
'';
post_hook = defaultNullOpts.mkRaw null ''
Callback to run after renaming, receives the result table (from LSP
handler) as an argument.
''; '';
}; };
config = settingsExample = {
let input_buffer_type = "dressing";
cfg = config.plugins.inc-rename; preview_empty_name = false;
setupOptions = { show_message.__raw = ''
cmd_name = cfg.cmdName; function(msg)
hl_group = cfg.hlGroup; vim.notify(msg, vim.log.levels.INFO, { title = "Rename" })
preview_empty_name = cfg.previewEmptyName; end
show_message = cfg.showMessage; '';
input_buffer_type = cfg.inputBufferType; };
post_hook = cfg.postHook;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require("inc_rename").setup(${lib.nixvim.toLuaObject setupOptions})
'';
};
} }

View file

@ -6,12 +6,32 @@
defaults = { defaults = {
plugins.inc-rename = { plugins.inc-rename = {
enable = true; enable = true;
cmdName = "IncRename";
hlGroup = "Substitute"; settings = {
previewEmptyName = false; cmd_name = "IncRename";
showMessage = true; hl_group = "Substitute";
inputBufferType = null; preview_empty_name = false;
postHook = null; show_message = true;
save_in_cmdline_history = true;
input_buffer_type = null;
post_hook = null;
};
};
};
example = {
plugins.inc-rename = {
enable = true;
settings = {
input_buffer_type = "dressing";
preview_empty_name = false;
show_message.__raw = ''
function(msg)
vim.notify(msg, vim.log.levels.INFO, { title = "Rename" })
end
'';
};
}; };
}; };
} }