plugins/gitsigns: cosmetic refactoring

This commit is contained in:
Gaetan Lepage 2025-01-20 14:36:23 +01:00
parent af6e4b0bad
commit 731699a24c
2 changed files with 54 additions and 49 deletions

View file

@ -1,17 +1,19 @@
{ {
lib, lib,
helpers,
config, config,
pkgs, pkgs,
... ...
}: }:
with lib; let
inherit (lib) flatten mapAttrsToList mkRemovedOptionModule;
inherit (lib.nixvim) mkDeprecatedSubOptionModule;
in
lib.nixvim.plugins.mkNeovimPlugin { lib.nixvim.plugins.mkNeovimPlugin {
name = "gitsigns"; name = "gitsigns";
packPathName = "gitsigns.nvim"; packPathName = "gitsigns.nvim";
package = "gitsigns-nvim"; package = "gitsigns-nvim";
maintainers = [ maintainers.GaetanLepage ]; maintainers = [ lib.maintainers.GaetanLepage ];
# TODO: introduced 2024-03-12, remove on 2024-05-12 # TODO: introduced 2024-03-12, remove on 2024-05-12
deprecateExtraOptions = true; deprecateExtraOptions = true;
@ -55,7 +57,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
in in
(map ( (map (
{ optionPath, hlg }: { optionPath, hlg }:
helpers.mkDeprecatedSubOptionModule optionPath "Please define the `${hlg}` highlight group instead." mkDeprecatedSubOptionModule optionPath "Please define the `${hlg}` highlight group instead."
) highlightRemovals) ) highlightRemovals)
++ [ ++ [
(mkRemovedOptionModule ( (mkRemovedOptionModule (
@ -65,7 +67,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
"interval" "interval"
] ]
) "The option has been removed from upstream.") ) "The option has been removed from upstream.")
(helpers.mkDeprecatedSubOptionModule ( (mkDeprecatedSubOptionModule (
settingsPath settingsPath
++ [ ++ [
"yadm" "yadm"
@ -80,7 +82,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
}; };
}; };
settingsOptions = import ./options.nix { inherit lib helpers; }; settingsOptions = import ./settings-options.nix lib;
settingsExample = { settingsExample = {
signs = { signs = {
@ -102,7 +104,7 @@ lib.nixvim.plugins.mkNeovimPlugin {
extraConfig = cfg: { extraConfig = cfg: {
warnings = lib.nixvim.mkWarnings "plugins.gitsigns" { warnings = lib.nixvim.mkWarnings "plugins.gitsigns" {
when = (isBool cfg.settings.trouble && cfg.settings.trouble) && !config.plugins.trouble.enable; when = (lib.isBool cfg.settings.trouble && cfg.settings.trouble) && !config.plugins.trouble.enable;
message = '' message = ''
You have enabled `plugins.gitsigns.settings.trouble` but `plugins.trouble.enable` is `false`. You have enabled `plugins.gitsigns.settings.trouble` but `plugins.trouble.enable` is `false`.

View file

@ -1,14 +1,17 @@
{ lib, helpers }: lib:
with lib; let
inherit (lib) types mkOption;
inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrLuaFn;
in
{ {
signs = signs =
let let
signOptions = defaults: { signOptions = defaults: {
text = helpers.defaultNullOpts.mkStr defaults.text '' text = defaultNullOpts.mkStr defaults.text ''
Specifies the character to use for the sign. Specifies the character to use for the sign.
''; '';
show_count = helpers.defaultNullOpts.mkBool false '' show_count = defaultNullOpts.mkBool false ''
Showing count of hunk, e.g. number of deleted lines. Showing count of hunk, e.g. number of deleted lines.
''; '';
}; };
@ -73,13 +76,13 @@ with lib;
}; };
}; };
in in
helpers.mkNullOrOption (types.listOf worktreeType) '' mkNullOrOption (types.listOf worktreeType) ''
Detached working trees. Detached working trees.
If normal attaching fails, then each entry in the table is attempted with the work tree If normal attaching fails, then each entry in the table is attempted with the work tree
details set. details set.
''; '';
on_attach = helpers.mkNullOrLuaFn '' on_attach = mkNullOrLuaFn ''
Callback called when attaching to a buffer. Mainly used to setup keymaps Callback called when attaching to a buffer. Mainly used to setup keymaps
when `config.keymaps` is empty. The buffer number is passed as the first when `config.keymaps` is empty. The buffer number is passed as the first
argument. argument.
@ -101,28 +104,28 @@ with lib;
''; '';
watch_gitdir = { watch_gitdir = {
enable = helpers.defaultNullOpts.mkBool true '' enable = defaultNullOpts.mkBool true ''
When opening a file, a `libuv` watcher is placed on the respective `.git` directory to detect When opening a file, a `libuv` watcher is placed on the respective `.git` directory to detect
when changes happen to use as a trigger to update signs. when changes happen to use as a trigger to update signs.
''; '';
follow_files = helpers.defaultNullOpts.mkBool true '' follow_files = defaultNullOpts.mkBool true ''
If a file is moved with `git mv`, switch the buffer to the new location. If a file is moved with `git mv`, switch the buffer to the new location.
''; '';
}; };
sign_priority = helpers.defaultNullOpts.mkUnsignedInt 6 '' sign_priority = defaultNullOpts.mkUnsignedInt 6 ''
Priority to use for signs. Priority to use for signs.
''; '';
signcolumn = helpers.defaultNullOpts.mkBool true '' signcolumn = defaultNullOpts.mkBool true ''
Enable/disable symbols in the sign column. Enable/disable symbols in the sign column.
When enabled the highlights defined in `signs.*.hl` and symbols defined in `signs.*.text` are When enabled the highlights defined in `signs.*.hl` and symbols defined in `signs.*.text` are
used. used.
''; '';
numhl = helpers.defaultNullOpts.mkBool false '' numhl = defaultNullOpts.mkBool false ''
Enable/disable line number highlights. Enable/disable line number highlights.
When enabled the highlights defined in `signs.*.numhl` are used. When enabled the highlights defined in `signs.*.numhl` are used.
@ -130,7 +133,7 @@ with lib;
corresponding highlight group in `signs.*.hl`. corresponding highlight group in `signs.*.hl`.
''; '';
linehl = helpers.defaultNullOpts.mkBool false '' linehl = defaultNullOpts.mkBool false ''
Enable/disable line highlights. Enable/disable line highlights.
When enabled the highlights defined in `signs.*.linehl` are used. When enabled the highlights defined in `signs.*.linehl` are used.
@ -138,7 +141,7 @@ with lib;
corresponding highlight group in `signs.*.hl`. corresponding highlight group in `signs.*.hl`.
''; '';
show_deleted = helpers.defaultNullOpts.mkBool false '' show_deleted = defaultNullOpts.mkBool false ''
Show the old version of hunks inline in the buffer (via virtual lines). Show the old version of hunks inline in the buffer (via virtual lines).
Note: Virtual lines currently use the highlight `GitSignsDeleteVirtLn`. Note: Virtual lines currently use the highlight `GitSignsDeleteVirtLn`.
@ -150,7 +153,7 @@ with lib;
freeformType = with types; attrsOf anything; freeformType = with types; attrsOf anything;
options = { options = {
algorithm = algorithm =
helpers.defaultNullOpts.mkEnumFirstDefault defaultNullOpts.mkEnumFirstDefault
[ [
"myers" "myers"
"minimal" "minimal"
@ -165,54 +168,54 @@ with lib;
- "histogram" histogram diff algorithm - "histogram" histogram diff algorithm
''; '';
internal = helpers.defaultNullOpts.mkBool false '' internal = defaultNullOpts.mkBool false ''
Use Neovim's built in `xdiff` library for running diffs. Use Neovim's built in `xdiff` library for running diffs.
''; '';
indent_heuristic = helpers.defaultNullOpts.mkBool false '' indent_heuristic = defaultNullOpts.mkBool false ''
Use the indent heuristic for the internal diff library. Use the indent heuristic for the internal diff library.
''; '';
vertical = helpers.defaultNullOpts.mkBool true '' vertical = defaultNullOpts.mkBool true ''
Start diff mode with vertical splits. Start diff mode with vertical splits.
''; '';
linematch = helpers.mkNullOrOption types.int '' linematch = mkNullOrOption types.int ''
Enable second-stage diff on hunks to align lines. Enable second-stage diff on hunks to align lines.
Requires `internal=true`. Requires `internal=true`.
''; '';
ignore_blank_lines = helpers.defaultNullOpts.mkBool true '' ignore_blank_lines = defaultNullOpts.mkBool true ''
Ignore changes where lines are blank. Ignore changes where lines are blank.
''; '';
ignore_whitespace_change = helpers.defaultNullOpts.mkBool true '' ignore_whitespace_change = defaultNullOpts.mkBool true ''
Ignore changes in amount of white space. Ignore changes in amount of white space.
It should ignore adding trailing white space, but not leading white space. It should ignore adding trailing white space, but not leading white space.
''; '';
ignore_whitespace = helpers.defaultNullOpts.mkBool true '' ignore_whitespace = defaultNullOpts.mkBool true ''
Ignore all white space changes. Ignore all white space changes.
''; '';
ignore_whitespace_change_at_eol = helpers.defaultNullOpts.mkBool true '' ignore_whitespace_change_at_eol = defaultNullOpts.mkBool true ''
Ignore white space changes at end of line. Ignore white space changes at end of line.
''; '';
}; };
}; };
in in
helpers.mkNullOrOption diffOptType '' mkNullOrOption diffOptType ''
Diff options. Diff options.
If set to null they are derived from the vim `diffopt`. If set to null they are derived from the vim `diffopt`.
''; '';
base = helpers.mkNullOrOption types.str '' base = mkNullOrOption types.str ''
The object/revision to diff against. The object/revision to diff against.
See `|gitsigns-revision|`. See `|gitsigns-revision|`.
''; '';
count_chars = count_chars =
helpers.defaultNullOpts.mkAttrsOf types.str defaultNullOpts.mkAttrsOf types.str
{ {
"__unkeyed_1" = "1"; "__unkeyed_1" = "1";
"__unkeyed_2" = "2"; "__unkeyed_2" = "2";
@ -235,7 +238,7 @@ with lib;
- to define characters to be used for counts greater than 9. - to define characters to be used for counts greater than 9.
''; '';
status_formatter = helpers.defaultNullOpts.mkLuaFn '' status_formatter = defaultNullOpts.mkLuaFn ''
function(status) function(status)
local added, changed, removed = status.added, status.changed, status.removed local added, changed, removed = status.added, status.changed, status.removed
local status_txt = {} local status_txt = {}
@ -252,12 +255,12 @@ with lib;
end end
'' "Function used to format `b:gitsigns_status`."; '' "Function used to format `b:gitsigns_status`.";
max_file_length = helpers.defaultNullOpts.mkUnsignedInt 40000 '' max_file_length = defaultNullOpts.mkUnsignedInt 40000 ''
Max file length (in lines) to attach to. Max file length (in lines) to attach to.
''; '';
preview_config = preview_config =
helpers.defaultNullOpts.mkAttrsOf types.anything defaultNullOpts.mkAttrsOf types.anything
{ {
border = "single"; border = "single";
style = "minimal"; style = "minimal";
@ -270,30 +273,30 @@ with lib;
Table is passed directly to `nvim_open_win`. Table is passed directly to `nvim_open_win`.
''; '';
auto_attach = helpers.defaultNullOpts.mkBool true '' auto_attach = defaultNullOpts.mkBool true ''
Automatically attach to files. Automatically attach to files.
''; '';
attach_to_untracked = helpers.defaultNullOpts.mkBool true '' attach_to_untracked = defaultNullOpts.mkBool true ''
Attach to untracked files. Attach to untracked files.
''; '';
update_debounce = helpers.defaultNullOpts.mkUnsignedInt 100 '' update_debounce = defaultNullOpts.mkUnsignedInt 100 ''
Debounce time for updates (in milliseconds). Debounce time for updates (in milliseconds).
''; '';
current_line_blame = helpers.defaultNullOpts.mkBool false '' current_line_blame = defaultNullOpts.mkBool false ''
Adds an unobtrusive and customisable blame annotation at the end of the current line. Adds an unobtrusive and customisable blame annotation at the end of the current line.
The highlight group used for the text is `GitSignsCurrentLineBlame`. The highlight group used for the text is `GitSignsCurrentLineBlame`.
''; '';
current_line_blame_opts = { current_line_blame_opts = {
virt_text = helpers.defaultNullOpts.mkBool true '' virt_text = defaultNullOpts.mkBool true ''
Whether to show a virtual text blame annotation Whether to show a virtual text blame annotation
''; '';
virt_text_pos = virt_text_pos =
helpers.defaultNullOpts.mkEnumFirstDefault defaultNullOpts.mkEnumFirstDefault
[ [
"eol" "eol"
"overlay" "overlay"
@ -308,20 +311,20 @@ with lib;
- `right_align` Display right aligned in the window. - `right_align` Display right aligned in the window.
''; '';
delay = helpers.defaultNullOpts.mkUnsignedInt 1000 '' delay = defaultNullOpts.mkUnsignedInt 1000 ''
Sets the delay (in milliseconds) before blame virtual text is displayed. Sets the delay (in milliseconds) before blame virtual text is displayed.
''; '';
ignore_whitespace = helpers.defaultNullOpts.mkBool false '' ignore_whitespace = defaultNullOpts.mkBool false ''
Ignore whitespace when running blame. Ignore whitespace when running blame.
''; '';
virt_text_priority = helpers.defaultNullOpts.mkUnsignedInt 100 '' virt_text_priority = defaultNullOpts.mkUnsignedInt 100 ''
Priority of virtual text. Priority of virtual text.
''; '';
}; };
current_line_blame_formatter = helpers.defaultNullOpts.mkStr " <author>, <author_time> - <summary> " '' current_line_blame_formatter = defaultNullOpts.mkStr " <author>, <author_time> - <summary> " ''
String or function used to format the virtual text of `current_line_blame`. String or function used to format the virtual text of `current_line_blame`.
When a string, accepts the following format specifiers: When a string, accepts the following format specifiers:
@ -391,26 +394,26 @@ with lib;
`|nvim_buf_set_extmark|` and thus must be a list of `[text, highlight]` tuples. `|nvim_buf_set_extmark|` and thus must be a list of `[text, highlight]` tuples.
''; '';
current_line_blame_formatter_nc = helpers.defaultNullOpts.mkStr " <author>" '' current_line_blame_formatter_nc = defaultNullOpts.mkStr " <author>" ''
String or function used to format the virtual text of `|gitsigns-config-current_line_blame|` String or function used to format the virtual text of `|gitsigns-config-current_line_blame|`
for lines that aren't committed. for lines that aren't committed.
See `|gitsigns-config-current_line_blame_formatter|` for more information. See `|gitsigns-config-current_line_blame_formatter|` for more information.
''; '';
trouble = helpers.mkNullOrOption types.bool '' trouble = mkNullOrOption types.bool ''
When using setqflist() or setloclist(), open Trouble instead of the When using setqflist() or setloclist(), open Trouble instead of the
quickfix/location list window. quickfix/location list window.
Default: `pcall(require, 'trouble')` Default: `pcall(require, 'trouble')`
''; '';
word_diff = helpers.defaultNullOpts.mkBool false '' word_diff = defaultNullOpts.mkBool false ''
Highlight intra-line word differences in the buffer. Highlight intra-line word differences in the buffer.
Requires `config.diff_opts.internal = true`. Requires `config.diff_opts.internal = true`.
''; '';
debug_mode = helpers.defaultNullOpts.mkBool false '' debug_mode = defaultNullOpts.mkBool false ''
Enables debug logging and makes the following functions available: `dump_cache`, Enables debug logging and makes the following functions available: `dump_cache`,
`debug_messages`, `clear_debug`. `debug_messages`, `clear_debug`.
''; '';