nix-community.nixvim/plugins/by-name/diffview/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

693 lines
20 KiB
Nix
Raw Normal View History

2023-07-06 09:01:07 +02:00
{
lib,
config,
2023-07-06 09:01:07 +02:00
...
}:
let
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "diffview";
packPathName = "diffview.nvim";
package = "diffview-nvim";
2023-07-06 09:01:07 +02:00
maintainers = [ lib.maintainers.khaneliman ];
2023-07-06 09:01:07 +02:00
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.
'';
2023-07-06 09:01:07 +02:00
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"`.
2023-07-06 09:01:07 +02:00
'';
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"`.
2023-07-06 09:01:07 +02:00
'';
position =
defaultNullOpts.mkEnum
[
"left"
"top"
"right"
"bottom"
]
position
''
Determines where the panel is positioned (only when
`type="split"`).
'';
2023-07-06 09:01:07 +02:00
relative =
defaultNullOpts.mkEnum
[
"editor"
"win"
]
"editor"
''
Determines what the `position` is relative to (when
`type="split"`).
'';
2023-07-06 09:01:07 +02:00
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 ''
2023-07-06 09:01:07 +02:00
Show diffs for binaries
'';
enhanced_diff_hl = defaultNullOpts.mkBool false ''
2023-07-06 09:01:07 +02:00
See ':h diffview-config-enhanced_diff_hl'
'';
git_cmd = defaultNullOpts.mkListOf types.str [ "git" ] ''
2023-07-06 09:01:07 +02:00
The git executable followed by default args.
'';
hg_cmd = defaultNullOpts.mkListOf types.str [ "hg" ] ''
2023-07-06 09:01:07 +02:00
The hg executable followed by default args.
'';
use_icons = lib.lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.bool;
description = "Requires nvim-web-devicons";
default = true;
};
show_help_hints = defaultNullOpts.mkBool true ''
2023-07-06 09:01:07 +02:00
Show hints for how to open the help panel
'';
watch_index = defaultNullOpts.mkBool.true ''
2023-07-06 09:01:07 +02:00
Update views and index buffers when the git index changes.
'';
icons = {
folder_closed = defaultNullOpts.mkStr "" ''
2023-07-06 09:01:07 +02:00
Only applies when use_icons is true.
'';
folder_open = defaultNullOpts.mkStr "" ''
2023-07-06 09:01:07 +02:00
Only applies when use_icons is true.
'';
};
signs = {
fold_closed = defaultNullOpts.mkStr "" "";
2023-07-06 09:01:07 +02:00
fold_open = defaultNullOpts.mkStr "" "";
2023-07-06 09:01:07 +02:00
done = defaultNullOpts.mkStr "" "";
2023-07-06 09:01:07 +02:00
};
view =
let
layoutsDescription = ''
Configure the layout and behavior of different types of views.
For more info, see ':h diffview-config-view.x.layout'.
'';
diff2HorizontalDescription = ''
diff2_horizontal:
| A | B |
'';
diff2VerticalDescription = ''
diff2_vertical:
A
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
B
'';
2024-05-05 19:39:35 +02:00
in
{
2023-07-06 09:01:07 +02:00
default = {
layout =
defaultNullOpts.mkEnum
2023-07-06 09:01:07 +02:00
[
"diff2_horizontal"
"diff2_vertical"
]
"diff2_horizontal"
''
Config for changed files, and staged files in diff views.
${layoutsDescription}
- A: Old state
- B: New state
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
${diff2HorizontalDescription}
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
${diff2VerticalDescription}
2024-05-05 19:39:35 +02:00
'';
winbarInfo = defaultNullOpts.mkBool.false ''
2023-07-06 09:01:07 +02:00
See ':h diffview-config-view.x.winbar_info'
'';
2024-05-05 19:39:35 +02:00
};
2023-07-06 09:01:07 +02:00
merge_tool = {
2024-05-05 19:39:35 +02:00
layout =
defaultNullOpts.mkEnum
2024-05-05 19:39:35 +02:00
[
2023-07-06 09:01:07 +02:00
"diff1_plain"
"diff3_horizontal"
"diff3_vertical"
"diff3_mixed"
"diff4_mixed"
2024-05-05 19:39:35 +02:00
]
2023-07-06 09:01:07 +02:00
"diff3_horizontal"
''
Config for conflicted files in diff views during a merge or rebase.
${layoutsDescription}
- A: OURS (current branch)
- B: LOCAL (the file as it currently exists on disk)
- C: THEIRS (incoming branch)
- D: BASE (common ancestor)
diff1_plain:
2024-05-05 19:39:35 +02:00
B
2023-07-06 09:01:07 +02:00
diff3_horizontal:
A | B | C
diff3_vertical:
A
2024-05-05 19:39:35 +02:00
B
2023-07-06 09:01:07 +02:00
C
diff3_mixed:
A | C
2024-05-05 19:39:35 +02:00
B
2023-07-06 09:01:07 +02:00
diff4_mixed:
A | D | C
2024-05-05 19:39:35 +02:00
B
2023-07-06 09:01:07 +02:00
'';
disable_diagnostics = defaultNullOpts.mkBool.true ''
2023-07-06 09:01:07 +02:00
Temporarily disable diagnostics for conflict buffers while in the view.
'';
winbar_info = defaultNullOpts.mkBool.true ''
2023-07-06 09:01:07 +02:00
See ':h diffview-config-view.x.winbar_info'
'';
2024-05-05 19:39:35 +02:00
};
2023-07-06 09:01:07 +02:00
file_history = {
2023-07-06 09:01:07 +02:00
layout =
defaultNullOpts.mkEnum
2024-05-05 19:39:35 +02:00
[
2023-07-06 09:01:07 +02:00
"diff2_horizontal"
"diff2_vertical"
2024-05-05 19:39:35 +02:00
]
2023-07-06 09:01:07 +02:00
"diff2_horizontal"
2024-05-05 19:39:35 +02:00
''
2023-07-06 09:01:07 +02:00
Config for changed files in file history views.
${layoutsDescription}
- A: Old state
- B: New state
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
${diff2HorizontalDescription}
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
${diff2VerticalDescription}
2024-05-05 19:39:35 +02:00
'';
winbar_info = defaultNullOpts.mkBool.false ''
2023-07-06 09:01:07 +02:00
See ':h diffview-config-view.x.winbar_info'
'';
2024-05-05 19:39:35 +02:00
};
};
2023-07-06 09:01:07 +02:00
file_panel = {
listing_style =
defaultNullOpts.mkEnum
2024-05-05 19:39:35 +02:00
[
"list"
2023-07-06 09:01:07 +02:00
"tree"
2024-05-05 19:39:35 +02:00
]
"tree"
2023-07-06 09:01:07 +02:00
''
One of 'list' or 'tree'
'';
tree_options =
2024-05-05 19:39:35 +02:00
let
2023-07-06 09:01:07 +02:00
commonDesc = "Only applies when listing_style is 'tree'";
2024-05-05 19:39:35 +02:00
in
{
flattenDirs = defaultNullOpts.mkBool.true ''
2024-03-07 19:44:13 +01:00
Flatten dirs that only contain one single dir
2023-07-06 09:01:07 +02:00
${commonDesc}
'';
folderStatuses =
defaultNullOpts.mkEnum
2024-05-05 19:39:35 +02:00
[
"never"
2023-07-06 09:01:07 +02:00
"only_folded"
2024-05-05 19:39:35 +02:00
"always"
]
2023-07-06 09:01:07 +02:00
"only_folded"
2024-05-05 19:39:35 +02:00
''
2023-07-06 09:01:07 +02:00
One of 'never', 'only_folded' or 'always'.
${commonDesc}
'';
};
win_config = mkWinConfig {
type = "split";
width = 35;
position = "left";
};
2024-05-05 19:39:35 +02:00
};
file_history_panel = {
2023-07-06 09:01:07 +02:00
logOptions =
2024-05-05 19:39:35 +02:00
let
mkNullStr = lib.nixvim.mkNullOrOption types.str;
mkNullBool = lib.nixvim.mkNullOrOption types.bool;
2023-07-06 09:01:07 +02:00
logOptions = {
base = mkNullStr ''
Specify a base git rev from which the right side of the diff
will be created. Use the special value `LOCAL` to use the
local version of the file.
2024-05-05 19:39:35 +02:00
'';
rev_range = mkNullStr ''
2023-07-06 09:01:07 +02:00
List only the commits in the specified revision range.
2024-05-05 19:39:35 +02:00
'';
path_args = defaultNullOpts.mkListOf.types.str [ ] ''
2023-07-06 09:01:07 +02:00
Limit the target files to only the files matching the given
path arguments (git pathspec is supported).
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
follow = mkNullBool ''
Follow renames (only for single file).
2024-05-05 19:39:35 +02:00
'';
first_parent = mkNullBool ''
2023-07-06 09:01:07 +02:00
Follow only the first parent upon seeing a merge commit.
2024-05-05 19:39:35 +02:00
'';
show_pulls = mkNullBool ''
2023-07-06 09:01:07 +02:00
Show merge commits that are not TREESAME to its first parent,
but are to a later parent.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
reflog = mkNullBool ''
Include all reachable objects mentioned by reflogs.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
all = mkNullBool ''
Include all refs.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
merges = mkNullBool ''
List only merge commits.
2024-05-05 19:39:35 +02:00
'';
no_merges = mkNullBool ''
2023-07-06 09:01:07 +02:00
List no merge commits.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
reverse = mkNullBool ''
List commits in reverse order.
2024-05-05 19:39:35 +02:00
'';
cherry_pick = mkNullBool ''
2023-07-06 09:01:07 +02:00
Omit commits that introduce the same change as another commit
on the "other side" when the set of commits are limited with
symmetric difference.
2024-05-05 19:39:35 +02:00
'';
left_only = mkNullBool ''
2023-07-06 09:01:07 +02:00
List only the commits on the left side of a symmetric
difference.
2024-05-05 19:39:35 +02:00
'';
right_only = mkNullBool ''
2023-07-06 09:01:07 +02:00
List only the commits on the right side of a symmetric
difference.
2024-05-05 19:39:35 +02:00
'';
max_count = lib.nixvim.mkNullOrOption types.int ''
2023-07-06 09:01:07 +02:00
Limit the number of commits.
2024-05-05 19:39:35 +02:00
'';
l = defaultNullOpts.mkListOf.types.str [ ] ''
2023-07-06 09:01:07 +02:00
`{ ("<start>,<end>:<file>" | ":<funcname>:<file>")... }`
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
Trace the evolution of the line range given by <start>,<end>,
or by the function name regex <funcname>, within the <file>.
2024-05-05 19:39:35 +02:00
'';
diff_merges =
lib.nixvim.mkNullOrOption
2023-07-06 09:01:07 +02:00
(types.enum [
2024-05-05 19:39:35 +02:00
"off"
"on"
2023-07-06 09:01:07 +02:00
"first-parent"
2024-05-05 19:39:35 +02:00
"separate"
2023-07-06 09:01:07 +02:00
"combined"
"dense-combined"
2024-05-05 19:39:35 +02:00
"remerge"
])
''
2023-07-06 09:01:07 +02:00
Determines how merge commits are treated.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
author = mkNullStr ''
Limit the commits output to ones with author/committer header
lines that match the specified pattern (regular expression).
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
grep = mkNullStr ''
Limit the commits output to ones with log message that matches
the specified pattern (regular expression).
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
g = mkNullStr ''
Look for differences whose patch text contains added/removed
lines that match the specified pattern (extended regular
expression).
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
s = mkNullStr ''
2024-03-07 19:44:13 +01:00
Look for differences that change the number of occurrences of
2023-07-06 09:01:07 +02:00
the specified pattern (extended regular expression) in a
2024-05-05 19:39:35 +02:00
file.
'';
};
in
{
git = {
single_file = logOptions;
2024-05-05 19:39:35 +02:00
multi_file = logOptions;
2024-05-05 19:39:35 +02:00
};
hg = {
single_file = logOptions;
2023-07-06 09:01:07 +02:00
multi_file = logOptions;
2024-05-05 19:39:35 +02:00
};
2023-07-06 09:01:07 +02:00
};
win_config = mkWinConfig {
type = "split";
height = 16;
position = "bottom";
};
2023-07-06 09:01:07 +02:00
};
commit_log_panel = {
winConfig = mkWinConfig { type = "float"; };
2023-07-06 09:01:07 +02:00
};
default_args =
2023-07-06 09:01:07 +02:00
let
commonDesc = "Default args prepended to the arg-list for the listed commands";
in
{
DiffviewOpen = defaultNullOpts.mkListOf.types.str [ ] commonDesc;
2023-07-06 09:01:07 +02:00
DiffviewFileHistory = defaultNullOpts.mkListOf.types.str [ ] commonDesc;
2023-07-06 09:01:07 +02:00
};
2024-05-05 19:39:35 +02:00
hooks =
let
mkNullStr = lib.nixvim.mkNullOrOption types.str;
2024-05-05 19:39:35 +02:00
in
{
view_opened = mkNullStr ''
2023-07-06 09:01:07 +02:00
{view_opened} (`fun(view: View)`)
Emitted after a new view has been opened. It's called after
initializing the layout in the new tabpage (all windows are
2024-05-05 19:39:35 +02:00
ready).
2023-07-06 09:01:07 +02:00
Callback Parameters:
{view} (`View`)
The `View` instance that was opened.
'';
view_closed = mkNullStr ''
2023-07-06 09:01:07 +02:00
{view_closed} (`fun(view: View)`)
Emitted after closing a view.
Callback Parameters:
{view} (`View`)
The `View` instance that was closed.
'';
view_enter = mkNullStr ''
2023-07-06 09:01:07 +02:00
{view_enter} (`fun(view: View)`)
Emitted just after entering the tabpage of a view.
Callback Parameters:
{view} (`View`)
The `View` instance that was entered.
'';
view_leave = mkNullStr ''
2023-07-06 09:01:07 +02:00
{view_leave} (`fun(view: View)`)
Emitted just before leaving the tabpage of a view.
Callback Parameters:
{view} (`View`)
The `View` instance that's about to be left.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
view_post_layout = mkNullStr ''
2023-07-06 09:01:07 +02:00
{view_post_layout} (`fun(view: View)`)
Emitted after the window layout in a view has been adjusted.
Callback Parameters:
{view} (`View`)
The `View` whose layout was adjusted.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
diff_buf_read = mkNullStr ''
2023-07-06 09:01:07 +02:00
{diff_buf_read} (`fun(bufnr: integer, ctx: table)`)
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
Emitted after a new diff buffer is ready (the first time it's
created and loaded into a window). Diff buffers are all
buffers with |diff-mode| enabled. That includes buffers of
local files (not created from git).
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
This is always called with the new buffer as the current
buffer and the correct diff window as the current window such
that |:setlocal| will apply settings to the relevant buffer /
window.
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
Callback Parameters:
{bufnr} (`integer`)
The buffer number of the new buffer.
{ctx} (`table`)
{symbol} (string)
A symbol that identifies the window's position in
the layout. These symbols correspond with the
figures under |diffview-config-view.x.layout|.
{layout_name} (string)
The name of the current layout.
2024-05-05 19:39:35 +02:00
'';
2023-07-06 09:01:07 +02:00
diff_buf_win_enter = mkNullStr ''
2023-07-06 09:01:07 +02:00
{diff_buf_win_enter} (`fun(bufnr: integer, winid: integer, ctx: table)`)
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
Emitted after a diff buffer is displayed in a window.
2024-05-05 19:39:35 +02:00
2023-07-06 09:01:07 +02:00
This is always called with the new buffer as the current
buffer and the correct diff window as the current window such
that |:setlocal| will apply settings to the relevant buffer /
2024-05-05 19:39:35 +02:00
window.
2023-07-06 09:01:07 +02:00
Callback Parameters:
{bufnr} (`integer`)
The buffer number of the new buffer.
{winid} (`integer`)
The window id of window inside which the buffer was
displayed.
{ctx} (`table`)
{symbol} (string)
A symbol that identifies the window's position in
the layout. These symbols correspond with the
figures under |diffview-config-view.x.layout|.
{layout_name} (string)
The name of the current layout.
'';
};
keymaps =
let
keymapList =
desc:
lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.listOf (
types.submodule {
options = {
mode = lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.str;
description = "mode to bind keybinding to";
example = "n";
};
key = lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.str;
description = "key to bind keybinding to";
example = "<tab>";
};
action = lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.str;
description = "action for keybinding";
example = "action.select_next_entry";
};
description = lib.mkOption {
2023-07-06 09:01:07 +02:00
type = types.nullOr types.str;
description = "description for keybinding";
default = null;
};
};
}
);
description = ''
List of keybindings.
${desc}
'';
default = [ ];
example = [
{
mode = "n";
key = "<tab>";
action = "actions.select_next_entry";
description = "Open the diff for the next file";
}
];
};
in
{
disable_defaults = defaultNullOpts.mkBool.false ''
2023-07-06 09:01:07 +02:00
Disable the default keymaps.
'';
view = keymapList ''
The `view` bindings are active in the diff buffers, only when the current
tabpage is a Diffview.
'';
diff1 = keymapList ''
Mappings in single window diff layouts
'';
diff2 = keymapList ''
Mappings in 2-way diff layouts
'';
diff3 = keymapList ''
Mappings in 3-way diff layouts
'';
diff4 = keymapList ''
Mappings in 4-way diff layouts
'';
file_panel = keymapList ''
2023-07-06 09:01:07 +02:00
Mappings in file panel.
'';
file_history_panel = keymapList ''
2023-07-06 09:01:07 +02:00
Mappings in file history panel.
'';
option_panel = keymapList ''
2023-07-06 09:01:07 +02:00
Mappings in options panel.
'';
help_panel = keymapList ''
2023-07-06 09:01:07 +02:00
Mappings in help panel.
'';
};
disable_default_keymaps = defaultNullOpts.mkBool.false ''
2023-07-06 09:01:07 +02:00
Disable the default keymaps;
'';
};
extraConfig =
cfg:
2023-07-06 09:01:07 +02:00
let
setupOptions = with cfg; {
keymaps =
with keymaps;
let
convertToKeybinding = attr: [
attr.mode
attr.key
attr.action
{ "desc" = attr.description; }
];
in
{
view = map convertToKeybinding view;
diff1 = map convertToKeybinding diff1;
diff2 = map convertToKeybinding diff2;
diff3 = map convertToKeybinding diff3;
diff4 = map convertToKeybinding diff4;
file_panel = map convertToKeybinding filePanel;
file_history_panel = map convertToKeybinding fileHistoryPanel;
option_panel = map convertToKeybinding optionPanel;
help_panel = map convertToKeybinding helpPanel;
2024-05-05 19:39:35 +02:00
};
2023-07-06 09:01:07 +02:00
};
in
{
2023-07-06 09:01:07 +02:00
};
inherit (import ./deprecations.nix { inherit lib; })
imports
optionsRenamedToSettings
deprecateExtraOptions
;
2023-07-06 09:01:07 +02:00
}