diff --git a/plugins/utils/nvim-tree.nix b/plugins/utils/nvim-tree.nix index 70423af8..f09f6148 100644 --- a/plugins/utils/nvim-tree.nix +++ b/plugins/utils/nvim-tree.nix @@ -7,6 +7,7 @@ with lib; let cfg = config.plugins.nvim-tree; helpers = import ../helpers.nix {inherit lib;}; + ifNonNull' = helpers.ifNonNull'; optionWarnings = import ../../lib/option-warnings.nix args; basePluginPath = ["plugins" "nvim-tree"]; @@ -36,10 +37,6 @@ in { option = basePluginPath ++ ["updateCwd"]; newOption = basePluginPath ++ ["syncRootWithCwd"]; }) - (optionWarnings.mkRenamedOption { - option = basePluginPath ++ ["updateFocusedFile" "updateCwd"]; - newOption = basePluginPath ++ ["updateFocusedFile" "updateRoot"]; - }) (optionWarnings.mkRenamedOption { option = basePluginPath ++ ["openOnTab"]; newOption = basePluginPath ++ ["tab" "sync" "open"]; @@ -48,6 +45,10 @@ in { option = basePluginPath ++ ["updateToBufDir"]; newOption = basePluginPath ++ ["hijackDirectories"]; }) + (optionWarnings.mkDeprecatedOption { + option = basePluginPath ++ ["removeKeymaps"]; + alternative = basePluginPath ++ ["onAttach"]; + }) ]; options.plugins.nvim-tree = @@ -172,100 +173,118 @@ in { Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree. ''; - hijackDirectories = { - enable = helpers.defaultNullOpts.mkBool true '' - Hijacks new directory buffers when they are opened (`:e dir`). - Disable this option if you use vim-dirvish or dirbuf.nvim. - If `hijackNetrw` and `disableNetrw` are `false`, this feature will be disabled. - ''; + hijackDirectories = + helpers.mkCompositeOption + "Hijacks new directory buffers when they are opened (`:e dir`)." + { + enable = helpers.defaultNullOpts.mkBool true '' + Enable the feature. + Disable this option if you use vim-dirvish or dirbuf.nvim. + If `hijackNetrw` and `disableNetrw` are `false`, this feature will be disabled. + ''; - autoOpen = helpers.defaultNullOpts.mkBool true '' - Opens the tree if the tree was previously closed. - ''; - }; + autoOpen = helpers.defaultNullOpts.mkBool true '' + Opens the tree if the tree was previously closed. + ''; + }; - updateFocusedFile = { - enable = helpers.defaultNullOpts.mkBool false '' + updateFocusedFile = + helpers.mkCompositeOption + '' Update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file. - ''; + '' + { + enable = helpers.defaultNullOpts.mkBool false "Enable this feature."; - updateRoot = helpers.defaultNullOpts.mkBool false '' - Update the root directory of the tree if the file is not under current root directory. - It prefers vim's cwd and `root_dirs`. - Otherwise it falls back to the folder containing the file. - Only relevant when `updateFocusedFile.enable` is `true` - ''; + updateRoot = helpers.defaultNullOpts.mkBool false '' + Update the root directory of the tree if the file is not under current root directory. + It prefers vim's cwd and `root_dirs`. + Otherwise it falls back to the folder containing the file. + Only relevant when `updateFocusedFile.enable` is `true` + ''; - 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 - isn't found under the current root directory. - Only relevant when `updateFocusedFile.updateRoot` and `updateFocusedFile.enable` are `true`. - ''; - }; + 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 isn't found under the current root directory. + Only relevant when `updateFocusedFile.updateRoot` and `updateFocusedFile.enable` are + `true`. + ''; + }; - systemOpen = { - cmd = helpers.defaultNullOpts.mkStr "" '' - A custom command to open files or directory with. + systemOpen = + helpers.mkCompositeOption + "Open a file or directory in your preferred application." + { + cmd = helpers.defaultNullOpts.mkStr "" '' + The open command itself. - Leave empty for OS specific default: - UNIX: `"xdg-open"` - macOS: `"open"` - Windows: "`cmd"` - ''; + Leave empty for OS specific default: + UNIX: `"xdg-open"` + macOS: `"open"` + Windows: "`cmd"` + ''; - args = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' - Optional argument list. + args = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' + Optional argument list. - Leave empty for OS specific default: - Windows: `{ "/c", "start", '""' }` - ''; - }; + Leave empty for OS specific default: + Windows: `{ "/c", "start", '""' }` + ''; + }; - diagnostics = { - enable = helpers.defaultNullOpts.mkBool false '' + diagnostics = + helpers.mkCompositeOption + '' Show LSP and COC diagnostics in the signcolumn Note that the modified sign will take precedence over the diagnostics signs. - `NOTE`: it will use the default diagnostic color groups to highlight the signs. - If you wish to customize, you can override these groups: - - `NvimTreeLspDiagnosticsError` - - `NvimTreeLspDiagnosticsWarning` - - `NvimTreeLspDiagnosticsInformation` - - `NvimTreeLspDiagnosticsHint` - ''; + `NOTE`: it will use the default diagnostic color groups to highlight the signs. + If you wish to customize, you can override these groups: + - `NvimTreeLspDiagnosticsError` + - `NvimTreeLspDiagnosticsWarning` + - `NvimTreeLspDiagnosticsInformation` + - `NvimTreeLspDiagnosticsHint` + '' + { + enable = helpers.defaultNullOpts.mkBool false "Enable/disable the feature."; - debounceDelay = helpers.defaultNullOpts.mkInt 50 '' - Idle milliseconds between diagnostic event and update. - ''; + debounceDelay = helpers.defaultNullOpts.mkInt 50 '' + Idle milliseconds between diagnostic event and update. + ''; - showOnDirs = helpers.defaultNullOpts.mkBool false '' - Show diagnostic icons on parent directories. - ''; + showOnDirs = helpers.defaultNullOpts.mkBool false '' + Show diagnostic icons on parent directories. + ''; - showOnOpenDirs = helpers.defaultNullOpts.mkBool true '' - Show diagnostics icons on directories that are open. - Only relevant when `diagnostics.showOnDirs` is `true - ''; + showOnOpenDirs = helpers.defaultNullOpts.mkBool true '' + Show diagnostics icons on directories that are open. + Only relevant when `diagnostics.showOnDirs` is `true + ''; - # Icons for diagnostic severity. - icons = { - hint = helpers.defaultNullOpts.mkStr "" ""; - info = helpers.defaultNullOpts.mkStr "" ""; - warning = helpers.defaultNullOpts.mkStr "" ""; - error = helpers.defaultNullOpts.mkStr "" ""; + icons = helpers.mkCompositeOption "Icons for diagnostic severity." { + hint = helpers.defaultNullOpts.mkStr "" ""; + info = helpers.defaultNullOpts.mkStr "" ""; + warning = helpers.defaultNullOpts.mkStr "" ""; + error = helpers.defaultNullOpts.mkStr "" ""; + }; + + severity = let + severityEnum = ["error" "warn" "info" "hint"]; + in + helpers.mkCompositeOption + '' + Severity for which the diagnostics will be displayed. + See |diagnostic-severity|. + '' + { + min = helpers.defaultNullOpts.mkEnum severityEnum "hint" "Minimum severity."; + max = helpers.defaultNullOpts.mkEnum severityEnum "error" "Maximum severity."; + }; }; - severity = let - severityEnum = ["error" "warn" "info" "hint"]; - in { - min = helpers.defaultNullOpts.mkEnum severityEnum "hint" "Minimum severity."; - max = helpers.defaultNullOpts.mkEnum severityEnum "error" "Maximum severity."; - }; - }; - - git = { - enable = helpers.defaultNullOpts.mkBool true "Git integration with icons and colors."; + git = helpers.mkCompositeOption "Git integration with icons and colors." { + enable = helpers.defaultNullOpts.mkBool true "Enable / disable the feature."; ignore = helpers.defaultNullOpts.mkBool true '' Ignore files based on `.gitignore`. Requires `git.enable` to be `true`. @@ -286,10 +305,8 @@ in { ''; }; - modified = { - enable = helpers.defaultNullOpts.mkBool false '' - Indicate which file have unsaved modification. - ''; + modified = helpers.mkCompositeOption "Indicate which file have unsaved modification." { + enable = helpers.defaultNullOpts.mkBool false "Enable / disable the feature."; showOnDirs = helpers.defaultNullOpts.mkBool true '' Show modified indication on directory whose children are modified. @@ -301,26 +318,29 @@ in { ''; }; - filesystemWatchers = { - enable = helpers.defaultNullOpts.mkBool true '' + filesystemWatchers = + helpers.mkCompositeOption + '' 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 update the whole tree. With this feature, the tree will be updated only for the appropriate folder change, resulting in better performance. - ''; + '' + { + enable = helpers.defaultNullOpts.mkBool true "Enable / disable the feature."; - debounceDelay = helpers.defaultNullOpts.mkInt 50 '' - Idle milliseconds between filesystem change and action. - ''; + debounceDelay = helpers.defaultNullOpts.mkInt 50 '' + Idle milliseconds between filesystem change and action. + ''; - ignoreDirs = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' - List of vim regex for absolute directory paths that will not be watched. - Backslashes must be escaped e.g. `"my-project/\\.build$"`. - See |string-match|. - Useful when path is not in `.gitignore` or git integration is disabled. - ''; - }; + ignoreDirs = helpers.defaultNullOpts.mkNullable (types.listOf types.str) "[]" '' + List of vim regex for absolute directory paths that will not be watched. + Backslashes must be escaped e.g. `"my-project/\\.build$"`. + See |string-match|. + Useful when path is not in `.gitignore` or git integration is disabled. + ''; + }; onAttach = helpers.defaultNullOpts.mkStr "disable" '' Function ran when creating the nvim-tree buffer. @@ -344,6 +364,8 @@ in { eg. {"", "", "o", ""} - Remove all default mappings by passing `true` - Ignore by passing `false` + + Deprecated: See https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach ''; 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. ''; - # Window / buffer setup - view = { + view = helpers.mkCompositeOption "Window / buffer setup." { centralizeSelection = helpers.defaultNullOpts.mkBool false '' When entering nvim-tree, reposition the view so that the current node is initially centralized, see |zz|. @@ -377,14 +398,15 @@ in { types.str types.int (types.submodule { - options = { - min = helpers.defaultNullOpts.mkNullable (types.either types.str types.int) "30" '' - Minimum dynamic width. - ''; - max = helpers.defaultNullOpts.mkNullable (types.either types.str types.int) "-1" '' + options = let + strOrInt = types.either types.str types.int; + in { + min = helpers.defaultNullOpts.mkNullable strOrInt "30" "Minimum dynamic width."; + + max = helpers.defaultNullOpts.mkNullable strOrInt "-1" '' 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. ''; }; @@ -419,7 +441,7 @@ in { 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 '' Will use only the provided user mappings and not the default otherwise, extends the default mappings with the provided user mappings. @@ -476,7 +498,7 @@ in { key = "p"; action = "print_the_node_path"; action_cb = \'\' - function print_node_path(node) + function(node) print(node.absolute_path) end \'\'; @@ -486,7 +508,7 @@ in { ''; }; - float = { + float = helpers.mkCompositeOption "Configuration options for floating window." { enable = helpers.defaultNullOpts.mkBool false '' Tree window will be floating. ''; @@ -499,8 +521,7 @@ in { }; }; - # UI rendering setup - renderer = { + renderer = helpers.mkCompositeOption "UI rendering setup" { addTrailing = helpers.defaultNullOpts.mkBool false '' Appends a trailing slash to folder names. ''; @@ -565,8 +586,7 @@ in { Number of spaces for an each tree nesting level. Minimum 1. ''; - # Configuration options for tree indent markers. - indentMarkers = { + indentMarkers = helpers.mkCompositeOption "Configuration options for tree indent markers." { enable = helpers.defaultNullOpts.mkBool false '' Display indent markers when folders are open ''; @@ -576,8 +596,7 @@ in { |renderer.icons.show.folder_arrow|. ''; - # Icons shown before the file/directory. Length 1. - icons = { + icons = helpers.mkCompositeOption "Icons shown before the file/directory. Length 1." { corner = helpers.defaultNullOpts.mkStr "└" ""; edge = helpers.defaultNullOpts.mkStr "│" ""; item = helpers.defaultNullOpts.mkStr "│" ""; @@ -586,8 +605,7 @@ in { }; }; - # Configuration options for icons. - icons = { + icons = helpers.mkCompositeOption "Configuration options for icons." { webdevColors = helpers.defaultNullOpts.mkBool true '' Use the webdev icon colors, otherwise `NvimTreeFileIcon`. ''; @@ -622,8 +640,7 @@ in { Used as a separator between symlinks' source and target. ''; - # Configuration options for showing icon types. - show = { + show = helpers.mkCompositeOption "Configuration options for showing icon types." { file = helpers.defaultNullOpts.mkBool true '' 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 = { + glyphs = helpers.mkCompositeOption "Configuration options for icon glyphs." { default = helpers.defaultNullOpts.mkStr "" '' Glyph for files. Will be overridden by `nvim-web-devicons` if available. ''; @@ -662,8 +678,7 @@ in { Icon to display for modified files. ''; - # Glyphs for directories. - folder = { + folder = helpers.mkCompositeOption "Glyphs for directories." { arrowClosed = helpers.defaultNullOpts.mkStr "" '' Arrow glyphs for closed directories. ''; @@ -690,8 +705,7 @@ in { ''; }; - # Glyphs for git status. - git = { + git = helpers.mkCompositeOption "Glyphs for git status." { unstaged = helpers.defaultNullOpts.mkStr "✗" '' Glyph for unstaged nodes. ''; @@ -728,8 +742,7 @@ in { ''; }; - # Filtering options - filters = { + filters = helpers.mkCompositeOption "Filtering options." { dotfiles = helpers.defaultNullOpts.mkBool false '' Do not show dotfiles: files starting with a `.` Toggle via the `toggle_dotfiles` action, default mapping `H`. @@ -760,17 +773,16 @@ in { ''; }; - # Configuration options for trashing - trash.cmd = helpers.defaultNullOpts.mkStr "gio trash" '' - The command used to trash items (must be installed on your system). - The default is shipped with glib2 which is a common linux package. - Only available for UNIX. - ''; + trash = helpers.mkCompositeOption "Configuration options for trashing." { + cmd = helpers.defaultNullOpts.mkStr "gio trash" '' + The command used to trash items (must be installed on your system). + The default is shipped with glib2 which is a common linux package. + Only available for UNIX. + ''; + }; - # Configuration for various actions - actions = { - # vim |current-directory| behaviour - changeDir = { + actions = helpers.mkCompositeOption "Configuration for various actions." { + changeDir = helpers.mkCompositeOption "vim |current-directory| behaviour." { enable = helpers.defaultNullOpts.mkBool true '' Change the working directory when changing directories in the tree. ''; @@ -785,8 +797,7 @@ in { ''; }; - # Configuration for expand_all behaviour - expandAll = { + expandAll = helpers.mkCompositeOption "Configuration for expand_all behaviour." { maxFolderDiscovery = helpers.defaultNullOpts.mkInt 300 '' Limit the number of folders being explored when expanding every folders. Avoids hanging neovim when running this action on very large folders. @@ -798,62 +809,66 @@ in { ''; }; - # Configuration for file_popup behaviour - filePopup.openWinConfig = openWinConfigOption; - - # Configuration options for opening a file from nvim-tree - openFile = { - quitOnOpen = helpers.defaultNullOpts.mkBool false '' - Closes the explorer when opening a file. - It will also disable preventing a buffer overriding the tree. - ''; - - resizeWindow = helpers.defaultNullOpts.mkBool true '' - Resizes the tree when opening a file. - ''; - - # Window picker configuration - windowPicker = { - enable = helpers.defaultNullOpts.mkBool true '' - Enable the feature. If the feature is not enabled, files will open in window from - which you last opened the tree. - ''; - - picker = - helpers.defaultNullOpts.mkNullable - (types.either types.str helpers.rawType) - "default" - '' - Change the default window picker, can be a string `"default"` or a function. - The function should return the window id that will open the node, or `nil` if an - invalid window is picked or user cancelled the action. - - This can be both a string or a function (see example below). - picker = { __raw = "require('window-picker').pick_window"; }; - ''; - - chars = helpers.defaultNullOpts.mkStr "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" '' - A string of chars used as identifiers by the window picker. - ''; - - exclude = - helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) - '' - { - filetype = [ "notify" "packer" "qf" "diff" "fugitive" "fugitiveblame" ]; - buftype = [ "nofile" "terminal" "help" ]; - }; - '' - '' - Table of buffer option names mapped to a list of option values that indicates to - the picker that the buffer's window should not be selectable. - ''; - }; + filePopup = helpers.mkCompositeOption "Configuration for file_popup behaviour." { + openWinConfig = openWinConfigOption; }; - removeFile.closeWindow = helpers.defaultNullOpts.mkBool true '' - Close any window displaying a file when removing the file from the tree. - ''; + openFile = + helpers.mkCompositeOption + "Configuration options for opening a file from nvim-tree." + { + quitOnOpen = helpers.defaultNullOpts.mkBool false '' + Closes the explorer when opening a file. + It will also disable preventing a buffer overriding the tree. + ''; + + resizeWindow = helpers.defaultNullOpts.mkBool true '' + Resizes the tree when opening a file. + ''; + }; + + windowPicker = helpers.mkCompositeOption "Window picker configuration." { + enable = helpers.defaultNullOpts.mkBool true '' + Enable the feature. If the feature is not enabled, files will open in window from + which you last opened the tree. + ''; + + picker = + helpers.defaultNullOpts.mkNullable + (types.either types.str helpers.rawType) + "default" + '' + Change the default window picker, can be a string `"default"` or a function. + The function should return the window id that will open the node, or `nil` if an + invalid window is picked or user cancelled the action. + + This can be both a string or a function (see example below). + picker = { __raw = "require('window-picker').pick_window"; }; + ''; + + chars = helpers.defaultNullOpts.mkStr "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" '' + A string of chars used as identifiers by the window picker. + ''; + + exclude = + helpers.defaultNullOpts.mkNullable (with types; attrsOf (listOf str)) + '' + { + filetype = [ "notify" "packer" "qf" "diff" "fugitive" "fugitiveblame" ]; + buftype = [ "nofile" "terminal" "help" ]; + }; + '' + '' + Table of buffer option names mapped to a list of option values that indicates to + the picker that the buffer's window should not be selectable. + ''; + }; + + removeFile = helpers.mkCompositeOption "" { + closeWindow = helpers.defaultNullOpts.mkBool true '' + Close any window displaying a file when removing the file from the tree. + ''; + }; useSystemClipboard = helpers.defaultNullOpts.mkBool true '' A boolean value that toggle the use of system clipboard when copy/paste function are @@ -863,25 +878,27 @@ in { ''; }; - # Configurations for the live_filtering feature. - # The live filter allows you to filter the tree nodes dynamically, based on - # regex matching (see |vim.regex|). - # This feature is bound to the `f` key by default. - # The filter can be cleared with the `F` key by default. - liveFilter = { - prefix = helpers.defaultNullOpts.mkStr "[FILTER]: " '' - Prefix of the filter displayed in the buffer. - ''; + liveFilter = + helpers.mkCompositeOption + '' + Configurations for the live_filtering feature. + The live filter allows you to filter the tree nodes dynamically, based on regex matching + (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 of the filter displayed in the buffer. + ''; - alwaysShowFolders = helpers.defaultNullOpts.mkBool true '' - Whether to filter folders or not. - ''; - }; + alwaysShowFolders = helpers.defaultNullOpts.mkBool true '' + Whether to filter folders or not. + ''; + }; - # Configuration for tab behaviour - tab = { - # Configuration for syncing nvim-tree across tabs - sync = { + tab = helpers.mkCompositeOption "Configuration for tab behaviour." { + sync = helpers.mkCompositeOption "Configuration for syncing nvim-tree across tabs." { open = helpers.defaultNullOpts.mkBool false '' Opens the tree automatically when switching tabpage or opening a new tabpage if the tree was previously open. @@ -898,20 +915,19 @@ in { }; }; - # Configuration for notification - notify.threshold = helpers.defaultNullOpts.mkEnum ["error" "warning" "info" "debug"] "info" '' - Specify minimum notification level, uses the values from |vim.log.levels| + notify = helpers.mkCompositeOption "Configuration for notification." { + threshold = helpers.defaultNullOpts.mkEnum ["error" "warning" "info" "debug"] "info" '' + Specify minimum notification level, uses the values from |vim.log.levels| - - `error`: hard errors e.g. failure to read from the file system. - - `warning`: non-fatal errors e.g. unable to system open a file. - - `info:` information only e.g. file copy path confirmation. - - `debug:` not used. - ''; + - `error`: hard errors e.g. failure to read from the file system. + - `warning`: non-fatal errors e.g. unable to system open a file. + - `info:` information only e.g. file copy path confirmation. + - `debug:` not used. + ''; + }; - # General UI configuration - ui = { - # Confirmation prompts - confirm = { + ui = helpers.mkCompositeOption "General UI configuration." { + confirm = helpers.mkCompositeOption "Confirmation prompts." { remove = helpers.defaultNullOpts.mkBool true '' Prompt before removing. ''; @@ -922,8 +938,7 @@ in { }; }; - # Configuration for diagnostic logging - log = { + log = helpers.mkCompositeOption "Configuration for diagnostic logging." { enable = helpers.defaultNullOpts.mkBool false '' Enable logging to a file `$XDG_CACHE_HOME/nvim/nvim-tree.log` ''; @@ -932,8 +947,7 @@ in { Remove existing log file at startup. ''; - # Specify which information to log - types = { + types = helpers.mkCompositeOption "Specify which information to log." { all = helpers.defaultNullOpts.mkBool false "Everything."; profile = helpers.defaultNullOpts.mkBool false "Timing of some operations."; @@ -971,169 +985,200 @@ in { sync_root_with_cwd = syncRootWithCwd; reload_on_bufenter = reloadOnBufenter; respect_buf_cwd = respectBufCwd; - hijack_directories = with hijackDirectories; { - inherit enable; - auto_open = autoOpen; - }; - update_focused_file = with updateFocusedFile; { - inherit enable; - update_root = updateRoot; - ignore_list = ignoreList; - }; - system_open = { - inherit (systemOpen) cmd args; - }; - diagnostics = with diagnostics; { - inherit enable; - debounce_delay = debounceDelay; - show_on_dirs = showOnDirs; - show_on_open_dirs = showOnOpenDirs; - inherit icons; - severity = - mapAttrs ( - name: value: - if value == null - then null - else helpers.mkRaw "vim.diagnostic.severity.${strings.toUpper value}" - ) - severity; - }; - git = with git; { - inherit enable; - inherit ignore; - show_on_dirs = showOnDirs; - show_on_open_dirs = showOnOpenDirs; - inherit timeout; - }; - modified = with modified; { - inherit enable; - show_on_dirs = showOnDirs; - show_on_open_dirs = showOnOpenDirs; - }; - filesystem_watchers = with filesystemWatchers; { - inherit enable; - debounce_delay = debounceDelay; - ignore_dirs = ignoreDirs; - }; + hijack_directories = with hijackDirectories; + ifNonNull' cfg.hijackDirectories { + inherit enable; + auto_open = autoOpenEnabled; + }; + update_focused_file = with updateFocusedFile; + ifNonNull' cfg.updateFocusedFile { + inherit enable; + update_root = updateRoot; + ignore_list = ignoreList; + }; + system_open = helpers.ifNonNull systemOpen; + diagnostics = with diagnostics; + ifNonNull' cfg.diagnostics { + inherit enable; + debounce_delay = debounceDelay; + show_on_dirs = showOnDirs; + show_on_open_dirs = showOnOpenDirs; + inherit icons; + severity = ifNonNull' cfg.diagnostics.severity ( + mapAttrs ( + name: value: + ifNonNull' value + (helpers.mkRaw "vim.diagnostic.severity.${strings.toUpper value}") + ) + severity + ); + }; + git = with git; + ifNonNull' cfg.git { + inherit enable; + inherit ignore; + show_on_dirs = showOnDirs; + show_on_open_dirs = showOnOpenDirs; + inherit timeout; + }; + modified = with modified; + ifNonNull' cfg.modified { + inherit enable; + show_on_dirs = showOnDirs; + show_on_open_dirs = showOnOpenDirs; + }; + filesystem_watchers = with filesystemWatchers; + ifNonNull' cfg.filesystemWatchers { + inherit enable; + debounce_delay = debounceDelay; + ignore_dirs = ignoreDirs; + }; on_attach = onAttach; remove_keymaps = removeKeymaps; select_prompts = selectPrompts; - view = with view; { - centralize_selection = centralizeSelection; - inherit cursorline; - debounce_delay = debounceDelay; - hide_root_folder = hideRootFolder; - inherit width; - inherit side; - preserve_window_proportions = preserveWindowProportions; - inherit number; - inherit relativenumber; - inherit signcolumn; - mappings = with mappings; { - custom_only = customOnly; - list = - if list == null - then null - else - map ( - mapping: { - inherit (mapping) key action mode; - action_cb = - if (mapping.action_cb == null) - then null - else helpers.mkRaw mapping.action_cb; - } - ) - list; - }; - float = with float; { - inherit enable; - quit_on_focus_loss = quitOnFocusLoss; - open_win_config = openWinConfig; - }; - }; - renderer = with renderer; { - add_trailing = addTrailing; - group_empty = groupEmpty; - full_name = fullName; - highlight_git = highlightGit; - highlight_opened_files = highlightOpenedFiles; - highlight_modified = highlightModified; - root_folder_label = rootFolderLabel; - indent_width = indentWidth; - indent_markers = with indentMarkers; { - inherit enable icons; - inline_arrows = inlineArrows; - }; - icons = with icons; { - webdev_colors = webdevColors; - git_placement = gitPlacement; - modified_placement = modifiedPlacement; - inherit padding; - symlink_arrow = symlinkArrow; - show = with show; { - inherit file folder git modified; - folder_arrow = folderArrow; - }; - glyphs = with glyphs; { - inherit default symlink modified git; - folder = with folder; { - arrow_closed = arrowClosed; - arrow_open = arrowOpen; - inherit default open empty symlink; - empty_open = emptyOpen; - symlink_open = symlinkOpen; + view = with view; + ifNonNull' cfg.view { + centralize_selection = centralizeSelection; + inherit cursorline; + debounce_delay = debounceDelay; + hide_root_folder = hideRootFolder; + inherit width; + inherit side; + preserve_window_proportions = preserveWindowProportions; + inherit number; + inherit relativenumber; + inherit signcolumn; + mappings = with mappings; + ifNonNull' cfg.view.mappings { + custom_only = customOnly; + list = + if list == null + then null + else + map ( + mapping: { + inherit (mapping) key action mode; + action_cb = + if (mapping.action_cb == null) + then null + else helpers.mkRaw mapping.action_cb; + } + ) + list; + }; + float = with float; + ifNonNull' cfg.view.float { + inherit enable; + quit_on_focus_loss = quitOnFocusLoss; + open_win_config = openWinConfig; }; - }; }; - special_files = specialFiles; - symlink_destination = symlinkDestination; - }; - filters = with filters; { - inherit dotfiles custom exclude; - git_clean = gitClean; - no_buffer = noBuffer; - }; - trash.cmd = trash.cmd; - actions = with actions; { - change_dir = with changeDir; { - inherit enable global; - restrict_above_cwd = restrictAboveCwd; + renderer = with renderer; + ifNonNull' cfg.renderer { + add_trailing = addTrailing; + group_empty = groupEmpty; + full_name = fullName; + highlight_git = highlightGit; + highlight_opened_files = highlightOpenedFiles; + highlight_modified = highlightModified; + root_folder_label = rootFolderLabel; + indent_width = indentWidth; + indent_markers = with indentMarkers; + ifNonNull' cfg.renderer.indentMarkers { + inherit enable icons; + inline_arrows = inlineArrows; + }; + icons = with icons; + ifNonNull' cfg.renderer.icons { + webdev_colors = webdevColors; + git_placement = gitPlacement; + modified_placement = modifiedPlacement; + inherit padding; + symlink_arrow = symlinkArrow; + show = with show; + ifNonNull' cfg.renderer.icons.show { + inherit file folder git modified; + folder_arrow = folderArrow; + }; + glyphs = with glyphs; + ifNonNull' cfg.renderer.icons.glyphs { + inherit default symlink modified git; + folder = with folder; { + arrow_closed = arrowClosed; + arrow_open = arrowOpen; + inherit default open empty symlink; + empty_open = emptyOpen; + symlink_open = symlinkOpen; + }; + }; + }; + special_files = specialFiles; + symlink_destination = symlinkDestination; }; - expand_all = with expandAll; { - max_folder_discovery = maxFolderDiscovery; - inherit exclude; + filters = with filters; + ifNonNull' cfg.filters { + inherit dotfiles custom exclude; + git_clean = gitClean; + no_buffer = noBuffer; }; - file_popup.open_win_config = filePopup.openWinConfig; - open_file = with openFile; { - quit_on_open = quitOnOpen; - resize_window = resizeWindow; - window_picker = windowPicker; + inherit trash; + actions = with actions; + ifNonNull' cfg.actions { + change_dir = with changeDir; + ifNonNull' cfg.actions.changeDir { + inherit enable global; + restrict_above_cwd = restrictAboveCwd; + }; + expand_all = with expandAll; + ifNonNull' cfg.actions.expandAll { + max_folder_discovery = maxFolderDiscovery; + inherit exclude; + }; + file_popup = with filePopup; + ifNonNull' cfg.actions.filePopup { + open_win_config = filePopup.openWinConfig; + }; + open_file = with openFile; + ifNonNull' cfg.actions.openFile { + quit_on_open = quitOnOpen; + resize_window = resizeWindow; + window_picker = windowPicker; + }; + remove_file = with removeFile; + ifNonNull' cfg.actions.removeFile { + close_window = removeFile.closeWindow; + }; + use_system_clipboard = useSystemClipboard; + }; + live_filter = with liveFilter; + ifNonNull' cfg.liveFilter { + inherit prefix; + always_show_folders = alwaysShowFolders; }; - remove_file.close_window = removeFile.closeWindow; - use_system_clipboard = useSystemClipboard; - }; - live_filter = with liveFilter; { - inherit prefix; - always_show_folders = alwaysShowFolders; - }; inherit tab; - notify.threshold = - if notify.threshold == null - then null - else helpers.mkRaw "vim.log.levels.${strings.toUpper notify.threshold}"; - inherit ui; - log = with log; { - inherit enable truncate; - types = with log.types; { - inherit all profile dev diagnostics git watcher; - inherit (log.types) config; - copy_paste = copyPaste; + notify = with notify; + ifNonNull' cfg.notify { + threshold = + ifNonNull' cfg.notify.threshold + (helpers.mkRaw "vim.log.levels.${strings.toUpper notify.threshold}"); + }; + inherit ui; + log = with log; + ifNonNull' cfg.log { + inherit enable truncate; + types = ifNonNull' log.types ( + with log.types; { + inherit all profile dev diagnostics git watcher; + inherit (log.types) config; + copy_paste = copyPaste; + } + ); }; - }; } // cfg.extraOptions; + autoOpenEnabled = cfg.openOnSetup or cfg.openOnSetupFile; + openNvimTreeFunction = '' local function open_nvim_tree(data) @@ -1202,7 +1247,7 @@ in { autoCmd = [] - ++ (optional (cfg.openOnSetup or cfg.openOnSetupFile) { + ++ (optional autoOpenEnabled { event = "VimEnter"; callback = helpers.mkRaw "open_nvim_tree"; }) @@ -1212,11 +1257,12 @@ in { nested = true; }); - extraConfigLua = '' - ${openNvimTreeFunction} + extraConfigLua = + (optionalString autoOpenEnabled openNvimTreeFunction) + + '' - require('nvim-tree').setup(${helpers.toLuaObject options}) - ''; + require('nvim-tree').setup(${helpers.toLuaObject options}) + ''; extraPackages = [pkgs.git]; }; } diff --git a/tests/plugins/nvim-tree.nix b/tests/plugins/nvim-tree.nix new file mode 100644 index 00000000..3cfc0d3a --- /dev/null +++ b/tests/plugins/nvim-tree.nix @@ -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 = ["" "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; + }; + }; + }; + }; +}