plugins/nvim-tree: fix regressions introduced in #213 + tests (#241)

This commit is contained in:
Gaétan Lepage 2023-03-13 10:58:03 +01:00 committed by GitHub
parent c34c941c8f
commit 1ac27edf2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 699 additions and 378 deletions

View file

@ -7,6 +7,7 @@
with lib; let with lib; let
cfg = config.plugins.nvim-tree; cfg = config.plugins.nvim-tree;
helpers = import ../helpers.nix {inherit lib;}; helpers = import ../helpers.nix {inherit lib;};
ifNonNull' = helpers.ifNonNull';
optionWarnings = import ../../lib/option-warnings.nix args; optionWarnings = import ../../lib/option-warnings.nix args;
basePluginPath = ["plugins" "nvim-tree"]; basePluginPath = ["plugins" "nvim-tree"];
@ -36,10 +37,6 @@ in {
option = basePluginPath ++ ["updateCwd"]; option = basePluginPath ++ ["updateCwd"];
newOption = basePluginPath ++ ["syncRootWithCwd"]; newOption = basePluginPath ++ ["syncRootWithCwd"];
}) })
(optionWarnings.mkRenamedOption {
option = basePluginPath ++ ["updateFocusedFile" "updateCwd"];
newOption = basePluginPath ++ ["updateFocusedFile" "updateRoot"];
})
(optionWarnings.mkRenamedOption { (optionWarnings.mkRenamedOption {
option = basePluginPath ++ ["openOnTab"]; option = basePluginPath ++ ["openOnTab"];
newOption = basePluginPath ++ ["tab" "sync" "open"]; newOption = basePluginPath ++ ["tab" "sync" "open"];
@ -48,6 +45,10 @@ in {
option = basePluginPath ++ ["updateToBufDir"]; option = basePluginPath ++ ["updateToBufDir"];
newOption = basePluginPath ++ ["hijackDirectories"]; newOption = basePluginPath ++ ["hijackDirectories"];
}) })
(optionWarnings.mkDeprecatedOption {
option = basePluginPath ++ ["removeKeymaps"];
alternative = basePluginPath ++ ["onAttach"];
})
]; ];
options.plugins.nvim-tree = options.plugins.nvim-tree =
@ -172,9 +173,12 @@ in {
Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
''; '';
hijackDirectories = { hijackDirectories =
helpers.mkCompositeOption
"Hijacks new directory buffers when they are opened (`:e dir`)."
{
enable = helpers.defaultNullOpts.mkBool true '' enable = helpers.defaultNullOpts.mkBool true ''
Hijacks new directory buffers when they are opened (`:e dir`). Enable the feature.
Disable this option if you use vim-dirvish or dirbuf.nvim. Disable this option if you use vim-dirvish or dirbuf.nvim.
If `hijackNetrw` and `disableNetrw` are `false`, this feature will be disabled. If `hijackNetrw` and `disableNetrw` are `false`, this feature will be disabled.
''; '';
@ -184,11 +188,14 @@ in {
''; '';
}; };
updateFocusedFile = { updateFocusedFile =
enable = helpers.defaultNullOpts.mkBool false '' helpers.mkCompositeOption
''
Update the focused file on `BufEnter`, un-collapses the folders recursively until it finds Update the focused file on `BufEnter`, un-collapses the folders recursively until it finds
the file. the file.
''; ''
{
enable = helpers.defaultNullOpts.mkBool false "Enable this feature.";
updateRoot = helpers.defaultNullOpts.mkBool false '' updateRoot = helpers.defaultNullOpts.mkBool false ''
Update the root directory of the tree if the file is not under current root directory. Update the root directory of the tree if the file is not under current root directory.
@ -198,15 +205,19 @@ in {
''; '';
ignoreList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' ignoreList = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" ''
List of buffer names and filetypes that will not update the root dir of the tree if the file List of buffer names and filetypes that will not update the root dir of the tree if the
isn't found under the current root directory. file isn't found under the current root directory.
Only relevant when `updateFocusedFile.updateRoot` and `updateFocusedFile.enable` are `true`. Only relevant when `updateFocusedFile.updateRoot` and `updateFocusedFile.enable` are
`true`.
''; '';
}; };
systemOpen = { systemOpen =
helpers.mkCompositeOption
"Open a file or directory in your preferred application."
{
cmd = helpers.defaultNullOpts.mkStr "" '' cmd = helpers.defaultNullOpts.mkStr "" ''
A custom command to open files or directory with. The open command itself.
Leave empty for OS specific default: Leave empty for OS specific default:
UNIX: `"xdg-open"` UNIX: `"xdg-open"`
@ -222,8 +233,9 @@ in {
''; '';
}; };
diagnostics = { diagnostics =
enable = helpers.defaultNullOpts.mkBool false '' helpers.mkCompositeOption
''
Show LSP and COC diagnostics in the signcolumn Show LSP and COC diagnostics in the signcolumn
Note that the modified sign will take precedence over the diagnostics signs. Note that the modified sign will take precedence over the diagnostics signs.
@ -233,7 +245,9 @@ in {
- `NvimTreeLspDiagnosticsWarning` - `NvimTreeLspDiagnosticsWarning`
- `NvimTreeLspDiagnosticsInformation` - `NvimTreeLspDiagnosticsInformation`
- `NvimTreeLspDiagnosticsHint` - `NvimTreeLspDiagnosticsHint`
''; ''
{
enable = helpers.defaultNullOpts.mkBool false "Enable/disable the feature.";
debounceDelay = helpers.defaultNullOpts.mkInt 50 '' debounceDelay = helpers.defaultNullOpts.mkInt 50 ''
Idle milliseconds between diagnostic event and update. Idle milliseconds between diagnostic event and update.
@ -248,8 +262,7 @@ in {
Only relevant when `diagnostics.showOnDirs` is `true Only relevant when `diagnostics.showOnDirs` is `true
''; '';
# Icons for diagnostic severity. icons = helpers.mkCompositeOption "Icons for diagnostic severity." {
icons = {
hint = helpers.defaultNullOpts.mkStr "" ""; hint = helpers.defaultNullOpts.mkStr "" "";
info = helpers.defaultNullOpts.mkStr "" ""; info = helpers.defaultNullOpts.mkStr "" "";
warning = helpers.defaultNullOpts.mkStr "" ""; warning = helpers.defaultNullOpts.mkStr "" "";
@ -258,14 +271,20 @@ in {
severity = let severity = let
severityEnum = ["error" "warn" "info" "hint"]; severityEnum = ["error" "warn" "info" "hint"];
in { in
helpers.mkCompositeOption
''
Severity for which the diagnostics will be displayed.
See |diagnostic-severity|.
''
{
min = helpers.defaultNullOpts.mkEnum severityEnum "hint" "Minimum severity."; min = helpers.defaultNullOpts.mkEnum severityEnum "hint" "Minimum severity.";
max = helpers.defaultNullOpts.mkEnum severityEnum "error" "Maximum severity."; max = helpers.defaultNullOpts.mkEnum severityEnum "error" "Maximum severity.";
}; };
}; };
git = { git = helpers.mkCompositeOption "Git integration with icons and colors." {
enable = helpers.defaultNullOpts.mkBool true "Git integration with icons and colors."; enable = helpers.defaultNullOpts.mkBool true "Enable / disable the feature.";
ignore = helpers.defaultNullOpts.mkBool true '' ignore = helpers.defaultNullOpts.mkBool true ''
Ignore files based on `.gitignore`. Requires `git.enable` to be `true`. Ignore files based on `.gitignore`. Requires `git.enable` to be `true`.
@ -286,10 +305,8 @@ in {
''; '';
}; };
modified = { modified = helpers.mkCompositeOption "Indicate which file have unsaved modification." {
enable = helpers.defaultNullOpts.mkBool false '' enable = helpers.defaultNullOpts.mkBool false "Enable / disable the feature.";
Indicate which file have unsaved modification.
'';
showOnDirs = helpers.defaultNullOpts.mkBool true '' showOnDirs = helpers.defaultNullOpts.mkBool true ''
Show modified indication on directory whose children are modified. Show modified indication on directory whose children are modified.
@ -301,14 +318,17 @@ in {
''; '';
}; };
filesystemWatchers = { filesystemWatchers =
enable = helpers.defaultNullOpts.mkBool true '' helpers.mkCompositeOption
''
Will use file system watcher (libuv fs_event) to watch the filesystem for changes. Will use file system watcher (libuv fs_event) to watch the filesystem for changes.
Using this will disable BufEnter / BufWritePost events in nvim-tree which were used to Using this will disable BufEnter / BufWritePost events in nvim-tree which were used to
update the whole tree. update the whole tree.
With this feature, the tree will be updated only for the appropriate folder change, With this feature, the tree will be updated only for the appropriate folder change,
resulting in better performance. resulting in better performance.
''; ''
{
enable = helpers.defaultNullOpts.mkBool true "Enable / disable the feature.";
debounceDelay = helpers.defaultNullOpts.mkInt 50 '' debounceDelay = helpers.defaultNullOpts.mkInt 50 ''
Idle milliseconds between filesystem change and action. Idle milliseconds between filesystem change and action.
@ -344,6 +364,8 @@ in {
eg. {"<C-o>", "<CR>", "o", "<Tab>"} eg. {"<C-o>", "<CR>", "o", "<Tab>"}
- Remove all default mappings by passing `true` - Remove all default mappings by passing `true`
- Ignore by passing `false` - Ignore by passing `false`
Deprecated: See https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach
''; '';
selectPrompts = helpers.defaultNullOpts.mkBool false '' selectPrompts = helpers.defaultNullOpts.mkBool false ''
@ -351,8 +373,7 @@ in {
Necessary when using a UI prompt decorator such as dressing.nvim or telescope-ui-select.nvim. Necessary when using a UI prompt decorator such as dressing.nvim or telescope-ui-select.nvim.
''; '';
# Window / buffer setup view = helpers.mkCompositeOption "Window / buffer setup." {
view = {
centralizeSelection = helpers.defaultNullOpts.mkBool false '' centralizeSelection = helpers.defaultNullOpts.mkBool false ''
When entering nvim-tree, reposition the view so that the current node is When entering nvim-tree, reposition the view so that the current node is
initially centralized, see |zz|. initially centralized, see |zz|.
@ -377,14 +398,15 @@ in {
types.str types.str
types.int types.int
(types.submodule { (types.submodule {
options = { options = let
min = helpers.defaultNullOpts.mkNullable (types.either types.str types.int) "30" '' strOrInt = types.either types.str types.int;
Minimum dynamic width. in {
''; min = helpers.defaultNullOpts.mkNullable strOrInt "30" "Minimum dynamic width.";
max = helpers.defaultNullOpts.mkNullable (types.either types.str types.int) "-1" ''
max = helpers.defaultNullOpts.mkNullable strOrInt "-1" ''
Maximum dynamic width, -1 for unbounded. Maximum dynamic width, -1 for unbounded.
''; '';
padding = helpers.defaultNullOpts.mkNullable (types.either types.str types.int) "1" '' padding = helpers.defaultNullOpts.mkNullable strOrInt "1" ''
Extra padding to the right. Extra padding to the right.
''; '';
}; };
@ -419,7 +441,7 @@ in {
Show diagnostic sign column. Value can be `"yes"`, `"auto"`, `"no"`. Show diagnostic sign column. Value can be `"yes"`, `"auto"`, `"no"`.
''; '';
mappings = { mappings = helpers.mkCompositeOption "Deprecated: please see |nvim-tree-mappings-legacy|." {
customOnly = helpers.defaultNullOpts.mkBool false '' customOnly = helpers.defaultNullOpts.mkBool false ''
Will use only the provided user mappings and not the default otherwise, Will use only the provided user mappings and not the default otherwise,
extends the default mappings with the provided user mappings. extends the default mappings with the provided user mappings.
@ -476,7 +498,7 @@ in {
key = "p"; key = "p";
action = "print_the_node_path"; action = "print_the_node_path";
action_cb = \'\' action_cb = \'\'
function print_node_path(node) function(node)
print(node.absolute_path) print(node.absolute_path)
end end
\'\'; \'\';
@ -486,7 +508,7 @@ in {
''; '';
}; };
float = { float = helpers.mkCompositeOption "Configuration options for floating window." {
enable = helpers.defaultNullOpts.mkBool false '' enable = helpers.defaultNullOpts.mkBool false ''
Tree window will be floating. Tree window will be floating.
''; '';
@ -499,8 +521,7 @@ in {
}; };
}; };
# UI rendering setup renderer = helpers.mkCompositeOption "UI rendering setup" {
renderer = {
addTrailing = helpers.defaultNullOpts.mkBool false '' addTrailing = helpers.defaultNullOpts.mkBool false ''
Appends a trailing slash to folder names. Appends a trailing slash to folder names.
''; '';
@ -565,8 +586,7 @@ in {
Number of spaces for an each tree nesting level. Minimum 1. Number of spaces for an each tree nesting level. Minimum 1.
''; '';
# Configuration options for tree indent markers. indentMarkers = helpers.mkCompositeOption "Configuration options for tree indent markers." {
indentMarkers = {
enable = helpers.defaultNullOpts.mkBool false '' enable = helpers.defaultNullOpts.mkBool false ''
Display indent markers when folders are open Display indent markers when folders are open
''; '';
@ -576,8 +596,7 @@ in {
|renderer.icons.show.folder_arrow|. |renderer.icons.show.folder_arrow|.
''; '';
# Icons shown before the file/directory. Length 1. icons = helpers.mkCompositeOption "Icons shown before the file/directory. Length 1." {
icons = {
corner = helpers.defaultNullOpts.mkStr "" ""; corner = helpers.defaultNullOpts.mkStr "" "";
edge = helpers.defaultNullOpts.mkStr "" ""; edge = helpers.defaultNullOpts.mkStr "" "";
item = helpers.defaultNullOpts.mkStr "" ""; item = helpers.defaultNullOpts.mkStr "" "";
@ -586,8 +605,7 @@ in {
}; };
}; };
# Configuration options for icons. icons = helpers.mkCompositeOption "Configuration options for icons." {
icons = {
webdevColors = helpers.defaultNullOpts.mkBool true '' webdevColors = helpers.defaultNullOpts.mkBool true ''
Use the webdev icon colors, otherwise `NvimTreeFileIcon`. Use the webdev icon colors, otherwise `NvimTreeFileIcon`.
''; '';
@ -622,8 +640,7 @@ in {
Used as a separator between symlinks' source and target. Used as a separator between symlinks' source and target.
''; '';
# Configuration options for showing icon types. show = helpers.mkCompositeOption "Configuration options for showing icon types." {
show = {
file = helpers.defaultNullOpts.mkBool true '' file = helpers.defaultNullOpts.mkBool true ''
Show an icon before the file name. `nvim-web-devicons` will be used if available. Show an icon before the file name. `nvim-web-devicons` will be used if available.
''; '';
@ -648,8 +665,7 @@ in {
''; '';
}; };
# Configuration options for icon glyphs. glyphs = helpers.mkCompositeOption "Configuration options for icon glyphs." {
glyphs = {
default = helpers.defaultNullOpts.mkStr "" '' default = helpers.defaultNullOpts.mkStr "" ''
Glyph for files. Will be overridden by `nvim-web-devicons` if available. Glyph for files. Will be overridden by `nvim-web-devicons` if available.
''; '';
@ -662,8 +678,7 @@ in {
Icon to display for modified files. Icon to display for modified files.
''; '';
# Glyphs for directories. folder = helpers.mkCompositeOption "Glyphs for directories." {
folder = {
arrowClosed = helpers.defaultNullOpts.mkStr "" '' arrowClosed = helpers.defaultNullOpts.mkStr "" ''
Arrow glyphs for closed directories. Arrow glyphs for closed directories.
''; '';
@ -690,8 +705,7 @@ in {
''; '';
}; };
# Glyphs for git status. git = helpers.mkCompositeOption "Glyphs for git status." {
git = {
unstaged = helpers.defaultNullOpts.mkStr "" '' unstaged = helpers.defaultNullOpts.mkStr "" ''
Glyph for unstaged nodes. Glyph for unstaged nodes.
''; '';
@ -728,8 +742,7 @@ in {
''; '';
}; };
# Filtering options filters = helpers.mkCompositeOption "Filtering options." {
filters = {
dotfiles = helpers.defaultNullOpts.mkBool false '' dotfiles = helpers.defaultNullOpts.mkBool false ''
Do not show dotfiles: files starting with a `.` Do not show dotfiles: files starting with a `.`
Toggle via the `toggle_dotfiles` action, default mapping `H`. Toggle via the `toggle_dotfiles` action, default mapping `H`.
@ -760,17 +773,16 @@ in {
''; '';
}; };
# Configuration options for trashing trash = helpers.mkCompositeOption "Configuration options for trashing." {
trash.cmd = helpers.defaultNullOpts.mkStr "gio trash" '' cmd = helpers.defaultNullOpts.mkStr "gio trash" ''
The command used to trash items (must be installed on your system). The command used to trash items (must be installed on your system).
The default is shipped with glib2 which is a common linux package. The default is shipped with glib2 which is a common linux package.
Only available for UNIX. Only available for UNIX.
''; '';
};
# Configuration for various actions actions = helpers.mkCompositeOption "Configuration for various actions." {
actions = { changeDir = helpers.mkCompositeOption "vim |current-directory| behaviour." {
# vim |current-directory| behaviour
changeDir = {
enable = helpers.defaultNullOpts.mkBool true '' enable = helpers.defaultNullOpts.mkBool true ''
Change the working directory when changing directories in the tree. Change the working directory when changing directories in the tree.
''; '';
@ -785,8 +797,7 @@ in {
''; '';
}; };
# Configuration for expand_all behaviour expandAll = helpers.mkCompositeOption "Configuration for expand_all behaviour." {
expandAll = {
maxFolderDiscovery = helpers.defaultNullOpts.mkInt 300 '' maxFolderDiscovery = helpers.defaultNullOpts.mkInt 300 ''
Limit the number of folders being explored when expanding every folders. Limit the number of folders being explored when expanding every folders.
Avoids hanging neovim when running this action on very large folders. Avoids hanging neovim when running this action on very large folders.
@ -798,11 +809,14 @@ in {
''; '';
}; };
# Configuration for file_popup behaviour filePopup = helpers.mkCompositeOption "Configuration for file_popup behaviour." {
filePopup.openWinConfig = openWinConfigOption; openWinConfig = openWinConfigOption;
};
# Configuration options for opening a file from nvim-tree openFile =
openFile = { helpers.mkCompositeOption
"Configuration options for opening a file from nvim-tree."
{
quitOnOpen = helpers.defaultNullOpts.mkBool false '' quitOnOpen = helpers.defaultNullOpts.mkBool false ''
Closes the explorer when opening a file. Closes the explorer when opening a file.
It will also disable preventing a buffer overriding the tree. It will also disable preventing a buffer overriding the tree.
@ -811,9 +825,9 @@ in {
resizeWindow = helpers.defaultNullOpts.mkBool true '' resizeWindow = helpers.defaultNullOpts.mkBool true ''
Resizes the tree when opening a file. Resizes the tree when opening a file.
''; '';
};
# Window picker configuration windowPicker = helpers.mkCompositeOption "Window picker configuration." {
windowPicker = {
enable = helpers.defaultNullOpts.mkBool true '' enable = helpers.defaultNullOpts.mkBool true ''
Enable the feature. If the feature is not enabled, files will open in window from Enable the feature. If the feature is not enabled, files will open in window from
which you last opened the tree. which you last opened the tree.
@ -849,11 +863,12 @@ in {
the picker that the buffer's window should not be selectable. the picker that the buffer's window should not be selectable.
''; '';
}; };
};
removeFile.closeWindow = helpers.defaultNullOpts.mkBool true '' removeFile = helpers.mkCompositeOption "" {
closeWindow = helpers.defaultNullOpts.mkBool true ''
Close any window displaying a file when removing the file from the tree. Close any window displaying a file when removing the file from the tree.
''; '';
};
useSystemClipboard = helpers.defaultNullOpts.mkBool true '' useSystemClipboard = helpers.defaultNullOpts.mkBool true ''
A boolean value that toggle the use of system clipboard when copy/paste function are A boolean value that toggle the use of system clipboard when copy/paste function are
@ -863,12 +878,16 @@ in {
''; '';
}; };
# Configurations for the live_filtering feature. liveFilter =
# The live filter allows you to filter the tree nodes dynamically, based on helpers.mkCompositeOption
# regex matching (see |vim.regex|). ''
# This feature is bound to the `f` key by default. Configurations for the live_filtering feature.
# The filter can be cleared with the `F` key by default. The live filter allows you to filter the tree nodes dynamically, based on regex matching
liveFilter = { (see |vim.regex|).
This feature is bound to the `f` key by default.
The filter can be cleared with the `F` key by default.
''
{
prefix = helpers.defaultNullOpts.mkStr "[FILTER]: " '' prefix = helpers.defaultNullOpts.mkStr "[FILTER]: " ''
Prefix of the filter displayed in the buffer. Prefix of the filter displayed in the buffer.
''; '';
@ -878,10 +897,8 @@ in {
''; '';
}; };
# Configuration for tab behaviour tab = helpers.mkCompositeOption "Configuration for tab behaviour." {
tab = { sync = helpers.mkCompositeOption "Configuration for syncing nvim-tree across tabs." {
# Configuration for syncing nvim-tree across tabs
sync = {
open = helpers.defaultNullOpts.mkBool false '' open = helpers.defaultNullOpts.mkBool false ''
Opens the tree automatically when switching tabpage or opening a new tabpage if the tree Opens the tree automatically when switching tabpage or opening a new tabpage if the tree
was previously open. was previously open.
@ -898,8 +915,8 @@ in {
}; };
}; };
# Configuration for notification notify = helpers.mkCompositeOption "Configuration for notification." {
notify.threshold = helpers.defaultNullOpts.mkEnum ["error" "warning" "info" "debug"] "info" '' threshold = helpers.defaultNullOpts.mkEnum ["error" "warning" "info" "debug"] "info" ''
Specify minimum notification level, uses the values from |vim.log.levels| Specify minimum notification level, uses the values from |vim.log.levels|
- `error`: hard errors e.g. failure to read from the file system. - `error`: hard errors e.g. failure to read from the file system.
@ -907,11 +924,10 @@ in {
- `info:` information only e.g. file copy path confirmation. - `info:` information only e.g. file copy path confirmation.
- `debug:` not used. - `debug:` not used.
''; '';
};
# General UI configuration ui = helpers.mkCompositeOption "General UI configuration." {
ui = { confirm = helpers.mkCompositeOption "Confirmation prompts." {
# Confirmation prompts
confirm = {
remove = helpers.defaultNullOpts.mkBool true '' remove = helpers.defaultNullOpts.mkBool true ''
Prompt before removing. Prompt before removing.
''; '';
@ -922,8 +938,7 @@ in {
}; };
}; };
# Configuration for diagnostic logging log = helpers.mkCompositeOption "Configuration for diagnostic logging." {
log = {
enable = helpers.defaultNullOpts.mkBool false '' enable = helpers.defaultNullOpts.mkBool false ''
Enable logging to a file `$XDG_CACHE_HOME/nvim/nvim-tree.log` Enable logging to a file `$XDG_CACHE_HOME/nvim/nvim-tree.log`
''; '';
@ -932,8 +947,7 @@ in {
Remove existing log file at startup. Remove existing log file at startup.
''; '';
# Specify which information to log types = helpers.mkCompositeOption "Specify which information to log." {
types = {
all = helpers.defaultNullOpts.mkBool false "Everything."; all = helpers.defaultNullOpts.mkBool false "Everything.";
profile = helpers.defaultNullOpts.mkBool false "Timing of some operations."; profile = helpers.defaultNullOpts.mkBool false "Timing of some operations.";
@ -971,46 +985,50 @@ in {
sync_root_with_cwd = syncRootWithCwd; sync_root_with_cwd = syncRootWithCwd;
reload_on_bufenter = reloadOnBufenter; reload_on_bufenter = reloadOnBufenter;
respect_buf_cwd = respectBufCwd; respect_buf_cwd = respectBufCwd;
hijack_directories = with hijackDirectories; { hijack_directories = with hijackDirectories;
ifNonNull' cfg.hijackDirectories {
inherit enable; inherit enable;
auto_open = autoOpen; auto_open = autoOpenEnabled;
}; };
update_focused_file = with updateFocusedFile; { update_focused_file = with updateFocusedFile;
ifNonNull' cfg.updateFocusedFile {
inherit enable; inherit enable;
update_root = updateRoot; update_root = updateRoot;
ignore_list = ignoreList; ignore_list = ignoreList;
}; };
system_open = { system_open = helpers.ifNonNull systemOpen;
inherit (systemOpen) cmd args; diagnostics = with diagnostics;
}; ifNonNull' cfg.diagnostics {
diagnostics = with diagnostics; {
inherit enable; inherit enable;
debounce_delay = debounceDelay; debounce_delay = debounceDelay;
show_on_dirs = showOnDirs; show_on_dirs = showOnDirs;
show_on_open_dirs = showOnOpenDirs; show_on_open_dirs = showOnOpenDirs;
inherit icons; inherit icons;
severity = severity = ifNonNull' cfg.diagnostics.severity (
mapAttrs ( mapAttrs (
name: value: name: value:
if value == null ifNonNull' value
then null (helpers.mkRaw "vim.diagnostic.severity.${strings.toUpper value}")
else helpers.mkRaw "vim.diagnostic.severity.${strings.toUpper value}"
) )
severity; severity
);
}; };
git = with git; { git = with git;
ifNonNull' cfg.git {
inherit enable; inherit enable;
inherit ignore; inherit ignore;
show_on_dirs = showOnDirs; show_on_dirs = showOnDirs;
show_on_open_dirs = showOnOpenDirs; show_on_open_dirs = showOnOpenDirs;
inherit timeout; inherit timeout;
}; };
modified = with modified; { modified = with modified;
ifNonNull' cfg.modified {
inherit enable; inherit enable;
show_on_dirs = showOnDirs; show_on_dirs = showOnDirs;
show_on_open_dirs = showOnOpenDirs; show_on_open_dirs = showOnOpenDirs;
}; };
filesystem_watchers = with filesystemWatchers; { filesystem_watchers = with filesystemWatchers;
ifNonNull' cfg.filesystemWatchers {
inherit enable; inherit enable;
debounce_delay = debounceDelay; debounce_delay = debounceDelay;
ignore_dirs = ignoreDirs; ignore_dirs = ignoreDirs;
@ -1018,7 +1036,8 @@ in {
on_attach = onAttach; on_attach = onAttach;
remove_keymaps = removeKeymaps; remove_keymaps = removeKeymaps;
select_prompts = selectPrompts; select_prompts = selectPrompts;
view = with view; { view = with view;
ifNonNull' cfg.view {
centralize_selection = centralizeSelection; centralize_selection = centralizeSelection;
inherit cursorline; inherit cursorline;
debounce_delay = debounceDelay; debounce_delay = debounceDelay;
@ -1029,7 +1048,8 @@ in {
inherit number; inherit number;
inherit relativenumber; inherit relativenumber;
inherit signcolumn; inherit signcolumn;
mappings = with mappings; { mappings = with mappings;
ifNonNull' cfg.view.mappings {
custom_only = customOnly; custom_only = customOnly;
list = list =
if list == null if list == null
@ -1046,13 +1066,15 @@ in {
) )
list; list;
}; };
float = with float; { float = with float;
ifNonNull' cfg.view.float {
inherit enable; inherit enable;
quit_on_focus_loss = quitOnFocusLoss; quit_on_focus_loss = quitOnFocusLoss;
open_win_config = openWinConfig; open_win_config = openWinConfig;
}; };
}; };
renderer = with renderer; { renderer = with renderer;
ifNonNull' cfg.renderer {
add_trailing = addTrailing; add_trailing = addTrailing;
group_empty = groupEmpty; group_empty = groupEmpty;
full_name = fullName; full_name = fullName;
@ -1061,21 +1083,25 @@ in {
highlight_modified = highlightModified; highlight_modified = highlightModified;
root_folder_label = rootFolderLabel; root_folder_label = rootFolderLabel;
indent_width = indentWidth; indent_width = indentWidth;
indent_markers = with indentMarkers; { indent_markers = with indentMarkers;
ifNonNull' cfg.renderer.indentMarkers {
inherit enable icons; inherit enable icons;
inline_arrows = inlineArrows; inline_arrows = inlineArrows;
}; };
icons = with icons; { icons = with icons;
ifNonNull' cfg.renderer.icons {
webdev_colors = webdevColors; webdev_colors = webdevColors;
git_placement = gitPlacement; git_placement = gitPlacement;
modified_placement = modifiedPlacement; modified_placement = modifiedPlacement;
inherit padding; inherit padding;
symlink_arrow = symlinkArrow; symlink_arrow = symlinkArrow;
show = with show; { show = with show;
ifNonNull' cfg.renderer.icons.show {
inherit file folder git modified; inherit file folder git modified;
folder_arrow = folderArrow; folder_arrow = folderArrow;
}; };
glyphs = with glyphs; { glyphs = with glyphs;
ifNonNull' cfg.renderer.icons.glyphs {
inherit default symlink modified git; inherit default symlink modified git;
folder = with folder; { folder = with folder; {
arrow_closed = arrowClosed; arrow_closed = arrowClosed;
@ -1089,51 +1115,70 @@ in {
special_files = specialFiles; special_files = specialFiles;
symlink_destination = symlinkDestination; symlink_destination = symlinkDestination;
}; };
filters = with filters; { filters = with filters;
ifNonNull' cfg.filters {
inherit dotfiles custom exclude; inherit dotfiles custom exclude;
git_clean = gitClean; git_clean = gitClean;
no_buffer = noBuffer; no_buffer = noBuffer;
}; };
trash.cmd = trash.cmd; inherit trash;
actions = with actions; { actions = with actions;
change_dir = with changeDir; { ifNonNull' cfg.actions {
change_dir = with changeDir;
ifNonNull' cfg.actions.changeDir {
inherit enable global; inherit enable global;
restrict_above_cwd = restrictAboveCwd; restrict_above_cwd = restrictAboveCwd;
}; };
expand_all = with expandAll; { expand_all = with expandAll;
ifNonNull' cfg.actions.expandAll {
max_folder_discovery = maxFolderDiscovery; max_folder_discovery = maxFolderDiscovery;
inherit exclude; inherit exclude;
}; };
file_popup.open_win_config = filePopup.openWinConfig; file_popup = with filePopup;
open_file = with openFile; { ifNonNull' cfg.actions.filePopup {
open_win_config = filePopup.openWinConfig;
};
open_file = with openFile;
ifNonNull' cfg.actions.openFile {
quit_on_open = quitOnOpen; quit_on_open = quitOnOpen;
resize_window = resizeWindow; resize_window = resizeWindow;
window_picker = windowPicker; window_picker = windowPicker;
}; };
remove_file.close_window = removeFile.closeWindow; remove_file = with removeFile;
ifNonNull' cfg.actions.removeFile {
close_window = removeFile.closeWindow;
};
use_system_clipboard = useSystemClipboard; use_system_clipboard = useSystemClipboard;
}; };
live_filter = with liveFilter; { live_filter = with liveFilter;
ifNonNull' cfg.liveFilter {
inherit prefix; inherit prefix;
always_show_folders = alwaysShowFolders; always_show_folders = alwaysShowFolders;
}; };
inherit tab; inherit tab;
notify.threshold = notify = with notify;
if notify.threshold == null ifNonNull' cfg.notify {
then null threshold =
else helpers.mkRaw "vim.log.levels.${strings.toUpper notify.threshold}"; ifNonNull' cfg.notify.threshold
(helpers.mkRaw "vim.log.levels.${strings.toUpper notify.threshold}");
};
inherit ui; inherit ui;
log = with log; { log = with log;
ifNonNull' cfg.log {
inherit enable truncate; inherit enable truncate;
types = with log.types; { types = ifNonNull' log.types (
with log.types; {
inherit all profile dev diagnostics git watcher; inherit all profile dev diagnostics git watcher;
inherit (log.types) config; inherit (log.types) config;
copy_paste = copyPaste; copy_paste = copyPaste;
}; }
);
}; };
} }
// cfg.extraOptions; // cfg.extraOptions;
autoOpenEnabled = cfg.openOnSetup or cfg.openOnSetupFile;
openNvimTreeFunction = '' openNvimTreeFunction = ''
local function open_nvim_tree(data) local function open_nvim_tree(data)
@ -1202,7 +1247,7 @@ in {
autoCmd = autoCmd =
[] []
++ (optional (cfg.openOnSetup or cfg.openOnSetupFile) { ++ (optional autoOpenEnabled {
event = "VimEnter"; event = "VimEnter";
callback = helpers.mkRaw "open_nvim_tree"; callback = helpers.mkRaw "open_nvim_tree";
}) })
@ -1212,8 +1257,9 @@ in {
nested = true; nested = true;
}); });
extraConfigLua = '' extraConfigLua =
${openNvimTreeFunction} (optionalString autoOpenEnabled openNvimTreeFunction)
+ ''
require('nvim-tree').setup(${helpers.toLuaObject options}) require('nvim-tree').setup(${helpers.toLuaObject options})
''; '';

275
tests/plugins/nvim-tree.nix Normal file
View file

@ -0,0 +1,275 @@
{
# Empty configuration
empty = {
plugins.nvim-tree.enable = true;
};
# All the upstream default options of nvim-tree
defaults = {
plugins.nvim-tree = {
enable = true;
disableNetrw = true;
hijackNetrw = false;
openOnSetup = true;
openOnSetupFile = true;
ignoreBufferOnSetup = true;
ignoreFtOnSetup = ["tex"];
autoClose = true;
autoReloadOnWrite = true;
sortBy = "name";
hijackUnnamedBufferWhenOpening = false;
hijackCursor = false;
rootDirs = [];
preferStartupRoot = false;
syncRootWithCwd = false;
reloadOnBufenter = false;
respectBufCwd = false;
hijackDirectories = {
enable = true;
autoOpen = true;
};
updateFocusedFile = {
enable = false;
updateRoot = false;
ignoreList = [];
};
systemOpen = {
cmd = "";
args = [];
};
diagnostics = {
enable = false;
debounceDelay = 50;
showOnDirs = false;
showOnOpenDirs = true;
icons = {
hint = "";
info = "";
warning = "";
error = "";
};
severity = {
min = "hint";
max = "error";
};
};
git = {
enable = true;
ignore = true;
showOnDirs = true;
showOnOpenDirs = true;
timeout = 400;
};
modified = {
enable = false;
showOnDirs = true;
showOnOpenDirs = true;
};
filesystemWatchers = {
enable = true;
debounceDelay = 50;
ignoreDirs = [];
};
onAttach = "default";
removeKeymaps = false;
selectPrompts = false;
view = {
centralizeSelection = false;
cursorline = true;
debounceDelay = 15;
hideRootFolder = false;
width = {
min = 30;
max = -1;
padding = 1;
};
side = "left";
preserveWindowProportions = false;
number = false;
relativenumber = false;
signcolumn = "yes";
mappings = {
customOnly = false;
list = [
# remove a default mapping for cd
{
key = "<2-RightMouse>";
action = "";
}
# add multiple normal mode mappings for edit
{
key = ["<CR>" "o"];
action = "edit";
mode = "n";
}
# custom action
{
key = "p";
action = "print_the_node_path";
action_cb = ''
function(node)
print(node.absolute_path)
end
'';
}
];
};
float = {
enable = false;
quitOnFocusLoss = true;
openWinConfig = {
col = 1;
row = 1;
relative = "cursor";
border = "shadow";
style = "minimal";
};
};
};
renderer = {
addTrailing = false;
groupEmpty = false;
fullName = false;
highlightGit = false;
highlightOpenedFiles = "none";
highlightModified = "none";
rootFolderLabel = ":~:s?$?/..?";
indentWidth = 2;
indentMarkers = {
enable = false;
inlineArrows = true;
icons = {
corner = "";
edge = "";
item = "";
bottom = "";
none = " ";
};
};
icons = {
webdevColors = true;
gitPlacement = "before";
modifiedPlacement = "after";
padding = " ";
symlinkArrow = " ";
show = {
file = true;
folder = true;
folderArrow = true;
git = true;
modified = true;
};
glyphs = {
default = "";
symlink = "";
modified = "";
folder = {
arrowClosed = "";
arrowOpen = "";
default = "";
open = "";
empty = "";
emptyOpen = "";
symlink = "";
symlinkOpen = "";
};
git = {
unstaged = "";
staged = "";
unmerged = "";
renamed = "";
untracked = "";
deleted = "";
ignored = "";
};
};
};
specialFiles = ["Cargo.toml" "Makefile" "README.md" "readme.md"];
symlinkDestination = true;
};
filters = {
dotfiles = false;
gitClean = false;
noBuffer = false;
custom = [];
exclude = [];
};
actions = {
changeDir = {
enable = true;
global = false;
restrictAboveCwd = false;
};
expandAll = {
maxFolderDiscovery = 300;
exclude = [];
};
filePopup = {
openWinConfig = {
col = 1;
row = 1;
relative = "cursor";
border = "shadow";
style = "minimal";
};
};
openFile = {
quitOnOpen = false;
resizeWindow = true;
};
windowPicker = {
enable = true;
picker = "default";
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
exclude = {
filetype = ["notify" "packer" "qf" "diff" "fugitive" "fugitiveblame"];
buftype = ["nofile" "terminal" "help"];
};
};
removeFile = {
closeWindow = true;
};
useSystemClipboard = true;
};
liveFilter = {
prefix = "[FILTER]: ";
alwaysShowFolders = true;
};
tab = {
sync = {
open = false;
close = false;
ignore = [];
};
};
notify = {
threshold = "info";
};
ui = {
confirm = {
remove = true;
trash = true;
};
};
log = {
enable = false;
truncate = false;
types = {
all = false;
profile = false;
config = false;
copyPaste = false;
dev = false;
diagnostics = false;
git = false;
watcher = false;
};
};
};
};
}