From e710afd1ac19c69e1eacd7be7c561c32ce22a80a Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 19 Apr 2024 21:14:41 +0200 Subject: [PATCH] fix: add rename warnings for nvimtree.setupOpts --- .../plugins/filetree/nvimtree/nvimtree.nix | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/modules/plugins/filetree/nvimtree/nvimtree.nix b/modules/plugins/filetree/nvimtree/nvimtree.nix index 8ccd735..b962dfe 100644 --- a/modules/plugins/filetree/nvimtree/nvimtree.nix +++ b/modules/plugins/filetree/nvimtree/nvimtree.nix @@ -3,11 +3,87 @@ lib, ... }: let + inherit (lib.modules) mkRenamedOptionModule; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.generators) mkLuaInline; inherit (lib.types) nullOr str bool int submodule listOf enum oneOf attrs addCheck; inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.lists) flatten; + inherit (lib.attrsets) mapAttrsToList; + + migrationTable = { + disableNetrw = "disable_netrw"; + hijackNetrw = "hijack_netrw"; + autoreloadOnWrite = "autoreload_on_write"; + updateFocusedFile = "update_focused_file"; + sort = { + sorter = "sorter"; + foldersFirst = "folders_first"; + }; + hijackCursor = "hijack_cursor"; + hijackUnnamedBufferWhenOpening = "hijack_unnamed_buffer_when_opening"; + rootDirs = "root_dirs"; + preferStartupRoot = "prefer_startup_root"; + syncRootWithCwd = "sync_root_with_cwd"; + reloadOnBufEnter = "reload_on_buf_enter"; + respectBufCwd = "respect_buf_cwd"; + hijackDirectories = "hijack_directories"; + systemOpen = { + args = "args"; + cmd = "cmd"; + }; + diagnostics = "diagnostics"; + git = { + enable = "enable"; + showOnDirs = "show_on_dirs"; + showOnOpenDirs = "show_on_open_dirs"; + disableForDirs = "disable_for_dirs"; + timeout = "timeout"; + }; + modified = "modified"; + filesystemWatchers = "filesystem_watchers"; + selectPrompts = "select_prompts"; + view = "view"; + renderer = { + addTrailing = "add_trailing"; + groupEmpty = "group_empty"; + fullName = "full_name"; + highlightGit = "highlight_git"; + highlightOpenedFiles = "highlight_opened_files"; + highlightModified = "highlight_modified"; + rootFolderLabel = "root_folder_label"; + indentWidth = "indent_width"; + indentMarkers = "indent_markers"; + specialFiles = "special_files"; + symlinkDestination = "symlink_destination"; + icons = "icons"; + }; + filters = "filters"; + trash = "trash"; + actions = "actions"; + liveFilter = "live_filter"; + tab = "tab"; + notify = "notify"; + ui = "ui"; + }; + + renamedSetupOpts = flatten (genSetupOptRenames [] migrationTable); + + # Note: I cut a few corners so it only works in this specific case + # if the parent of a nested option needs to be renamed, this would not work + genSetupOptRenames = path: table: + mapAttrsToList ( + oldName: newNameOrAttr: + if builtins.isAttrs newNameOrAttr + then genSetupOptRenames (path ++ [oldName]) newNameOrAttr + else + mkRenamedOptionModule + (["vim" "filetree" "nvimTree"] ++ path ++ [oldName]) + (["vim" "filetree" "nvimTree" "setupOpts"] ++ path ++ [newNameOrAttr]) + ) + table; in { + imports = renamedSetupOpts; options.vim.filetree.nvimTree = { enable = mkEnableOption "filetree via nvim-tree.lua";