plugins/gitblame: switch to mkNeovimPlugin

This commit is contained in:
Gaetan Lepage 2024-08-03 10:56:01 +02:00
parent 0bc1699037
commit 96d0a2e390
2 changed files with 159 additions and 56 deletions

View file

@ -5,67 +5,136 @@
pkgs,
...
}:
with lib;
let
cfg = config.plugins.gitblame;
inherit (lib.nixvim) defaultNullOpts mkPackageOption;
types = lib.nixvim.nixvimTypes;
in
{
options = {
plugins.gitblame = {
enable = mkEnableOption "gitblame";
helpers.neovim-plugin.mkNeovimPlugin config {
name = "gitblame";
originalName = "git-blame.nvim";
defaultPackage = pkgs.vimPlugins.git-blame-nvim;
package = helpers.mkPluginPackageOption "gitblame" pkgs.vimPlugins.git-blame-nvim;
maintainers = with lib.maintainers; [ GaetanLepage ];
messageTemplate = helpers.defaultNullOpts.mkStr " <author> <date> <summary>" "The template for the blame message that will be shown.";
# TODO: introduce 2024-08-03. Remove after 24.11
optionsRenamedToSettings = [
"messageTemplate"
"dateFormat"
"messageWhenNotCommitted"
"highlightGroup"
"extmarkOptions"
"displayVirtualText"
"ignoredFiletypes"
"delay"
"virtualTextColumn"
];
dateFormat = helpers.defaultNullOpts.mkStr "%c" "The format of the date fields in messageTemplate.";
settingsOptions = {
enabled = defaultNullOpts.mkBool true ''
Enables the plugin on Neovim startup.
You can toggle git blame messages on/off with the `:GitBlameToggle` command.
'';
messageWhenNotCommitted = helpers.defaultNullOpts.mkStr " Not Committed Yet" "The blame message that will be shown when the current modification hasn't been committed yet.";
message_template = defaultNullOpts.mkStr " <author> <date> <summary>" ''
The template for the blame message that will be shown.
highlightGroup = helpers.defaultNullOpts.mkStr "Comment" "The highlight group for virtual text.";
Available options: `<author>`, `<committer>`, `<date>`, `<committer-date>`, `<summary>`,
`<sha>`.
'';
displayVirtualText = helpers.defaultNullOpts.mkBool true "If the blame message should be displayed as virtual text. You may want to disable this if you display the blame message in statusline.";
date_format = defaultNullOpts.mkStr "%c" ''
The [format](https://www.lua.org/pil/22.1.html) of the date fields in `message_template`.
ignoredFiletypes =
helpers.defaultNullOpts.mkListOf types.str [ ]
"A list of filetypes for which gitblame information will not be displayed.";
See [upstream doc](https://github.com/f-person/git-blame.nvim?tab=readme-ov-file#date-format)
for the available options.
'';
delay =
helpers.defaultNullOpts.mkUnsignedInt 0
"The delay in milliseconds after which the blame info will be displayed.";
message_when_not_committed = defaultNullOpts.mkStr " Not Committed Yet" ''
The blame message that will be shown when the current modification hasn't been committed yet.
virtualTextColumn =
helpers.defaultNullOpts.mkNullable types.ints.unsigned null
"Have the blame message start at a given column instead of EOL. If the current line is longer than the specified column value the blame message will default to being displayed at EOL.";
Supports the same template options as `message_template`.
'';
extmarkOptions = helpers.defaultNullOpts.mkAttributeSet null "nvim_buf_set_extmark optional parameters. (Warning: overwriting id and virt_text will break the plugin behavior)";
highlight_group = defaultNullOpts.mkStr "Comment" ''
The highlight group for virtual text.
'';
set_extmark_options = defaultNullOpts.mkAttrsOf types.anything { } ''
`nvim_buf_set_extmark` is the function used for setting the virtual text.
You can view an up-to-date full list of options in the
[Neovim documentation](https://neovim.io/doc/user/api.html#nvim_buf_set_extmark()).
**Warning:** overwriting `id` and `virt_text` will break the plugin behavior.
'';
display_virtual_text = defaultNullOpts.mkBool true ''
If the blame message should be displayed as virtual text.
You may want to disable this if you display the blame message in statusline.
'';
ignored_filetypes = defaultNullOpts.mkListOf types.str [ ] ''
A list of filetypes for which gitblame information will not be displayed.
'';
delay = defaultNullOpts.mkUnsignedInt 250 ''
The delay in milliseconds after which the blame info will be displayed.
'';
virtual_text_column = defaultNullOpts.mkUnsignedInt null ''
Have the blame message start at a given column instead of EOL.
If the current line is longer than the specified column value, the blame message will default
to being displayed at EOL.
'';
use_blame_commit_file_urls = defaultNullOpts.mkBool false ''
By default the commands `GitBlameOpenFileURL` and `GitBlameCopyFileURL` open the current file
at latest branch commit.
If you would like to open these files at the latest blame commit (in other words, the commit
marked by the blame), set this to true.
For ranges, the blame selected will be the most recent blame from the range.
'';
schedule_event = defaultNullOpts.mkStr "CursorMoved" ''
If you are experiencing poor performance (e.g. in particularly large projects) you can use
`CursorHold` instead of the default `CursorMoved` autocommand to limit the frequency of events
being run.
'';
clear_event = defaultNullOpts.mkStr "CursorMovedI" ''
If you are experiencing poor performance (e.g. in particularly large projects) you can use
`CursorHoldI` instead of the default `CursorMovedI` autocommand to limit the frequency of
events being run.
'';
clipboard_register = defaultNullOpts.mkStr "+" ''
By default the `:GitBlameCopySHA`, `:GitBlameCopyFileURL` and `:GitBlameCopyCommitURL`
commands use the `+` register.
Set this value if you would like to use a different register (such as `*`).
'';
};
settingsExample = {
message_template = "<summary> <date> <author>";
date_format = "%r";
message_when_not_committed = "Oh please, commit this !";
highlight_group = "Question";
set_extmark_options.priority = 7;
display_virtual_text = false;
ignored_filetypes = [
"lua"
"c"
];
delay = 1000;
virtual_text_column = 80;
use_blame_commit_file_urls = true;
};
extraOptions = {
gitPackage = mkPackageOption {
name = "git";
default = pkgs.git;
};
};
config =
let
setupOptions = {
enabled = cfg.enable;
message_template = cfg.messageTemplate;
date_format = cfg.dateFormat;
message_when_not_committed = cfg.messageWhenNotCommitted;
highlight_group = cfg.highlightGroup;
display_virtual_text = helpers.ifNonNull' cfg.displayVirtualText (
if cfg.displayVirtualText then 1 else 0
);
ignored_filetypes = cfg.ignoredFiletypes;
inherit (cfg) delay;
virtual_text_column = cfg.virtualTextColumn;
set_extmark_options = cfg.extmarkOptions;
};
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraPackages = [ pkgs.git ];
extraConfigLua = ''
require('gitblame').setup${helpers.toLuaObject setupOptions}
'';
};
extraConfig = cfg: { extraPackages = [ cfg.gitPackage ]; };
}

View file

@ -6,14 +6,48 @@
defaults = {
plugins.gitblame = {
enable = true;
messageTemplate = " <author> <date> <summary>";
dateFormat = "%c";
messageWhenNotCommitted = " Not Committed Yet";
highlightGroup = "Comment";
displayVirtualText = true;
delay = 0;
virtualTextColumn = null;
extmarkOptions = null;
settings = {
enabled = true;
message_template = " <author> <date> <summary>";
date_format = "%c";
message_when_not_committed = " Not Committed Yet";
highlight_group = "Comment";
set_extmark_options = { };
display_virtual_text = true;
ignored_filetypes = [ ];
delay = 250;
virtual_text_column = null;
use_blame_commit_file_urls = false;
schedule_event = "CursorMoved";
clear_event = "CursorMovedI";
clipboard_register = "+";
};
};
};
example = {
plugins.gitblame = {
enable = true;
settings = {
message_template = "<summary> <date> <author>";
date_format = "%r";
message_when_not_committed = "Oh please, commit this !";
highlight_group = "Question";
set_extmark_options.priority = 7;
display_virtual_text = false;
ignored_filetypes = [
"lua"
"c"
];
delay = 1000;
virtual_text_column = 80;
use_blame_commit_file_urls = true;
schedule_event = "CursorHold";
clear_event = "CursorHoldI";
clipboard_register = "*";
};
};
};
}