From 2f09d48e7c4f8b7c5b8359d056b45023dc8cef8a Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 30 Jul 2023 15:02:36 +0300 Subject: [PATCH] dev: redefine diagnostics as submodules --- modules/filetree/nvimtree/config.nix | 409 +++++++++++++------------ modules/filetree/nvimtree/nvimtree.nix | 69 +++-- 2 files changed, 242 insertions(+), 236 deletions(-) diff --git a/modules/filetree/nvimtree/config.nix b/modules/filetree/nvimtree/config.nix index ecb63f82..e2a789f1 100644 --- a/modules/filetree/nvimtree/config.nix +++ b/modules/filetree/nvimtree/config.nix @@ -24,38 +24,38 @@ in { ]; vim.luaConfigRC.nvimtreelua = nvim.dag.entryAnywhere '' - ${ + ${ lib.optionalString (cfg.openOnSetup) '' - -- Open on startup has been deprecated - -- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup + -- Open on startup has been deprecated + -- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup - -- use a nix eval to dynamically insert the open on startup function - local function open_nvim_tree(data) - local IGNORED_FT = { - "markdown", - } + -- use a nix eval to dynamically insert the open on startup function + local function open_nvim_tree(data) + local IGNORED_FT = { + "markdown", + } - -- buffer is a real file on the disk - local real_file = vim.fn.filereadable(data.file) == 1 + -- buffer is a real file on the disk + local real_file = vim.fn.filereadable(data.file) == 1 - -- buffer is a [No Name] - local no_name = data.file == "" and vim.bo[data.buf].buftype == "" + -- buffer is a [No Name] + local no_name = data.file == "" and vim.bo[data.buf].buftype == "" - -- &ft - local filetype = vim.bo[data.buf].ft + -- &ft + local filetype = vim.bo[data.buf].ft - -- only files please - if not real_file and not no_name then - return - end + -- only files please + if not real_file and not no_name then + return + end - -- skip ignored filetypes - if vim.tbl_contains(IGNORED_FT, filetype) then - return - end + -- skip ignored filetypes + if vim.tbl_contains(IGNORED_FT, filetype) then + return + end - -- open the tree but don't focus it - require("nvim-tree.api").tree.toggle({ focus = false }) + -- open the tree but don't focus it + require("nvim-tree.api").tree.toggle({ focus = false }) end -- function to automatically open the tree on VimEnter @@ -63,86 +63,86 @@ in { '' } - ${ + ${ lib.optionalString (cfg.disableNetrw) '' vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 '' } - 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}, + 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 = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.updateFocusedFile.ignoreList}, + }, + + system_open = { + cmd = "${cfg.systemOpen.cmd}", + args = ${nvim.lua.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}", }, - hijack_unnamed_buffer_when_opening = ${boolToString cfg.hijackUnnamedBufferWhenOpening}, - hijack_cursor = ${boolToString cfg.hijackCursor}, - root_dirs = ${nvim.lua.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}, + severity = { + min = "vim.diagnostic.severity.${cfg.diagnostics.severity.min}", + max = "vim.diagnostic.severity.${cfg.diagnostics.severity.max}", }, + }, - update_focused_file = { - enable = ${boolToString cfg.updateFocusedFile.enable}, - update_root = ${boolToString cfg.updateFocusedFile.updateRoot}, - ignore_list = ${nvim.lua.listToLuaTable cfg.updateFocusedFile.ignoreList}, - }, + git = { + enable = ${boolToString cfg.git.enable}, + show_on_dirs = ${boolToString cfg.git.showOnDirs}, + show_on_open_dirs = ${boolToString cfg.git.showOnOpenDirs}, + disable_for_dirs = ${nvim.lua.listToLuaTable cfg.git.disableForDirs}, + timeout = ${toString cfg.git.timeOut}, + }, - system_open = { - cmd = "${cfg.systemOpen.cmd}", - args = ${nvim.lua.listToLuaTable cfg.systemOpen.args}, - }, + modified = { + enable = ${boolToString cfg.modified.enable}, + show_on_dirs = ${boolToString cfg.modified.showOnDirs}, + show_on_open_dirs = ${boolToString cfg.modified.showOnOpenDirs}, + }, - 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}", - }, + filesystem_watchers = { + enable = ${boolToString cfg.filesystemWatchers.enable}, + debounce_delay = ${toString cfg.filesystemWatchers.debounceDelay}, + ignore_dirs = ${nvim.lua.listToLuaTable cfg.filesystemWatchers.ignoreDirs}, + }, - severity = { - min = "vim.diagnostic.severity.${cfg.diagnostics.severity.min}", - max = "vim.diagnostic.severity.${cfg.diagnostics.severity.max}", - }, - }, + select_prompts = ${boolToString cfg.selectPrompts}, - git = { - enable = ${boolToString cfg.git.enable}, - show_on_dirs = ${boolToString cfg.git.showOnDirs}, - show_on_open_dirs = ${boolToString cfg.git.showOnOpenDirs}, - disable_for_dirs = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.filesystemWatchers.ignoreDirs}, - }, - - select_prompts = ${boolToString cfg.selectPrompts}, - - view = { - centralize_selection = ${boolToString cfg.view.centralizeSelection}, + view = { + centralize_selection = ${boolToString cfg.view.centralizeSelection}, cursorline = ${boolToString cfg.view.cursorline}, debounce_delay = ${toString cfg.view.debounceDelay}, width = ${nvim.lua.expToLua cfg.view.width}, @@ -164,7 +164,7 @@ in { }, }, }, - + renderer = { add_trailing = ${boolToString cfg.renderer.addTrailing}, group_empty = ${boolToString cfg.renderer.groupEmpty}, @@ -179,125 +179,128 @@ in { inline_arrows = ${boolToString cfg.renderer.indentMarkers.inlineArrows}, icons = ${nvim.lua.expToLua cfg.renderer.indentMarkers.icons}, }, - + special_files = ${nvim.lua.listToLuaTable cfg.renderer.specialFiles}, - symlink_destination = ${boolToString cfg.renderer.symlinkDestination}, + 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}", - }, + 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}", - 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}", + 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 = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.actions.expandAll.exclude}, - }, - - file_popup = { - open_win_config = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.filetype}, - buftype = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.buftype}, + 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 = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.actions.expandAll.exclude}, + }, + + file_popup = { + open_win_config = ${nvim.lua.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 = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.filetype}, + buftype = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.buftype}, + }, + }, + }, + + remove_file = { + close_window = ${boolToString cfg.actions.removeFile.closeWindow}, }, }, - }, - - 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 = ${nvim.lua.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}, - }, - }, - })''; + + 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 = ${nvim.lua.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}, + }, + }, + }) + ''; }; } diff --git a/modules/filetree/nvimtree/nvimtree.nix b/modules/filetree/nvimtree/nvimtree.nix index 291d3a27..a68877e0 100644 --- a/modules/filetree/nvimtree/nvimtree.nix +++ b/modules/filetree/nvimtree/nvimtree.nix @@ -118,6 +118,12 @@ with builtins; { hijackDirectories = mkOption { description = "hijack new directory buffers when they are opened (`:e dir`)."; + + default = { + enable = true; + autoOpen = false; + }; + type = types.submodule { options = { enable = mkOption { @@ -136,10 +142,6 @@ with builtins; { }; }; }; - default = { - enable = true; - autoOpen = false; - }; }; updateFocusedFile = mkOption { @@ -147,6 +149,13 @@ with builtins; { Update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file. ''; + + default = { + enable = false; + updateRoot = false; + ignoreList = []; + }; + type = types.submodule { options = { enable = mkEnableOption "update focused file"; @@ -169,9 +178,6 @@ with builtins; { }; }; }; - default = { - ignoreList = []; - }; }; systemOpen = { @@ -199,11 +205,23 @@ with builtins; { debounceDelay = 50; showOnDirs = false; showOnOpenDirs = true; + + icons = { + hint = ""; + info = ""; + warning = ""; + error = ""; + }; + + severity = { + min = "HINT"; + max = "ERROR"; + }; }; type = types.submodule { options = { - enable = mkEnableOption "diagnostics"; + enable = mkEnableOption "Enable diagnostics view in the signcolumn."; debounceDelay = mkOption { description = "Idle milliseconds between diagnostic event and update."; @@ -212,24 +230,17 @@ with builtins; { showOnDirs = mkOption { description = "Show diagnostic icons on parent directories."; - type = types.bool; }; showOnOpenDirs = mkOption { - description = "Show diagnostics icons on directories that are open."; - type = types.bool; + description = '' + Show diagnostics icons on directories that are open. + Only relevant when `diagnostics.show_on_dirs` is `true`. + ''; }; icons = mkOption { description = "Icons for diagnostic severity."; - - default = { - hint = ""; - info = ""; - warning = ""; - error = ""; - }; - type = types.submodule { options = { hint = mkOption { @@ -253,13 +264,7 @@ with builtins; { }; severity = mkOption { - description = "Severity for which the diagnostics will be displayed"; - - default = { - min = "HINT"; - max = "ERROR"; - }; - + description = "Severity for which the diagnostics will be displayed. See `:help diagnostic-severity`"; type = types.submodule { options = { min = mkOption { @@ -316,6 +321,7 @@ with builtins; { description = "Indicate which file have unsaved modification."; default = { + enable = false; showOnDirs = true; showOnOpenDirs = true; }; @@ -382,6 +388,7 @@ with builtins; { view = mkOption { description = "Window / buffer setup."; + default = { centralizeSelection = false; cursorline = true; @@ -405,6 +412,7 @@ with builtins; { }; }; }; + type = types.submodule { options = { centralizeSelection = mkOption { @@ -1066,13 +1074,6 @@ with builtins; { options = { sync = mkOption { description = "Configuration for syncing nvim-tree across tabs."; - - default = { - open = false; - close = false; - ignore = []; - }; - type = types.submodule { options = { open = mkOption { @@ -1126,8 +1127,10 @@ with builtins; { }; }; }; + ui = mkOption { description = "General UI configuration."; + default = { confirm = { remove = true;