feat(nvimtree): add custom setup options

This commit is contained in:
Ching Pei Yang 2024-01-03 00:55:03 +01:00
parent 42016d8e04
commit 4001943a7b
2 changed files with 951 additions and 1188 deletions

View file

@ -6,10 +6,9 @@
}: let
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) boolToString;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) listToLuaTable expToLua;
inherit (lib.nvim.lua) toLuaObject;
# TODO: move this to its own module
inherit (lib) pushDownDefault;
@ -40,237 +39,7 @@ in {
''
}
require'nvim-tree'.setup({
disable_netrw = ${boolToString cfg.disableNetrw},
hijack_netrw = ${boolToString cfg.hijackNetrw},
auto_reload_on_write = ${boolToString cfg.autoreloadOnWrite},
sort = {
sorter = "${cfg.sort.sorter}",
folders_first = ${boolToString cfg.sort.foldersFirst},
},
hijack_unnamed_buffer_when_opening = ${boolToString cfg.hijackUnnamedBufferWhenOpening},
hijack_cursor = ${boolToString cfg.hijackCursor},
root_dirs = ${listToLuaTable cfg.rootDirs},
prefer_startup_root = ${boolToString cfg.preferStartupRoot},
sync_root_with_cwd = ${boolToString cfg.syncRootWithCwd},
reload_on_bufenter = ${boolToString cfg.reloadOnBufEnter},
respect_buf_cwd = ${boolToString cfg.respectBufCwd},
hijack_directories = {
enable = ${boolToString cfg.hijackDirectories.enable},
auto_open = ${boolToString cfg.hijackDirectories.autoOpen},
},
update_focused_file = {
enable = ${boolToString cfg.updateFocusedFile.enable},
update_root = ${boolToString cfg.updateFocusedFile.updateRoot},
ignore_list = ${listToLuaTable cfg.updateFocusedFile.ignoreList},
},
system_open = {
cmd = "${cfg.systemOpen.cmd}",
args = ${listToLuaTable cfg.systemOpen.args},
},
diagnostics = {
enable = ${boolToString cfg.diagnostics.enable},
icons = {
hint = "${cfg.diagnostics.icons.hint}",
info = "${cfg.diagnostics.icons.info}",
warning = "${cfg.diagnostics.icons.warning}",
error = "${cfg.diagnostics.icons.error}",
},
severity = {
min = vim.diagnostic.severity.${cfg.diagnostics.severity.min},
max = vim.diagnostic.severity.${cfg.diagnostics.severity.max},
},
},
git = {
enable = ${boolToString cfg.git.enable},
show_on_dirs = ${boolToString cfg.git.showOnDirs},
show_on_open_dirs = ${boolToString cfg.git.showOnOpenDirs},
disable_for_dirs = ${listToLuaTable cfg.git.disableForDirs},
timeout = ${toString cfg.git.timeout},
},
modified = {
enable = ${boolToString cfg.modified.enable},
show_on_dirs = ${boolToString cfg.modified.showOnDirs},
show_on_open_dirs = ${boolToString cfg.modified.showOnOpenDirs},
},
filesystem_watchers = {
enable = ${boolToString cfg.filesystemWatchers.enable},
debounce_delay = ${toString cfg.filesystemWatchers.debounceDelay},
ignore_dirs = ${listToLuaTable cfg.filesystemWatchers.ignoreDirs},
},
select_prompts = ${boolToString cfg.selectPrompts},
view = {
centralize_selection = ${boolToString cfg.view.centralizeSelection},
cursorline = ${boolToString cfg.view.cursorline},
debounce_delay = ${toString cfg.view.debounceDelay},
width = ${expToLua cfg.view.width},
side = "${cfg.view.side}",
preserve_window_proportions = ${boolToString cfg.view.preserveWindowProportions},
number = ${boolToString cfg.view.number},
relativenumber = ${boolToString cfg.view.relativenumber},
signcolumn = "${cfg.view.signcolumn}",
float = {
enable = ${boolToString cfg.view.float.enable},
quit_on_focus_loss = ${boolToString cfg.view.float.quitOnFocusLoss},
open_win_config = {
relative = "${cfg.view.float.openWinConfig.relative}",
border = "${cfg.view.float.openWinConfig.border}",
width = ${toString cfg.view.float.openWinConfig.width},
height = ${toString cfg.view.float.openWinConfig.height},
row = ${toString cfg.view.float.openWinConfig.row},
col = ${toString cfg.view.float.openWinConfig.col},
},
},
},
renderer = {
add_trailing = ${boolToString cfg.renderer.addTrailing},
group_empty = ${boolToString cfg.renderer.groupEmpty},
full_name = ${boolToString cfg.renderer.fullName},
highlight_git = ${boolToString cfg.renderer.highlightGit},
highlight_opened_files = ${cfg.renderer.highlightOpenedFiles},
highlight_modified = ${cfg.renderer.highlightModified},
root_folder_label = ${expToLua cfg.renderer.rootFolderLabel},
indent_width = ${toString cfg.renderer.indentWidth},
indent_markers = {
enable = ${boolToString cfg.renderer.indentMarkers.enable},
inline_arrows = ${boolToString cfg.renderer.indentMarkers.inlineArrows},
icons = ${expToLua cfg.renderer.indentMarkers.icons},
},
special_files = ${listToLuaTable cfg.renderer.specialFiles},
symlink_destination = ${boolToString cfg.renderer.symlinkDestination},
icons = {
webdev_colors = ${boolToString cfg.renderer.icons.webdevColors},
git_placement = "${cfg.renderer.icons.gitPlacement}",
modified_placement = "${cfg.renderer.icons.modifiedPlacement}",
padding = "${cfg.renderer.icons.padding}",
symlink_arrow = "${cfg.renderer.icons.symlinkArrow}",
show = {
git = ${boolToString cfg.renderer.icons.show.git},
folder = ${boolToString cfg.renderer.icons.show.folder},
folder_arrow = ${boolToString cfg.renderer.icons.show.folderArrow},
file = ${boolToString cfg.renderer.icons.show.file},
modified = ${boolToString cfg.renderer.icons.show.modified},
},
glyphs = {
default = "${cfg.renderer.icons.glyphs.default}",
symlink = "${cfg.renderer.icons.glyphs.symlink}",
modified = "${cfg.renderer.icons.glyphs.modified}",
folder = {
default = "${cfg.renderer.icons.glyphs.folder.default}",
open = "${cfg.renderer.icons.glyphs.folder.open}",
arrow_open = "${cfg.renderer.icons.glyphs.folder.arrowOpen}",
arrow_closed = "${cfg.renderer.icons.glyphs.folder.arrowClosed}",
empty = "${cfg.renderer.icons.glyphs.folder.empty}",
empty_open = "${cfg.renderer.icons.glyphs.folder.emptyOpen}",
symlink = "${cfg.renderer.icons.glyphs.folder.symlink}",
symlink_open = "${cfg.renderer.icons.glyphs.folder.symlinkOpen}",
},
git = {
unstaged = "${cfg.renderer.icons.glyphs.git.unstaged}",
staged = "${cfg.renderer.icons.glyphs.git.staged}",
unmerged = "${cfg.renderer.icons.glyphs.git.unmerged}",
renamed = "${cfg.renderer.icons.glyphs.git.renamed}",
untracked = "${cfg.renderer.icons.glyphs.git.untracked}",
deleted = "${cfg.renderer.icons.glyphs.git.deleted}",
ignored = "${cfg.renderer.icons.glyphs.git.ignored}",
},
},
},
},
filters = {
git_ignored = ${boolToString cfg.filters.gitIgnored},
dotfiles = ${boolToString cfg.filters.dotfiles},
git_clean = ${boolToString cfg.filters.gitClean},
no_buffer = ${boolToString cfg.filters.noBuffer},
exclude = ${listToLuaTable cfg.filters.exclude},
},
trash = {
cmd = "${cfg.trash.cmd}",
},
actions = {
use_system_clipboard = ${boolToString cfg.actions.useSystemClipboard},
change_dir = {
enable = ${boolToString cfg.actions.changeDir.enable},
global = ${boolToString cfg.actions.changeDir.global},
restrict_above_cwd = ${boolToString cfg.actions.changeDir.restrictAboveCwd},
},
expand_all = {
max_folder_discovery = ${toString cfg.actions.expandAll.maxFolderDiscovery},
exclude = ${listToLuaTable cfg.actions.expandAll.exclude},
},
file_popup = {
open_win_config = ${expToLua cfg.actions.filePopup.openWinConfig},
},
open_file = {
quit_on_open = ${boolToString cfg.actions.openFile.quitOnOpen},
eject = ${boolToString cfg.actions.openFile.eject},
resize_window = ${boolToString cfg.actions.openFile.resizeWindow},
window_picker = {
enable = ${boolToString cfg.actions.openFile.windowPicker.enable},
picker = "${cfg.actions.openFile.windowPicker.picker}",
chars = "${cfg.actions.openFile.windowPicker.chars}",
exclude = {
filetype = ${listToLuaTable cfg.actions.openFile.windowPicker.exclude.filetype},
buftype = ${listToLuaTable cfg.actions.openFile.windowPicker.exclude.buftype},
},
},
},
remove_file = {
close_window = ${boolToString cfg.actions.removeFile.closeWindow},
},
},
live_filter = {
prefix = "${cfg.liveFilter.prefix}",
always_show_folders = ${boolToString cfg.liveFilter.alwaysShowFolders},
},
tab = {
sync = {
open = ${boolToString cfg.tab.sync.open},
close = ${boolToString cfg.tab.sync.close},
ignore = ${listToLuaTable cfg.tab.sync.ignore},
},
},
notify = {
threshold = vim.log.levels.${cfg.notify.threshold},
absolute_path = ${boolToString cfg.notify.absolutePath},
},
ui = {
confirm = {
remove = ${boolToString cfg.ui.confirm.remove},
trash = ${boolToString cfg.ui.confirm.trash},
},
},
})
require'nvim-tree'.setup(${toLuaObject cfg.setupOpts})
${
optionalString cfg.openOnSetup ''

View file

@ -4,7 +4,8 @@
...
}: let
inherit (lib.options) mkEnableOption mkOption literalExpression;
inherit (lib.types) nullOr str bool int listOf enum attrs oneOf addCheck submodule;
inherit (lib.types) nullOr str bool int submodule listOf enum oneOf attrs addCheck;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.filetree.nvimTree = {
enable = mkEnableOption "filetree via nvim-tree.lua";
@ -38,19 +39,20 @@ in {
type = bool;
};
hijackNetrw = mkOption {
setupOpts = mkPluginSetupOption "Nvim Tree" {
hijack_netrw = mkOption {
default = true;
description = "Prevents netrw from automatically opening when opening directories";
type = bool;
};
autoreloadOnWrite = mkOption {
autoreload_on_write = mkOption {
default = true;
description = "Auto reload tree on write";
type = bool;
};
updateFocusedFile = mkOption {
update_focused_file = mkOption {
description = ''
Update the focused file on `BufEnter`, un-collapses the folders recursively
until it finds the file.
@ -64,7 +66,7 @@ in {
description = "update focused file";
};
updateRoot = mkOption {
update_root = mkOption {
type = bool;
default = false;
description = ''
@ -75,7 +77,7 @@ in {
'';
};
ignoreList = mkOption {
ignore_list = mkOption {
type = listOf str;
default = [];
description = ''
@ -97,26 +99,26 @@ in {
type = enum ["name" "extension" "modification_time" "case_sensitive" "suffix" "filetype"];
};
foldersFirst = mkOption {
folders_first = mkOption {
default = true;
description = "Sort folders before files. Has no effect when `sort.sorter` is a function.";
type = bool;
};
};
hijackCursor = mkOption {
hijack_cursor = mkOption {
default = false;
description = "Hijack the cursor in the tree to put it at the start of the filename";
type = bool;
};
hijackUnnamedBufferWhenOpening = mkOption {
hijack_unnamed_buffer_when_opening = mkOption {
default = false;
description = "Open nvimtree in place of the unnamed buffer if it's empty.";
type = bool;
};
rootDirs = mkOption {
root_dirs = mkOption {
default = [];
description = ''
Preferred root directories. Only relevant when `updateFocusedFile.updateRoot` is `true`
@ -124,7 +126,7 @@ in {
type = listOf str;
};
preferStartupRoot = mkOption {
prefer_startup_root = mkOption {
default = false;
description = ''
Prefer startup root directory when updating root directory of the tree.
@ -133,7 +135,7 @@ in {
type = bool;
};
syncRootWithCwd = mkOption {
sync_root_with_cwd = mkOption {
type = bool;
default = false;
description = ''
@ -144,47 +146,38 @@ in {
'';
};
reloadOnBufEnter = mkOption {
reload_on_buf_enter = mkOption {
default = false;
type = bool;
description = "Automatically reloads the tree on `BufEnter` nvim-tree.";
};
respectBufCwd = mkOption {
respect_buf_cwd = mkOption {
default = false;
type = bool;
description = "Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.";
};
hijackDirectories = mkOption {
description = "hijack new directory buffers when they are opened (`:e dir`).";
default = {
enable = true;
autoOpen = false;
};
type = submodule {
options = {
hijack_directories = {
enable = mkOption {
type = bool;
description = ''
Enable the `hijack_directories` feature. Disable this option if you use vim-dirvish or dirbuf.nvim.
If `hijack_netrw` and `disable_netrw` are `false`, this feature will be disabled.
'';
default = true;
};
autoOpen = mkOption {
auto_open = mkOption {
type = bool;
description = ''
Opens the tree if the tree was previously closed.
'';
};
};
default = false;
};
};
systemOpen = {
system_open = {
args = mkOption {
default = [];
description = "Optional argument list.";
@ -215,18 +208,18 @@ in {
options = {
enable = mkEnableOption "diagnostics view in the signcolumn.";
debounceDelay = mkOption {
debounce_delay = mkOption {
description = "Idle milliseconds between diagnostic event and update.";
type = int;
default = 50;
};
showOnDirs = mkOption {
show_on_dirs = mkOption {
description = "Show diagnostic icons on parent directories.";
default = false;
};
showOnOpenDirs = mkOption {
show_on_open_dirs = mkOption {
type = bool;
default = true;
description = ''
@ -290,19 +283,19 @@ in {
git = {
enable = mkEnableOption "Git integration with icons and colors.";
showOnDirs = mkOption {
show_on_dirs = mkOption {
type = bool;
default = true;
description = "Show git icons on parent directories.";
};
showOnOpenDirs = mkOption {
show_on_open_dirs = mkOption {
type = bool;
default = true;
description = "Show git icons on directories that are open.";
};
disableForDirs = mkOption {
disable_for_dirs = mkOption {
type = listOf str;
default = [];
description = ''
@ -328,13 +321,13 @@ in {
options = {
enable = mkEnableOption "Modified files with icons and color highlight.";
showOnDirs = mkOption {
show_on_dirs = mkOption {
type = bool;
description = "Show modified icons on parent directories.";
default = true;
};
showOnOpenDirs = mkOption {
show_on_open_dirs = mkOption {
type = bool;
description = "Show modified icons on directories that are open.";
default = true;
@ -343,7 +336,7 @@ in {
};
};
filesystemWatchers = mkOption {
filesystem_watchers = mkOption {
description = ''
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
@ -360,13 +353,13 @@ in {
default = true;
};
debounceDelay = mkOption {
debounce_delay = mkOption {
description = "Idle milliseconds between filesystem change and action.";
type = int;
default = 50;
};
ignoreDirs = mkOption {
ignore_dirs = mkOption {
type = listOf str;
default = [];
description = ''
@ -388,7 +381,7 @@ in {
default = {};
type = submodule {
options = {
centralizeSelection = mkOption {
centralize_selection = mkOption {
description = "If true, reposition the view so that the current node is initially centralized when entering nvim-tree.";
type = bool;
default = false;
@ -400,7 +393,7 @@ in {
default = true;
};
debounceDelay = mkOption {
debounce_delay = mkOption {
type = int;
default = 15;
description = ''
@ -434,7 +427,7 @@ in {
default = "left";
};
preserveWindowProportions = mkOption {
preserve_window_proportions = mkOption {
description = ''
Preserves window proportions when opening a file.
If `false`, the height and width of windows other than nvim-tree will be equalized.
@ -477,13 +470,13 @@ in {
default = false;
};
quitOnFocusLoss = mkOption {
quit_on_focus_loss = mkOption {
description = "Close the floating tree window when it loses focus.";
type = bool;
default = true;
};
openWinConfig = mkOption {
open_win_config = mkOption {
description = "Floating window config. See `:h nvim_open_win()` for more details.";
type = attrs;
default = {
@ -503,25 +496,25 @@ in {
};
renderer = {
addTrailing = mkOption {
add_trailing = mkOption {
default = false;
description = "Appends a trailing slash to folder names.";
type = bool;
};
groupEmpty = mkOption {
group_empty = mkOption {
default = false;
description = "Compact folders that only contain a single folder into one node in the file tree.";
type = bool;
};
fullName = mkOption {
full_name = mkOption {
default = false;
description = "Display node whose name length is wider than the width of nvim-tree window in floating window.";
type = bool;
};
highlightGit = mkOption {
highlight_git = mkOption {
type = bool;
default = false;
description = ''
@ -531,7 +524,7 @@ in {
'';
};
highlightOpenedFiles = mkOption {
highlight_opened_files = mkOption {
type = enum ["none" "icon" "name" "all"];
default = "none";
description = ''
@ -540,7 +533,7 @@ in {
'';
};
highlightModified = mkOption {
highlight_modified = mkOption {
type = enum ["none" "icon" "name" "all"];
default = "none";
description = ''
@ -549,7 +542,7 @@ in {
'';
};
rootFolderLabel = mkOption {
root_folder_label = mkOption {
type = oneOf [str bool];
default = false;
example = ''"":~:s?$?/..?"'';
@ -566,19 +559,19 @@ in {
'';
};
indentWidth = mkOption {
indent_width = mkOption {
type = addCheck int (x: x >= 1);
default = 2;
description = "Number of spaces for an each tree nesting level. Minimum 1.";
};
indentMarkers = mkOption {
indent_markers = mkOption {
description = "Configuration options for tree indent markers.";
default = {};
type = submodule {
options = {
enable = mkEnableOption "Display indent markers when folders are open.";
inlineArrows = mkOption {
inline_arrows = mkOption {
type = bool;
default = true;
description = "Display folder arrows in the same column as indent marker when using `renderer.icons.show.folder_arrow`";
@ -599,13 +592,13 @@ in {
};
};
specialFiles = mkOption {
special_files = mkOption {
type = listOf str;
default = ["Cargo.toml" "README.md" "readme.md" "Makefile" "MAKEFILE" "flake.nix"]; # ;)
description = "A list of filenames that gets highlighted with `NvimTreeSpecialFile";
};
symlinkDestination = mkOption {
symlink_destination = mkOption {
type = bool;
default = true;
description = "Whether to show the destination of the symlink.";
@ -616,19 +609,19 @@ in {
default = {};
type = submodule {
options = {
webdevColors = mkOption {
webdev_colors = mkOption {
type = bool;
description = " Use the webdev icon colors, otherwise `NvimTreeFileIcon`";
default = true;
};
gitPlacement = mkOption {
git_placement = mkOption {
type = enum ["before" "after" "signcolumn"];
description = "Place where the git icons will be rendered. `signcolumn` requires `view.signcolumn` to be enabled.";
default = "before";
};
modifiedPlacement = mkOption {
modified_placement = mkOption {
type = enum ["before" "after" "signcolumn"];
description = "Place where the modified icons will be rendered. `signcolumn` requires `view.signcolumn` to be enabled.";
default = "after";
@ -640,7 +633,7 @@ in {
default = " ";
};
symlinkArrow = mkOption {
symlink_arrow = mkOption {
type = str;
description = "Used as a separator between symlinks' source and target.";
default = " ";
@ -659,7 +652,7 @@ in {
default = true;
};
folderArrow = mkOption {
folder_arrow = mkOption {
type = bool;
default = true;
description = ''
@ -754,15 +747,15 @@ in {
description = "Filtering options.";
default = {
gitIgnored = false;
git_ignored = false;
dotfiles = false;
gitClean = false;
noBuffer = false;
git_clean = false;
no_buffer = false;
exclude = [];
};
type = submodule {
options = {
gitIgnored = mkOption {
git_ignored = mkOption {
type = bool;
description = "Ignore files based on `.gitignore`. Requires git.enable` to be `true`";
default = false;
@ -774,7 +767,7 @@ in {
default = false;
};
gitClean = mkOption {
git_clean = mkOption {
type = bool;
default = false;
@ -784,7 +777,7 @@ in {
'';
};
noBuffer = mkOption {
no_buffer = mkOption {
type = bool;
default = false;
description = "Do not show files that have no `buflisted()` buffer.";
@ -820,7 +813,7 @@ in {
default = {};
type = submodule {
options = {
useSystemClipboard = mkOption {
use_system_clipboard = mkOption {
type = bool;
default = true;
description = ''
@ -831,7 +824,7 @@ in {
};
# change_dir actions
changeDir = mkOption {
change_dir = mkOption {
description = "vim `change-directory` behaviour";
default = {};
type = submodule {
@ -851,7 +844,7 @@ in {
'';
};
restrictAboveCwd = mkOption {
restrict_above_cwd = mkOption {
type = bool;
default = false;
description = ''
@ -863,12 +856,12 @@ in {
};
# expand_all actions
expandAll = mkOption {
expand_all = mkOption {
description = "Configuration for expand_all behaviour.";
default = {};
type = submodule {
options = {
maxFolderDiscovery = mkOption {
max_folder_discovery = mkOption {
type = int;
default = 300;
description = ''
@ -886,12 +879,12 @@ in {
};
# file_popup actions
filePopup = mkOption {
file_popup = mkOption {
description = "Configuration for file_popup behaviour.";
default = {};
type = submodule {
options = {
openWinConfig = mkOption {
open_win_config = mkOption {
type = attrs;
default = {
col = 1;
@ -907,12 +900,12 @@ in {
};
# open_file actions
openFile = mkOption {
open_file = mkOption {
description = "Configuration options for opening a file from nvim-tree.";
default = {};
type = submodule {
options = {
quitOnOpen = mkOption {
quit_on_open = mkOption {
type = bool;
description = "Closes the explorer when opening a file.";
default = false;
@ -924,14 +917,14 @@ in {
default = false;
};
resizeWindow = mkOption {
resize_window = mkOption {
type = bool;
default = false;
description = "Resizes the tree when opening a file. Previously `view.auto_resize`";
};
windowPicker = mkOption {
window_picker = mkOption {
description = "window_picker";
default = {};
type = submodule {
@ -985,8 +978,8 @@ in {
};
};
removeFile = {
closeWindow = mkOption {
remove_file = {
close_window = mkOption {
type = bool;
default = true;
description = "Close any window displaying a file when removing the file from the tree";
@ -996,7 +989,7 @@ in {
};
};
liveFilter = mkOption {
live_filter = mkOption {
description = ''
Configurations for the live_filtering feature.
The live filter allows you to filter the tree nodes dynamically, based on
@ -1013,7 +1006,7 @@ in {
default = "[FILTER]: ";
};
alwaysShowFolders = mkOption {
always_show_folders = mkOption {
type = bool;
description = "Whether to filter folders or not.";
default = true;
@ -1075,7 +1068,7 @@ in {
default = "INFO";
};
absolutePath = mkOption {
absolute_path = mkOption {
type = bool;
description = "Whether to use absolute paths or item names in fs action notifications.";
default = true;
@ -1105,6 +1098,7 @@ in {
};
};
};
};
# kept for backwards compatibility
openOnSetup = mkOption {