From ffc4d73814ff06f06bfb9ee14ffde722aec494aa Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 24 Sep 2025 13:41:29 +0200 Subject: [PATCH] plugins/chadtree: migrate to mkNeovimPlugin --- plugins/by-name/chadtree/default.nix | 513 +----------------- plugins/by-name/chadtree/renamed-options.nix | 322 +++++++++++ .../plugins/by-name/chadtree/default.nix | 250 +++++---- 3 files changed, 475 insertions(+), 610 deletions(-) create mode 100644 plugins/by-name/chadtree/renamed-options.nix diff --git a/plugins/by-name/chadtree/default.nix b/plugins/by-name/chadtree/default.nix index c8f1ed02..d7ad0e74 100644 --- a/plugins/by-name/chadtree/default.nix +++ b/plugins/by-name/chadtree/default.nix @@ -1,506 +1,29 @@ { lib, - helpers, - config, - pkgs, ... }: -with lib; -let - cfg = config.plugins.chadtree; - mkListStr = helpers.defaultNullOpts.mkNullable (types.listOf types.str); -in -{ - options.plugins.chadtree = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "chadtree"; +lib.nixvim.plugins.mkNeovimPlugin { + name = "chadtree"; - package = lib.mkPackageOption pkgs "chadtree" { - default = [ - "vimPlugins" - "chadtree" - ]; - }; + maintainers = [ lib.maintainers.GaetanLepage ]; - options = { - follow = helpers.defaultNullOpts.mkBool true '' - CHADTree will highlight currently open file, and open all its parents. - ''; + # TODO introduced 2025-09-24: remove after 26.05 + deprecateExtraOptions = true; + optionsRenamedToSettings = import ./renamed-options.nix; - lang = helpers.mkNullOrOption types.str '' - CHADTree will guess your locale from unix environmental variables. - Set to `c` to disable emojis. - ''; - - mimetypes = { - warn = - mkListStr - [ - "audio" - "font" - "image" - "video" - ] - '' - Show a warning before opening these datatypes. - ''; - - allowExts = mkListStr [ ".ts" ] '' - Skip warning for these extensions. - ''; - }; - - pageIncrement = helpers.defaultNullOpts.mkInt 5 '' - Change how many lines `{` and `}` scroll. - ''; - - pollingRate = helpers.defaultNullOpts.mkNum 2.0 '' - CHADTree's background refresh rate. - ''; - - session = helpers.defaultNullOpts.mkBool true '' - Save & restore currently open folders. - ''; - - showHidden = helpers.defaultNullOpts.mkBool false '' - Hide some files and folders by default. By default this can be toggled using the `.` key. - see `chadtree_settings.ignore` for more details. - ''; - - versionControl = helpers.defaultNullOpts.mkBool true '' - Enable version control. This can also be toggled. But unlike `show_hidden`, does not have a default keybind. - ''; - - ignore = { - nameExact = - mkListStr - [ - ".DS_Store" - ".directory" - "thumbs.db" - ".git" - ] - '' - Files whose name match these exactly will be ignored. - ''; - - nameGlob = mkListStr [ ] '' - Files whose name match these glob patterns will be ignored. - ie. `*.py` will match all python files - ''; - - pathGlob = mkListStr [ ] '' - Files whose full path match these glob patterns will be ignored. - ''; - }; - }; - - view = { - openDirection = - helpers.defaultNullOpts.mkEnum - [ - "left" - "right" - ] - "left" - '' - Which way does CHADTree open? - ''; - - sortBy = - mkListStr - [ - "is_folder" - "ext" - "file_name" - ] - '' - CHADTree can sort by the following criterion. - Reorder them if you want a different sorting order. - legal keys: some of - `["is_folder" "ext" "file_name"]` - ''; - - width = helpers.defaultNullOpts.mkInt 40 '' - How big is CHADTree when initially opened? - ''; - - windowOptions = - helpers.defaultNullOpts.mkAttributeSet - '' - { - cursorline = true; - number = false; - relativenumber = false; - signcolumn = "no"; - winfixwidth = true; - wrap = false; - } - '' - '' - Set of window local options to for CHADTree windows. - ''; - }; - - theme = { - highlights = { - ignored = helpers.defaultNullOpts.mkStr "Comment" '' - These are used for files that are ignored by user supplied pattern - in `chadtree.ignore` and by version control. - ''; - - bookmarks = helpers.defaultNullOpts.mkStr "Title" '' - These are used to show bookmarks. - ''; - - quickfix = helpers.defaultNullOpts.mkStr "Label" '' - These are used to notify the number of times a file / folder appears in the `quickfix` list. - ''; - - versionControl = helpers.defaultNullOpts.mkStr "Comment" '' - These are used to put a version control status beside each file. - ''; - }; - - iconGlyphSet = - helpers.defaultNullOpts.mkEnum - [ - "devicons" - "emoji" - "ascii" - "ascii_hollow" - ] - "devicons" - '' - Icon glyph set to use. - ''; - - textColourSet = - helpers.defaultNullOpts.mkEnum - [ - "env" - "solarized_dark_256" - "solarized_dark" - "solarized_light" - "solarized_universal" - "nord" - "trapdoor" - "nerdtree_syntax_light" - "nerdtree_syntax_dark" - ] - "env" - '' - On `unix`, the command `ls` can produce coloured results based on the `LS_COLORS` environmental variable. - - CHADTree can pretend it's `ls` by setting `chadtree.theme.textColourSet` to `env`. - - If you are not happy with that, you can choose one of the many others. - ''; - - iconColourSet = - helpers.defaultNullOpts.mkEnum - [ - "github" - "none" - ] - "github" - '' - Right now you all the file icons are coloured according to Github colours. - - You may also disable colouring if you wish. - ''; - }; - - keymap = { - windowManagement = { - quit = mkListStr [ "q" ] '' - Close CHADTree window, quit if it is the last window. - ''; - - bigger = - mkListStr - [ - "+" - "=" - ] - '' - Resize CHADTree window bigger. - ''; - - smaller = - mkListStr - [ - "-" - "_" - ] - '' - Resize CHADTree window smaller. - ''; - - refresh = mkListStr [ "" ] '' - Refresh CHADTree. - ''; - }; - - rerooting = { - changeDir = mkListStr [ "b" ] '' - Change vim's working directory. - ''; - - changeFocus = mkListStr [ "c" ] '' - Set CHADTree's root to folder at cursor. Does not change working directory. - ''; - - changeFocusUp = mkListStr [ "C" ] '' - Set CHADTree's root one level up. - ''; - }; - - openFileFolder = { - primary = mkListStr [ "" ] '' - Open file at cursor. - ''; - - secondary = mkListStr [ " <2-leftmouse>" ] '' - Open file at cursor, keep cursor in CHADTree's window. - ''; - - tertiary = - mkListStr - [ - "" - "" - ] - '' - Open file at cursor in a new tab. - ''; - - vSplit = mkListStr [ "w" ] '' - Open file at cursor in vertical split. - ''; - - hSplit = mkListStr [ "W" ] '' - Open file at cursor in horizontal split. - ''; - - openSys = mkListStr [ "o" ] '' - Open file with GUI tools using `open` or `xdg open`. - This will open third party tools such as Finder or KDE Dolphin or GNOME nautilus, etc. - Depends on platform and user setup. - ''; - - collapse = mkListStr [ "o" ] '' - Collapse all subdirectories for directory at cursor. - ''; - }; - - cursor = { - refocus = mkListStr [ "~" ] '' - Put cursor at the root of CHADTree. - ''; - - jumpToCurrent = mkListStr [ "J" ] '' - Position cursor in CHADTree at currently open buffer, if the buffer points to a location visible under CHADTree. - ''; - - stat = mkListStr [ "K" ] '' - Print `ls --long` stat for file under cursor. - ''; - - copyName = mkListStr [ "y" ] '' - Copy paths of files under cursor or visual block. - ''; - - copyBasename = mkListStr [ "Y" ] '' - Copy names of files under cursor or visual block. - ''; - - copyRelname = mkListStr [ "" ] '' - Copy relative paths of files under cursor or visual block. - ''; - }; - - filtering = { - filter = mkListStr [ "f" ] '' - Set a glob pattern to narrow down visible files. - ''; - - clearFilter = mkListStr [ "F" ] '' - Clear filter. - ''; - }; - - bookmarks = { - bookmarkGoto = mkListStr [ "m" ] '' - Goto bookmark `A-Z`. - ''; - }; - - selecting = { - select = mkListStr [ "s" ] '' - Select files under cursor or visual block. - ''; - - clearSelection = mkListStr [ "S" ] '' - Clear selection. - ''; - }; - - fileOperations = { - new = mkListStr [ "a" ] '' - Create new file at location under cursor. Files ending with platform specific path separator will be folders. - - Intermediary folders are created automatically. - - ie. `uwu/owo/` under unix will create `uwu/` then `owo/` under it. Both are folders. - ''; - - link = mkListStr [ "A" ] '' - Create links at location under cursor from selection. - - Links are always relative. - - Intermediary folders are created automatically. - ''; - - rename = mkListStr [ "r" ] '' - Rename file under cursor. - ''; - - toggleExec = mkListStr [ "X" ] '' - Toggle all the `+x` bits of the selected / highlighted files. - - Except for directories, where `-x` will prevent reading. - ''; - - copy = mkListStr [ "p" ] '' - Copy the selected files to location under cursor. - ''; - - cut = mkListStr [ "x" ] '' - Move the selected files to location under cursor. - ''; - - delete = mkListStr [ "d" ] '' - Delete the selected files. Items deleted cannot be recovered. - ''; - - trash = mkListStr [ "t" ] '' - Trash the selected files using platform specific `trash` command, if they are available. - Items trashed may be recovered. - ''; - }; - - toggles = { - toggleHidden = mkListStr [ "." ] '' - Toggle show_hidden on and off. See `chadtree.showHidden` for details. - ''; - - toggleFollow = mkListStr [ "u" ] '' - Toggle `follow` on and off. See `chadtree.follow` for details. - ''; - - toggleVersionControl = mkListStr [ "i" ] '' - Toggle version control integration on and off. - ''; - }; - }; + callSetup = false; + settingsDescription = "Options provided as `vim.api.nvim_set_var('chadtree_settings', settings)`."; + extraConfig = cfg: { + plugins.chadtree.luaConfig.content = '' + vim.api.nvim_set_var("chadtree_settings", ${lib.nixvim.toLuaObject cfg.settings}) + ''; }; - config = - let - setupOptions = with cfg; { - xdg = true; - options = with cfg.options; { - inherit follow; - inherit lang; - mimetypes = with mimetypes; { - inherit warn; - allow_exts = allowExts; - }; - page_increment = pageIncrement; - polling_rate = pollingRate; - inherit session; - show_hidden = showHidden; - version_control = versionControl; - ignore = with ignore; { - name_exact = nameExact; - name_glob = nameGlob; - path_glob = pathGlob; - }; - }; - view = with view; { - open_direction = openDirection; - sort_by = sortBy; - inherit width; - window_options = windowOptions; - }; - theme = with theme; { - highlights = with highlights; { - inherit ignored; - inherit bookmarks; - inherit quickfix; - version_control = versionControl; - }; - icon_glyph_set = iconGlyphSet; - text_colour_set = textColourSet; - icon_colour_set = iconColourSet; - }; - keymap = - with keymap; - with windowManagement; - with rerooting; - with openFileFolder; - with cursor; - with filtering; - with bookmarks; - with selecting; - with fileOperations; - with toggles; - { - inherit quit; - inherit bigger; - inherit smaller; - inherit refresh; - change_dir = changeDir; - change_focus = changeFocus; - change_focus_up = changeFocusUp; - inherit primary; - inherit secondary; - inherit tertiary; - v_split = vSplit; - h_split = hSplit; - open_sys = openSys; - inherit collapse; - inherit refocus; - jump_to_current = jumpToCurrent; - inherit stat; - copy_name = copyName; - copy_basename = copyBasename; - copy_relname = copyRelname; - inherit filter; - clear_filter = clearFilter; - bookmark_goto = bookmarkGoto; - inherit select; - clear_selection = clearSelection; - inherit new; - inherit link; - inherit rename; - toggle_exec = toggleExec; - inherit copy; - inherit cut; - inherit delete; - inherit trash; - toggle_hidden = toggleHidden; - toggle_follow = toggleFollow; - toggle_version_control = toggleVersionControl; - }; - }; - in - mkIf cfg.enable { - extraPlugins = [ cfg.package ]; - - extraConfigLua = '' - vim.api.nvim_set_var("chadtree_settings", ${lib.nixvim.toLuaObject setupOptions}) - ''; + settingsExample = { + view.window_options.relativenumber = true; + theme = { + icon_glyph_set = "devicons"; + text_colour_set = "nerdtree_syntax_dark"; }; + }; } diff --git a/plugins/by-name/chadtree/renamed-options.nix b/plugins/by-name/chadtree/renamed-options.nix new file mode 100644 index 00000000..720e75db --- /dev/null +++ b/plugins/by-name/chadtree/renamed-options.nix @@ -0,0 +1,322 @@ +[ + # OPTIONS + [ + "options" + "follow" + ] + [ + "options" + "lang" + ] + [ + "options" + "mimetypes" + "warn" + ] + [ + "options" + "mimetypes" + "allowExts" + ] + [ + "options" + "pageIncrement" + ] + [ + "options" + "pollingRate" + ] + [ + "options" + "session" + ] + [ + "options" + "showHidden" + ] + [ + "options" + "versionControl" + ] + [ + "options" + "ignore" + "nameExact" + ] + [ + "options" + "ignore" + "nameGlob" + ] + [ + "options" + "ignore" + "pathGlob" + ] + + # VIEW + [ + "view" + "openDirection" + ] + [ + "view" + "sortBy" + ] + [ + "view" + "width" + ] + [ + "view" + "windowOptions" + ] + + # THEME + [ + "theme" + "highlights" + "ignored" + ] + [ + "theme" + "highlights" + "bookmarks" + ] + [ + "theme" + "highlights" + "quickfix" + ] + [ + "theme" + "highlights" + "versionControl" + ] + [ + "theme" + "iconGlyphSet" + ] + [ + "theme" + "textColourSet" + ] + [ + "theme" + "iconColourSet" + ] + + # KEYMAP + [ + "keymap" + "windowManagement" + ] + [ + "keymap" + "rerooting" + ] + [ + "keymap" + "openFileFolder" + ] + [ + "keymap" + "cursor" + ] + [ + "keymap" + "filtering" + ] + [ + "keymap" + "bookmarks" + ] + [ + "keymap" + "selecting" + ] + [ + "keymap" + "fileOperations" + ] + [ + "keymap" + "toggles" + "quit" + ] + [ + "keymap" + "toggles" + "bigger" + ] + [ + "keymap" + "toggles" + "smaller" + ] + [ + "keymap" + "toggles" + "refresh" + ] + [ + "keymap" + "toggles" + "changeDir" + ] + [ + "keymap" + "toggles" + "changeFocus" + ] + [ + "keymap" + "toggles" + "changeFocusUp" + ] + [ + "keymap" + "toggles" + "primary" + ] + [ + "keymap" + "toggles" + "secondary" + ] + [ + "keymap" + "toggles" + "tertiary" + ] + [ + "keymap" + "toggles" + "vSplit" + ] + [ + "keymap" + "toggles" + "hSplit" + ] + [ + "keymap" + "toggles" + "openSys" + ] + [ + "keymap" + "toggles" + "collapse" + ] + [ + "keymap" + "toggles" + "refocus" + ] + [ + "keymap" + "toggles" + "jumpToCurrent" + ] + [ + "keymap" + "toggles" + "stat" + ] + [ + "keymap" + "toggles" + "copyName" + ] + [ + "keymap" + "toggles" + "copyBasename" + ] + [ + "keymap" + "toggles" + "copyRelname" + ] + [ + "keymap" + "toggles" + "filter" + ] + [ + "keymap" + "toggles" + "clearFilter" + ] + [ + "keymap" + "toggles" + "bookmarkGoto" + ] + [ + "keymap" + "toggles" + "select" + ] + [ + "keymap" + "toggles" + "clearSelection" + ] + [ + "keymap" + "toggles" + "new" + ] + [ + "keymap" + "toggles" + "link" + ] + [ + "keymap" + "toggles" + "rename" + ] + [ + "keymap" + "toggles" + "toggle_Exec" + ] + [ + "keymap" + "toggles" + "copy" + ] + [ + "keymap" + "toggles" + "cut" + ] + [ + "keymap" + "toggles" + "delete" + ] + [ + "keymap" + "toggles" + "trash" + ] + [ + "keymap" + "toggles" + "toggleHidden" + ] + [ + "keymap" + "toggles" + "toggleFollow" + ] + [ + "keymap" + "toggles" + "toggleVersionControl" + ] +] diff --git a/tests/test-sources/plugins/by-name/chadtree/default.nix b/tests/test-sources/plugins/by-name/chadtree/default.nix index 53bb902d..5dc91df6 100644 --- a/tests/test-sources/plugins/by-name/chadtree/default.nix +++ b/tests/test-sources/plugins/by-name/chadtree/default.nix @@ -6,130 +6,150 @@ example = { plugins = { web-devicons.enable = true; + chadtree = { enable = true; - options = { - follow = true; - mimetypes = { - warn = [ - "audio" - "font" - "image" - "video" - ]; - allowExts = [ ".ts" ]; - }; - pageIncrement = 5; - pollingRate = 2.0; - session = true; - showHidden = false; - versionControl = true; - ignore = { - nameExact = [ - ".DS_Store" - ".directory" - "thumbs.db" - ".git" - ]; - nameGlob = [ ]; - pathGlob = [ ]; + settings = { + view.window_options.relativenumber = true; + theme = { + icon_glyph_set = "devicons"; + text_colour_set = "nerdtree_syntax_dark"; }; }; - view = { - openDirection = "left"; - sortBy = [ - "is_folder" - "ext" - "file_name" - ]; - width = 40; - windowOptions = { - cursorline = true; - number = false; - relativenumber = false; - signcolumn = "no"; - winfixwidth = true; - wrap = false; + }; + }; + }; + + bigExample = { + plugins = { + web-devicons.enable = true; + chadtree = { + enable = true; + + settings = { + options = { + follow = true; + mimetypes = { + warn = [ + "audio" + "font" + "image" + "video" + ]; + allowExts = [ ".ts" ]; + }; + page_increment = 5; + polling_rate = 2.0; + session = true; + show_hidden = false; + version_control = true; + ignore = { + name_exact = [ + ".DS_Store" + ".directory" + "thumbs.db" + ".git" + ]; + name_glob = [ ]; + path_glob = [ ]; + }; }; - }; - theme = { - highlights = { - ignored = "Comment"; - bookmarks = "Title"; - quickfix = "Label"; - versionControl = "Comment"; - }; - iconGlyphSet = "devicons"; - textColourSet = "env"; - iconColourSet = "github"; - }; - keymap = { - windowManagement = { - quit = [ "q" ]; - bigger = [ - "+" - "=" + view = { + open_direction = "left"; + sort_by = [ + "is_folder" + "ext" + "file_name" ]; - smaller = [ - "-" - "_" - ]; - refresh = [ "" ]; + width = 40; + window_options = { + cursorline = true; + number = false; + relativenumber = false; + signcolumn = "no"; + winfixwidth = true; + wrap = false; + }; }; - rerooting = { - changeDir = [ "b" ]; - changeFocus = [ "c" ]; - changeFocusUp = [ "C" ]; + theme = { + highlights = { + ignored = "Comment"; + bookmarks = "Title"; + quickfix = "Label"; + versionControl = "Comment"; + }; + icon_glyph_set = "devicons"; + text_colour_set = "env"; + icon_colour_set = "github"; }; - openFileFolder = { - primary = [ "" ]; - secondary = [ - "" - "<2-leftmouse>" - ]; - tertiary = [ - "" - "" - ]; - vSplit = [ "w" ]; - hSplit = [ "W" ]; - openSys = [ "o" ]; - collapse = [ "o" ]; - }; - cursor = { - refocus = [ "~" ]; - jumpToCurrent = [ "J" ]; - stat = [ "K" ]; - copyName = [ "y" ]; - copyBasename = [ "Y" ]; - copyRelname = [ "" ]; - }; - filtering = { - filter = [ "f" ]; - clearFilter = [ "F" ]; - }; - bookmarks = { - bookmarkGoto = [ "m" ]; - }; - selecting = { - select = [ "s" ]; - clearSelection = [ "S" ]; - }; - fileOperations = { - new = [ "a" ]; - link = [ "A" ]; - rename = [ "r" ]; - toggleExec = [ "X" ]; - copy = [ "p" ]; - cut = [ "x" ]; - delete = [ "d" ]; - trash = [ "t" ]; - }; - toggles = { - toggleHidden = [ "." ]; - toggleFollow = [ "u" ]; - toggleVersionControl = [ "i" ]; + keymap = { + window_management = { + quit = [ "q" ]; + bigger = [ + "+" + "=" + ]; + smaller = [ + "-" + "_" + ]; + refresh = [ "" ]; + }; + rerooting = { + change_dir = [ "b" ]; + change_focus = [ "c" ]; + change_focus_up = [ "C" ]; + }; + open_file_folder = { + primary = [ "" ]; + secondary = [ + "" + "<2-leftmouse>" + ]; + tertiary = [ + "" + "" + ]; + v_split = [ "w" ]; + h_split = [ "W" ]; + open_sys = [ "o" ]; + collapse = [ "o" ]; + }; + cursor = { + refocus = [ "~" ]; + jump_to_current = [ "J" ]; + stat = [ "K" ]; + copy_name = [ "y" ]; + copy_basename = [ "Y" ]; + copy_relname = [ "" ]; + }; + filtering = { + filter = [ "f" ]; + clear_filter = [ "F" ]; + }; + bookmarks = { + bookmark_goto = [ "m" ]; + }; + selecting = { + select = [ "s" ]; + clear_selection = [ "S" ]; + }; + file_operations = { + new = [ "a" ]; + link = [ "A" ]; + rename = [ "r" ]; + toggle_exec = [ "X" ]; + copy = [ "p" ]; + cut = [ "x" ]; + delete = [ "d" ]; + trash = [ "t" ]; + }; + toggles = { + toggle_hidden = [ "." ]; + toggle_follow = [ "u" ]; + toggle_version_control = [ "i" ]; + }; }; }; };