plugins/diffview: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2024-09-04 22:07:06 -05:00
parent 380435c555
commit bc83b5d80d
No known key found for this signature in database
2 changed files with 356 additions and 309 deletions

View file

@ -1,145 +1,138 @@
{ {
lib, lib,
helpers,
config, config,
pkgs,
options,
... ...
}: }:
with lib;
let let
cfg = config.plugins.diffview; inherit (lib.nixvim) defaultNullOpts;
mkWinConfig = inherit (lib) types;
{
type ? null,
width ? null,
height ? null,
position ? null,
}:
with helpers.defaultNullOpts;
{
type =
mkEnum
[
"split"
"float"
]
type
''
Determines whether the window should be a float or a normal
split.
'';
width = mkInt width ''
The width of the window (in character cells). If `type` is
`"split"` then this is only applicable when `position` is
`"left"|"right"`.
'';
height = mkInt height ''
The height of the window (in character cells). If `type` is
`"split"` then this is only applicable when `position` is
`"top"|"bottom"`.
'';
position =
mkEnum
[
"left"
"top"
"right"
"bottom"
]
position
''
Determines where the panel is positioned (only when
`type="split"`).
'';
relative =
mkEnum
[
"editor"
"win"
]
"editor"
''
Determines what the `position` is relative to (when
`type="split"`).
'';
win = mkInt 0 ''
The window handle of the target relative window (when
`type="split"`. Only when `relative="win"`). Use `0` for
current window.
'';
winOpts = mkAttributeSet { } ''
Table of window local options (see |vim.opt_local|).
These options are applied whenever the window is opened.
'';
};
in in
{ lib.nixvim.plugins.mkNeovimPlugin {
options.plugins.diffview = name = "diffview";
with helpers.defaultNullOpts; packPathName = "diffview.nvim";
lib.nixvim.plugins.neovim.extraOptionsOptions package = "diffview-nvim";
// {
enable = mkEnableOption "diffview";
package = lib.mkPackageOption pkgs "diffview" { maintainers = [ lib.maintainers.khaneliman ];
default = [
"vimPlugins"
"diffview-nvim"
];
};
diffBinaries = mkBool false '' settingsOptions =
let
mkWinConfig =
{
type ? null,
width ? null,
height ? null,
position ? null,
}:
{
type =
defaultNullOpts.mkEnum
[
"split"
"float"
]
type
''
Determines whether the window should be a float or a normal
split.
'';
width = defaultNullOpts.mkInt width ''
The width of the window (in character cells). If `type` is
`"split"` then this is only applicable when `position` is
`"left"|"right"`.
'';
height = defaultNullOpts.mkInt height ''
The height of the window (in character cells). If `type` is
`"split"` then this is only applicable when `position` is
`"top"|"bottom"`.
'';
position =
defaultNullOpts.mkEnum
[
"left"
"top"
"right"
"bottom"
]
position
''
Determines where the panel is positioned (only when
`type="split"`).
'';
relative =
defaultNullOpts.mkEnum
[
"editor"
"win"
]
"editor"
''
Determines what the `position` is relative to (when
`type="split"`).
'';
win = defaultNullOpts.mkInt 0 ''
The window handle of the target relative window (when
`type="split"`. Only when `relative="win"`). Use `0` for
current window.
'';
win_opts = defaultNullOpts.mkAttributeSet { } ''
Table of window local options (see |vim.opt_local|).
These options are applied whenever the window is opened.
'';
};
in
{
diff_binaries = defaultNullOpts.mkBool false ''
Show diffs for binaries Show diffs for binaries
''; '';
enhancedDiffHl = mkBool false '' enhanced_diff_hl = defaultNullOpts.mkBool false ''
See ':h diffview-config-enhanced_diff_hl' See ':h diffview-config-enhanced_diff_hl'
''; '';
gitCmd = mkListOf types.str [ "git" ] '' git_cmd = defaultNullOpts.mkListOf types.str [ "git" ] ''
The git executable followed by default args. The git executable followed by default args.
''; '';
hgCmd = mkListOf types.str [ "hg" ] '' hg_cmd = defaultNullOpts.mkListOf types.str [ "hg" ] ''
The hg executable followed by default args. The hg executable followed by default args.
''; '';
useIcons = mkOption { use_icons = lib.lib.mkOption {
type = types.bool; type = types.bool;
description = "Requires nvim-web-devicons"; description = "Requires nvim-web-devicons";
default = true; default = true;
}; };
showHelpHints = mkBool true '' show_help_hints = defaultNullOpts.mkBool true ''
Show hints for how to open the help panel Show hints for how to open the help panel
''; '';
watchIndex = mkBool true '' watch_index = defaultNullOpts.mkBool.true ''
Update views and index buffers when the git index changes. Update views and index buffers when the git index changes.
''; '';
icons = { icons = {
folderClosed = mkStr "" '' folder_closed = defaultNullOpts.mkStr "" ''
Only applies when use_icons is true. Only applies when use_icons is true.
''; '';
folderOpen = mkStr "" '' folder_open = defaultNullOpts.mkStr "" ''
Only applies when use_icons is true. Only applies when use_icons is true.
''; '';
}; };
signs = { signs = {
foldClosed = mkStr "" ""; fold_closed = defaultNullOpts.mkStr "" "";
foldOpen = mkStr "" ""; fold_open = defaultNullOpts.mkStr "" "";
done = mkStr "" ""; done = defaultNullOpts.mkStr "" "";
}; };
view = view =
@ -167,7 +160,7 @@ in
{ {
default = { default = {
layout = layout =
mkEnum defaultNullOpts.mkEnum
[ [
"diff2_horizontal" "diff2_horizontal"
"diff2_vertical" "diff2_vertical"
@ -184,14 +177,14 @@ in
${diff2VerticalDescription} ${diff2VerticalDescription}
''; '';
winbarInfo = mkBool false '' winbarInfo = defaultNullOpts.mkBool.false ''
See ':h diffview-config-view.x.winbar_info' See ':h diffview-config-view.x.winbar_info'
''; '';
}; };
mergeTool = { merge_tool = {
layout = layout =
mkEnum defaultNullOpts.mkEnum
[ [
"diff1_plain" "diff1_plain"
"diff3_horizontal" "diff3_horizontal"
@ -238,18 +231,18 @@ in
''; '';
disableDiagnostics = mkBool true '' disable_diagnostics = defaultNullOpts.mkBool.true ''
Temporarily disable diagnostics for conflict buffers while in the view. Temporarily disable diagnostics for conflict buffers while in the view.
''; '';
winbarInfo = mkBool true '' winbar_info = defaultNullOpts.mkBool.true ''
See ':h diffview-config-view.x.winbar_info' See ':h diffview-config-view.x.winbar_info'
''; '';
}; };
fileHistory = { file_history = {
layout = layout =
mkEnum defaultNullOpts.mkEnum
[ [
"diff2_horizontal" "diff2_horizontal"
"diff2_vertical" "diff2_vertical"
@ -266,15 +259,15 @@ in
${diff2VerticalDescription} ${diff2VerticalDescription}
''; '';
winbarInfo = mkBool false '' winbar_info = defaultNullOpts.mkBool.false ''
See ':h diffview-config-view.x.winbar_info' See ':h diffview-config-view.x.winbar_info'
''; '';
}; };
}; };
filePanel = { file_panel = {
listingStyle = listing_style =
mkEnum defaultNullOpts.mkEnum
[ [
"list" "list"
"tree" "tree"
@ -284,18 +277,18 @@ in
One of 'list' or 'tree' One of 'list' or 'tree'
''; '';
treeOptions = tree_options =
let let
commonDesc = "Only applies when listing_style is 'tree'"; commonDesc = "Only applies when listing_style is 'tree'";
in in
{ {
flattenDirs = mkBool true '' flattenDirs = defaultNullOpts.mkBool.true ''
Flatten dirs that only contain one single dir Flatten dirs that only contain one single dir
${commonDesc} ${commonDesc}
''; '';
folderStatuses = folderStatuses =
mkEnum defaultNullOpts.mkEnum
[ [
"never" "never"
"only_folded" "only_folded"
@ -307,17 +300,17 @@ in
${commonDesc} ${commonDesc}
''; '';
}; };
winConfig = mkWinConfig { win_config = mkWinConfig {
type = "split"; type = "split";
width = 35; width = 35;
position = "left"; position = "left";
}; };
}; };
fileHistoryPanel = { file_history_panel = {
logOptions = logOptions =
let let
mkNullStr = helpers.mkNullOrOption types.str; mkNullStr = lib.nixvim.mkNullOrOption types.str;
mkNullBool = helpers.mkNullOrOption types.bool; mkNullBool = lib.nixvim.mkNullOrOption types.bool;
logOptions = { logOptions = {
base = mkNullStr '' base = mkNullStr ''
Specify a base git rev from which the right side of the diff Specify a base git rev from which the right side of the diff
@ -325,11 +318,11 @@ in
local version of the file. local version of the file.
''; '';
revRange = mkNullStr '' rev_range = mkNullStr ''
List only the commits in the specified revision range. List only the commits in the specified revision range.
''; '';
pathArgs = mkListOf types.str [ ] '' path_args = defaultNullOpts.mkListOf.types.str [ ] ''
Limit the target files to only the files matching the given Limit the target files to only the files matching the given
path arguments (git pathspec is supported). path arguments (git pathspec is supported).
''; '';
@ -338,11 +331,11 @@ in
Follow renames (only for single file). Follow renames (only for single file).
''; '';
firstParent = mkNullBool '' first_parent = mkNullBool ''
Follow only the first parent upon seeing a merge commit. Follow only the first parent upon seeing a merge commit.
''; '';
showPulls = mkNullBool '' show_pulls = mkNullBool ''
Show merge commits that are not TREESAME to its first parent, Show merge commits that are not TREESAME to its first parent,
but are to a later parent. but are to a later parent.
''; '';
@ -359,7 +352,7 @@ in
List only merge commits. List only merge commits.
''; '';
noMerges = mkNullBool '' no_merges = mkNullBool ''
List no merge commits. List no merge commits.
''; '';
@ -367,35 +360,35 @@ in
List commits in reverse order. List commits in reverse order.
''; '';
cherryPick = mkNullBool '' cherry_pick = mkNullBool ''
Omit commits that introduce the same change as another commit Omit commits that introduce the same change as another commit
on the "other side" when the set of commits are limited with on the "other side" when the set of commits are limited with
symmetric difference. symmetric difference.
''; '';
leftOnly = mkNullBool '' left_only = mkNullBool ''
List only the commits on the left side of a symmetric List only the commits on the left side of a symmetric
difference. difference.
''; '';
rightOnly = mkNullBool '' right_only = mkNullBool ''
List only the commits on the right side of a symmetric List only the commits on the right side of a symmetric
difference. difference.
''; '';
maxCount = helpers.mkNullOrOption types.int '' max_count = lib.nixvim.mkNullOrOption types.int ''
Limit the number of commits. Limit the number of commits.
''; '';
l = mkListOf types.str [ ] '' l = defaultNullOpts.mkListOf.types.str [ ] ''
`{ ("<start>,<end>:<file>" | ":<funcname>:<file>")... }` `{ ("<start>,<end>:<file>" | ":<funcname>:<file>")... }`
Trace the evolution of the line range given by <start>,<end>, Trace the evolution of the line range given by <start>,<end>,
or by the function name regex <funcname>, within the <file>. or by the function name regex <funcname>, within the <file>.
''; '';
diffMerges = diff_merges =
helpers.mkNullOrOption lib.nixvim.mkNullOrOption
(types.enum [ (types.enum [
"off" "off"
"on" "on"
@ -434,43 +427,43 @@ in
in in
{ {
git = { git = {
singleFile = logOptions; single_file = logOptions;
multiFile = logOptions; multi_file = logOptions;
}; };
hg = { hg = {
singleFile = logOptions; single_file = logOptions;
multiFile = logOptions; multi_file = logOptions;
}; };
}; };
winConfig = mkWinConfig { win_config = mkWinConfig {
type = "split"; type = "split";
height = 16; height = 16;
position = "bottom"; position = "bottom";
}; };
}; };
commitLogPanel = { commit_log_panel = {
winConfig = mkWinConfig { type = "float"; }; winConfig = mkWinConfig { type = "float"; };
}; };
defaultArgs = default_args =
let let
commonDesc = "Default args prepended to the arg-list for the listed commands"; commonDesc = "Default args prepended to the arg-list for the listed commands";
in in
{ {
diffviewOpen = mkListOf types.str [ ] commonDesc; DiffviewOpen = defaultNullOpts.mkListOf.types.str [ ] commonDesc;
diffviewFileHistory = mkListOf types.str [ ] commonDesc; DiffviewFileHistory = defaultNullOpts.mkListOf.types.str [ ] commonDesc;
}; };
hooks = hooks =
let let
mkNullStr = helpers.mkNullOrOption types.str; mkNullStr = lib.nixvim.mkNullOrOption types.str;
in in
{ {
viewOpened = mkNullStr '' view_opened = mkNullStr ''
{view_opened} (`fun(view: View)`) {view_opened} (`fun(view: View)`)
Emitted after a new view has been opened. It's called after Emitted after a new view has been opened. It's called after
@ -482,7 +475,7 @@ in
The `View` instance that was opened. The `View` instance that was opened.
''; '';
viewClosed = mkNullStr '' view_closed = mkNullStr ''
{view_closed} (`fun(view: View)`) {view_closed} (`fun(view: View)`)
Emitted after closing a view. Emitted after closing a view.
@ -492,7 +485,7 @@ in
The `View` instance that was closed. The `View` instance that was closed.
''; '';
viewEnter = mkNullStr '' view_enter = mkNullStr ''
{view_enter} (`fun(view: View)`) {view_enter} (`fun(view: View)`)
Emitted just after entering the tabpage of a view. Emitted just after entering the tabpage of a view.
@ -502,7 +495,7 @@ in
The `View` instance that was entered. The `View` instance that was entered.
''; '';
viewLeave = mkNullStr '' view_leave = mkNullStr ''
{view_leave} (`fun(view: View)`) {view_leave} (`fun(view: View)`)
Emitted just before leaving the tabpage of a view. Emitted just before leaving the tabpage of a view.
@ -512,7 +505,7 @@ in
The `View` instance that's about to be left. The `View` instance that's about to be left.
''; '';
viewPostLayout = mkNullStr '' view_post_layout = mkNullStr ''
{view_post_layout} (`fun(view: View)`) {view_post_layout} (`fun(view: View)`)
Emitted after the window layout in a view has been adjusted. Emitted after the window layout in a view has been adjusted.
@ -522,7 +515,7 @@ in
The `View` whose layout was adjusted. The `View` whose layout was adjusted.
''; '';
diffBufRead = mkNullStr '' diff_buf_read = mkNullStr ''
{diff_buf_read} (`fun(bufnr: integer, ctx: table)`) {diff_buf_read} (`fun(bufnr: integer, ctx: table)`)
Emitted after a new diff buffer is ready (the first time it's Emitted after a new diff buffer is ready (the first time it's
@ -547,7 +540,7 @@ in
The name of the current layout. The name of the current layout.
''; '';
diffBufWinEnter = mkNullStr '' diff_buf_win_enter = mkNullStr ''
{diff_buf_win_enter} (`fun(bufnr: integer, winid: integer, ctx: table)`) {diff_buf_win_enter} (`fun(bufnr: integer, winid: integer, ctx: table)`)
Emitted after a diff buffer is displayed in a window. Emitted after a diff buffer is displayed in a window.
@ -577,26 +570,26 @@ in
let let
keymapList = keymapList =
desc: desc:
mkOption { lib.mkOption {
type = types.listOf ( type = types.listOf (
types.submodule { types.submodule {
options = { options = {
mode = mkOption { mode = lib.mkOption {
type = types.str; type = types.str;
description = "mode to bind keybinding to"; description = "mode to bind keybinding to";
example = "n"; example = "n";
}; };
key = mkOption { key = lib.mkOption {
type = types.str; type = types.str;
description = "key to bind keybinding to"; description = "key to bind keybinding to";
example = "<tab>"; example = "<tab>";
}; };
action = mkOption { action = lib.mkOption {
type = types.str; type = types.str;
description = "action for keybinding"; description = "action for keybinding";
example = "action.select_next_entry"; example = "action.select_next_entry";
}; };
description = mkOption { description = lib.mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
description = "description for keybinding"; description = "description for keybinding";
default = null; default = null;
@ -620,7 +613,7 @@ in
}; };
in in
{ {
disableDefaults = mkBool false '' disable_defaults = defaultNullOpts.mkBool.false ''
Disable the default keymaps. Disable the default keymaps.
''; '';
@ -642,163 +635,29 @@ in
diff4 = keymapList '' diff4 = keymapList ''
Mappings in 4-way diff layouts Mappings in 4-way diff layouts
''; '';
filePanel = keymapList '' file_panel = keymapList ''
Mappings in file panel. Mappings in file panel.
''; '';
fileHistoryPanel = keymapList '' file_history_panel = keymapList ''
Mappings in file history panel. Mappings in file history panel.
''; '';
optionPanel = keymapList '' option_panel = keymapList ''
Mappings in options panel. Mappings in options panel.
''; '';
helpPanel = keymapList '' help_panel = keymapList ''
Mappings in help panel. Mappings in help panel.
''; '';
}; };
disableDefaultKeymaps = mkBool false '' disable_default_keymaps = defaultNullOpts.mkBool.false ''
Disable the default keymaps; Disable the default keymaps;
''; '';
}; };
config = extraConfig =
cfg:
let let
setupOptions = with cfg; { setupOptions = with cfg; {
diff_binaries = diffBinaries;
enhanced_diff_hl = enhancedDiffHl;
git_cmd = gitCmd;
hg_cmd = hgCmd;
use_icons = useIcons;
show_help_hints = showHelpHints;
watch_index = watchIndex;
icons = {
folder_closed = icons.folderClosed;
folder_open = icons.folderOpen;
};
signs = with signs; {
fold_closed = foldClosed;
fold_open = foldOpen;
inherit done;
};
view = with view; {
default = with default; {
inherit layout;
winbar_info = winbarInfo;
};
merge_tool = with mergeTool; {
inherit layout;
disable_diagnostics = disableDiagnostics;
winbar_info = winbarInfo;
};
file_history = with fileHistory; {
inherit layout;
winbar_info = winbarInfo;
};
};
file_panel = with filePanel; {
listing_style = listingStyle;
tree_options = with treeOptions; {
flatten_dirs = flattenDirs;
folder_statuses = folderStatuses;
};
win_config = with winConfig; {
inherit type;
inherit width;
inherit height;
inherit position;
inherit relative;
inherit win;
win_opts = winOpts;
};
};
file_history_panel = with fileHistoryPanel; {
log_options =
with logOptions;
let
setupLogOptions =
opts: with opts; {
inherit base;
rev_range = revRange;
path_args = pathArgs;
inherit follow;
first_parent = firstParent;
show_pulls = showPulls;
inherit reflog;
inherit all;
inherit merges;
no_merges = noMerges;
inherit reverse;
cherry_pick = cherryPick;
left_only = leftOnly;
right_only = rightOnly;
max_count = maxCount;
L = l;
diff_merges = diffMerges;
inherit author;
inherit grep;
G = g;
S = s;
};
in
{
git = with git; {
single_file = setupLogOptions singleFile;
multi_file = setupLogOptions multiFile;
};
hg = with hg; {
single_file = setupLogOptions singleFile;
multi_file = setupLogOptions multiFile;
};
};
win_config = with winConfig; {
inherit type;
inherit width;
inherit height;
inherit position;
inherit relative;
inherit win;
win_opts = winOpts;
};
};
commit_log_panel = with commitLogPanel; {
win_config = with winConfig; {
inherit type;
inherit width;
inherit height;
inherit position;
inherit relative;
inherit win;
win_opts = winOpts;
};
};
default_args = with defaultArgs; {
DiffviewOpen = diffviewOpen;
DiffviewFileHistory = diffviewFileHistory;
};
hooks = with hooks; {
view_opened = viewOpened;
view_closed = viewClosed;
view_enter = viewEnter;
view_leave = viewLeave;
view_post_layout = viewPostLayout;
diff_buf_read = diffBufRead;
diff_buf_win_enter = diffBufWinEnter;
};
keymaps = keymaps =
with keymaps; with keymaps;
let let
@ -822,20 +681,12 @@ in
}; };
}; };
in in
mkIf cfg.enable { {
# TODO: added 2024-09-20 remove after 24.11
plugins.web-devicons = mkIf (
!(
config.plugins.mini.enable
&& config.plugins.mini.modules ? icons
&& config.plugins.mini.mockDevIcons
)
) { enable = mkOverride 1490 true; };
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require("diffview").setup(${lib.nixvim.toLuaObject setupOptions})
'';
}; };
inherit (import ./deprecations.nix { inherit lib; })
imports
optionsRenamedToSettings
deprecateExtraOptions
;
} }

View file

@ -0,0 +1,196 @@
{
# TODO: added 2024-09-04 remove after 24.11
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"diffBinaries"
"enhancedDiffHl"
"gitCmd"
"hgCmd"
"useIcons"
"showHelpHints"
"watchIndex"
[
"icons"
"folderClosed"
]
[
"icons"
"folderOpen"
]
[
"signs"
"folderClosed"
]
[
"signs"
"folderOpen"
]
[
"signs"
"done"
]
[
"view"
"default"
"layout"
]
[
"view"
"default"
"disableDiagnostics"
]
[
"view"
"default"
"winbarInfo"
]
[
"view"
"mergeTool"
"layout"
]
[
"view"
"mergeTool"
"disableDiagnostics"
]
[
"view"
"mergeTool"
"winbarInfo"
]
[
"filePanel"
"listingStyle"
]
[
"filePanel"
"treeOptions"
"flattenDirs"
]
[
"filePanel"
"treeOptions"
"folderStatuses"
]
[
"filePanel"
"winConfig"
"type"
]
[
"filePanel"
"winConfig"
"width"
]
[
"filePanel"
"winConfig"
"height"
]
[
"filePanel"
"winConfig"
"position"
]
[
"filePanel"
"winConfig"
"relative"
]
[
"filePanel"
"winConfig"
"win"
]
[
"filePanel"
"winConfig"
"winOpts"
]
[
"hooks"
"viewOpened"
]
[
"hooks"
"viewClosed"
]
[
"hooks"
"viewEnter"
]
[
"hooks"
"viewLeave"
]
[
"hooks"
"viewPostLayout"
]
[
"hooks"
"diffBufRead"
]
[
"hooks"
"diffBufWinEnter"
]
[
"fileHistoryPanel"
"logOptions"
"git"
"multiFile"
]
[
"fileHistoryPanel"
"logOptions"
"git"
"singleFile"
]
[
"fileHistoryPanel"
"logOptions"
"hg"
"multiFile"
]
[
"fileHistoryPanel"
"logOptions"
"hg"
"singleFile"
]
(map
(optionName: [
"fileHistoryPanel"
"logOptions"
"git"
"singleFile"
optionName
])
[
"base"
"revRange"
"pathArgs"
"follow"
"firstParent"
"showPulls"
"reflog"
"all"
"merges"
"noMerges"
"reverse"
"cherryPick"
"leftOnly"
"rightOnly"
"maxCount"
"l"
"diffMerges"
"author"
"grep"
"g"
"s"
]
)
];
}