mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
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:
parent
092a46a1ca
commit
592e9eaff0
2 changed files with 81 additions and 53 deletions
|
@ -1,61 +1,69 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
options.plugins.inc-rename = {
|
||||
enable = mkEnableOption "inc-rename, a plugin previewing LSP renaming";
|
||||
|
||||
package = lib.mkPackageOption pkgs "inc-rename" {
|
||||
default = [
|
||||
"vimPlugins"
|
||||
"inc-rename-nvim"
|
||||
];
|
||||
};
|
||||
|
||||
cmdName = helpers.defaultNullOpts.mkStr "IncRename" "the name of the command";
|
||||
|
||||
hlGroup = helpers.defaultNullOpts.mkStr "Substitute" "the highlight group used for highlighting the identifier's new name";
|
||||
|
||||
previewEmptyName = helpers.defaultNullOpts.mkBool false ''
|
||||
whether an empty new name should be previewed; if false the command preview will be cancelled
|
||||
instead
|
||||
'';
|
||||
|
||||
showMessage = helpers.defaultNullOpts.mkBool true ''
|
||||
whether to display a `Renamed m instances in n files` message after a rename operation
|
||||
'';
|
||||
|
||||
inputBufferType = helpers.defaultNullOpts.mkNullable (types.enum [ "dressing" ]) null ''
|
||||
the type of the external input buffer to use
|
||||
'';
|
||||
|
||||
postHook = helpers.defaultNullOpts.mkLuaFn null ''
|
||||
callback to run after renaming, receives the result table (from LSP handler) as an argument
|
||||
'';
|
||||
};
|
||||
|
||||
config =
|
||||
{ lib, ... }:
|
||||
let
|
||||
cfg = config.plugins.inc-rename;
|
||||
setupOptions = {
|
||||
cmd_name = cfg.cmdName;
|
||||
hl_group = cfg.hlGroup;
|
||||
preview_empty_name = cfg.previewEmptyName;
|
||||
show_message = cfg.showMessage;
|
||||
input_buffer_type = cfg.inputBufferType;
|
||||
post_hook = cfg.postHook;
|
||||
};
|
||||
inherit (lib) types;
|
||||
inherit (lib.nixvim) defaultNullOpts;
|
||||
in
|
||||
mkIf cfg.enable {
|
||||
extraPlugins = [ cfg.package ];
|
||||
lib.nixvim.plugins.mkNeovimPlugin {
|
||||
name = "inc-rename";
|
||||
moduleName = "inc_rename";
|
||||
packPathName = "inc-rename.nvim";
|
||||
package = "inc-rename-nvim";
|
||||
description = ''
|
||||
A small Neovim plugin that provides a command for LSP renaming with
|
||||
immediate visual feedback thanks to Neovim's command preview feature.
|
||||
'';
|
||||
|
||||
extraConfigLua = ''
|
||||
require("inc_rename").setup(${lib.nixvim.toLuaObject setupOptions})
|
||||
maintainers = [ lib.maintainers.jolars ];
|
||||
|
||||
# TODO: introduced 2025-01-08: remove after 25.05
|
||||
optionsRenamedToSettings = [
|
||||
"cmdName"
|
||||
"hlGroup"
|
||||
"previewEmptyName"
|
||||
"showMessage"
|
||||
"inputBufferType"
|
||||
"postHook"
|
||||
];
|
||||
|
||||
settingsOptions = {
|
||||
cmd_name = defaultNullOpts.mkStr "IncRename" "The name of the command.";
|
||||
|
||||
hl_group = defaultNullOpts.mkStr "Substitute" ''
|
||||
The highlight group used for highlighting the identifier's new name.
|
||||
'';
|
||||
|
||||
preview_empty_name = defaultNullOpts.mkBool false ''
|
||||
Whether an empty new name should be previewed; if false the command
|
||||
preview will be cancelled instead.
|
||||
'';
|
||||
|
||||
show_message = defaultNullOpts.mkBool true ''
|
||||
Whether to display a `Renamed m instances in n files` message after a rename operation.
|
||||
'';
|
||||
|
||||
save_in_cmdline_history = defaultNullOpts.mkBool true ''
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
settingsExample = {
|
||||
input_buffer_type = "dressing";
|
||||
preview_empty_name = false;
|
||||
show_message.__raw = ''
|
||||
function(msg)
|
||||
vim.notify(msg, vim.log.levels.INFO, { title = "Rename" })
|
||||
end
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,12 +6,32 @@
|
|||
defaults = {
|
||||
plugins.inc-rename = {
|
||||
enable = true;
|
||||
cmdName = "IncRename";
|
||||
hlGroup = "Substitute";
|
||||
previewEmptyName = false;
|
||||
showMessage = true;
|
||||
inputBufferType = null;
|
||||
postHook = null;
|
||||
|
||||
settings = {
|
||||
cmd_name = "IncRename";
|
||||
hl_group = "Substitute";
|
||||
preview_empty_name = false;
|
||||
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue