dev: redefine diagnostics as submodules

This commit is contained in:
raf 2023-07-30 15:02:36 +03:00
parent 500c9b67dd
commit 2f09d48e7c
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 242 additions and 236 deletions

View file

@ -24,38 +24,38 @@ in {
]; ];
vim.luaConfigRC.nvimtreelua = nvim.dag.entryAnywhere '' vim.luaConfigRC.nvimtreelua = nvim.dag.entryAnywhere ''
${ ${
lib.optionalString (cfg.openOnSetup) '' lib.optionalString (cfg.openOnSetup) ''
-- Open on startup has been deprecated -- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup -- 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 -- use a nix eval to dynamically insert the open on startup function
local function open_nvim_tree(data) local function open_nvim_tree(data)
local IGNORED_FT = { local IGNORED_FT = {
"markdown", "markdown",
} }
-- buffer is a real file on the disk -- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1 local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name] -- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == "" local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- &ft -- &ft
local filetype = vim.bo[data.buf].ft local filetype = vim.bo[data.buf].ft
-- only files please -- only files please
if not real_file and not no_name then if not real_file and not no_name then
return return
end end
-- skip ignored filetypes -- skip ignored filetypes
if vim.tbl_contains(IGNORED_FT, filetype) then if vim.tbl_contains(IGNORED_FT, filetype) then
return return
end end
-- open the tree but don't focus it -- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false }) require("nvim-tree.api").tree.toggle({ focus = false })
end end
-- function to automatically open the tree on VimEnter -- function to automatically open the tree on VimEnter
@ -63,86 +63,86 @@ in {
'' ''
} }
${ ${
lib.optionalString (cfg.disableNetrw) '' lib.optionalString (cfg.disableNetrw) ''
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
'' ''
} }
require'nvim-tree'.setup({ require'nvim-tree'.setup({
disable_netrw = ${boolToString cfg.disableNetrw}, disable_netrw = ${boolToString cfg.disableNetrw},
hijack_netrw = ${boolToString cfg.hijackNetrw}, hijack_netrw = ${boolToString cfg.hijackNetrw},
auto_reload_on_write = ${boolToString cfg.autoreloadOnWrite}, auto_reload_on_write = ${boolToString cfg.autoreloadOnWrite},
sort = { sort = {
sorter = "${cfg.sort.sorter}", sorter = "${cfg.sort.sorter}",
folders_first = ${boolToString cfg.sort.foldersFirst}, 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}, severity = {
hijack_cursor = ${boolToString cfg.hijackCursor}, min = "vim.diagnostic.severity.${cfg.diagnostics.severity.min}",
root_dirs = ${nvim.lua.listToLuaTable cfg.rootDirs}, max = "vim.diagnostic.severity.${cfg.diagnostics.severity.max}",
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 = { git = {
enable = ${boolToString cfg.updateFocusedFile.enable}, enable = ${boolToString cfg.git.enable},
update_root = ${boolToString cfg.updateFocusedFile.updateRoot}, show_on_dirs = ${boolToString cfg.git.showOnDirs},
ignore_list = ${nvim.lua.listToLuaTable cfg.updateFocusedFile.ignoreList}, show_on_open_dirs = ${boolToString cfg.git.showOnOpenDirs},
}, disable_for_dirs = ${nvim.lua.listToLuaTable cfg.git.disableForDirs},
timeout = ${toString cfg.git.timeOut},
},
system_open = { modified = {
cmd = "${cfg.systemOpen.cmd}", enable = ${boolToString cfg.modified.enable},
args = ${nvim.lua.listToLuaTable cfg.systemOpen.args}, show_on_dirs = ${boolToString cfg.modified.showOnDirs},
}, show_on_open_dirs = ${boolToString cfg.modified.showOnOpenDirs},
},
diagnostics = { filesystem_watchers = {
enable = ${boolToString cfg.diagnostics.enable}, enable = ${boolToString cfg.filesystemWatchers.enable},
icons = { debounce_delay = ${toString cfg.filesystemWatchers.debounceDelay},
hint = "${cfg.diagnostics.icons.hint}", ignore_dirs = ${nvim.lua.listToLuaTable cfg.filesystemWatchers.ignoreDirs},
info = "${cfg.diagnostics.icons.info}", },
warning = "${cfg.diagnostics.icons.warning}",
error = "${cfg.diagnostics.icons.error}",
},
severity = { select_prompts = ${boolToString cfg.selectPrompts},
min = "vim.diagnostic.severity.${cfg.diagnostics.severity.min}",
max = "vim.diagnostic.severity.${cfg.diagnostics.severity.max}",
},
},
git = { view = {
enable = ${boolToString cfg.git.enable}, centralize_selection = ${boolToString cfg.view.centralizeSelection},
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},
cursorline = ${boolToString cfg.view.cursorline}, cursorline = ${boolToString cfg.view.cursorline},
debounce_delay = ${toString cfg.view.debounceDelay}, debounce_delay = ${toString cfg.view.debounceDelay},
width = ${nvim.lua.expToLua cfg.view.width}, width = ${nvim.lua.expToLua cfg.view.width},
@ -164,7 +164,7 @@ in {
}, },
}, },
}, },
renderer = { renderer = {
add_trailing = ${boolToString cfg.renderer.addTrailing}, add_trailing = ${boolToString cfg.renderer.addTrailing},
group_empty = ${boolToString cfg.renderer.groupEmpty}, group_empty = ${boolToString cfg.renderer.groupEmpty},
@ -179,125 +179,128 @@ in {
inline_arrows = ${boolToString cfg.renderer.indentMarkers.inlineArrows}, inline_arrows = ${boolToString cfg.renderer.indentMarkers.inlineArrows},
icons = ${nvim.lua.expToLua cfg.renderer.indentMarkers.icons}, icons = ${nvim.lua.expToLua cfg.renderer.indentMarkers.icons},
}, },
special_files = ${nvim.lua.listToLuaTable cfg.renderer.specialFiles}, special_files = ${nvim.lua.listToLuaTable cfg.renderer.specialFiles},
symlink_destination = ${boolToString cfg.renderer.symlinkDestination}, symlink_destination = ${boolToString cfg.renderer.symlinkDestination},
icons = { icons = {
webdev_colors = ${boolToString cfg.renderer.icons.webdevColors}, webdev_colors = ${boolToString cfg.renderer.icons.webdevColors},
git_placement = "${cfg.renderer.icons.gitPlacement}", git_placement = "${cfg.renderer.icons.gitPlacement}",
modified_placement = "${cfg.renderer.icons.modifiedPlacement}", modified_placement = "${cfg.renderer.icons.modifiedPlacement}",
padding = "${cfg.renderer.icons.padding}", padding = "${cfg.renderer.icons.padding}",
symlink_arrow = "${cfg.renderer.icons.symlinkArrow}", 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 = { show = {
unstaged = "${cfg.renderer.icons.glyphs.git.unstaged}", git = ${boolToString cfg.renderer.icons.show.git},
staged = "${cfg.renderer.icons.glyphs.git.staged}", folder = ${boolToString cfg.renderer.icons.show.folder},
unmerged = "${cfg.renderer.icons.glyphs.git.unmerged}", folder_arrow = ${boolToString cfg.renderer.icons.show.folderArrow},
renamed = "${cfg.renderer.icons.glyphs.git.renamed}", file = ${boolToString cfg.renderer.icons.show.file},
untracked = "${cfg.renderer.icons.glyphs.git.untracked}", modified = ${boolToString cfg.renderer.icons.show.modified},
deleted = "${cfg.renderer.icons.glyphs.git.deleted}", },
ignored = "${cfg.renderer.icons.glyphs.git.ignored}",
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 = { filters = {
max_folder_discovery = ${toString cfg.actions.expandAll.maxFolderDiscovery}, git_ignored = ${boolToString cfg.filters.gitIgnored},
exclude = ${nvim.lua.listToLuaTable cfg.actions.expandAll.exclude}, dotfiles = ${boolToString cfg.filters.dotfiles},
}, git_clean = ${boolToString cfg.filters.gitClean},
no_buffer = ${boolToString cfg.filters.noBuffer},
file_popup = { exclude = ${nvim.lua.listToLuaTable cfg.filters.exclude},
open_win_config = ${nvim.lua.expToLua cfg.actions.filePopup.openWinConfig}, },
},
trash = {
open_file = { cmd = "${cfg.trash.cmd}",
quit_on_open = ${boolToString cfg.actions.openFile.quitOnOpen}, },
eject = ${boolToString cfg.actions.openFile.eject},
resize_window = ${boolToString cfg.actions.openFile.resizeWindow}, actions = {
window_picker = { use_system_clipboard = ${boolToString cfg.actions.useSystemClipboard},
enable = ${boolToString cfg.actions.openFile.windowPicker.enable}, change_dir = {
picker = "${cfg.actions.openFile.windowPicker.picker}", enable = ${boolToString cfg.actions.changeDir.enable},
chars = "${cfg.actions.openFile.windowPicker.chars}", global = ${boolToString cfg.actions.changeDir.global},
exclude = { restrict_above_cwd = ${boolToString cfg.actions.changeDir.restrictAboveCwd},
filetype = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.filetype}, },
buftype = ${nvim.lua.listToLuaTable cfg.actions.openFile.windowPicker.exclude.buftype},
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},
}, },
}, },
},
live_filter = {
remove_file = { prefix = "${cfg.liveFilter.prefix}",
close_window = ${boolToString cfg.actions.removeFile.closeWindow}, always_show_folders = ${boolToString cfg.liveFilter.alwaysShowFolders},
}, },
},
tab = {
live_filter = { sync = {
prefix = "${cfg.liveFilter.prefix}", open = ${boolToString cfg.tab.sync.open},
always_show_folders = ${boolToString cfg.liveFilter.alwaysShowFolders}, close = ${boolToString cfg.tab.sync.close},
}, ignore = ${nvim.lua.listToLuaTable cfg.tab.sync.ignore},
},
tab = { },
sync = {
open = ${boolToString cfg.tab.sync.open}, notify = {
close = ${boolToString cfg.tab.sync.close}, threshold = vim.log.levels.${cfg.notify.threshold},
ignore = ${nvim.lua.listToLuaTable cfg.tab.sync.ignore}, absolute_path = ${boolToString cfg.notify.absolutePath},
}, },
},
notify = { ui = {
threshold = vim.log.levels.${cfg.notify.threshold}, confirm = {
absolute_path = ${boolToString cfg.notify.absolutePath}, remove = ${boolToString cfg.ui.confirm.remove},
}, trash = ${boolToString cfg.ui.confirm.trash},
ui = { },
confirm = { },
remove = ${boolToString cfg.ui.confirm.remove}, })
trash = ${boolToString cfg.ui.confirm.trash}, '';
},
},
})'';
}; };
} }

View file

@ -118,6 +118,12 @@ with builtins; {
hijackDirectories = mkOption { hijackDirectories = mkOption {
description = "hijack new directory buffers when they are opened (`:e dir`)."; description = "hijack new directory buffers when they are opened (`:e dir`).";
default = {
enable = true;
autoOpen = false;
};
type = types.submodule { type = types.submodule {
options = { options = {
enable = mkOption { enable = mkOption {
@ -136,10 +142,6 @@ with builtins; {
}; };
}; };
}; };
default = {
enable = true;
autoOpen = false;
};
}; };
updateFocusedFile = mkOption { updateFocusedFile = mkOption {
@ -147,6 +149,13 @@ with builtins; {
Update the focused file on `BufEnter`, un-collapses the folders recursively Update the focused file on `BufEnter`, un-collapses the folders recursively
until it finds the file. until it finds the file.
''; '';
default = {
enable = false;
updateRoot = false;
ignoreList = [];
};
type = types.submodule { type = types.submodule {
options = { options = {
enable = mkEnableOption "update focused file"; enable = mkEnableOption "update focused file";
@ -169,9 +178,6 @@ with builtins; {
}; };
}; };
}; };
default = {
ignoreList = [];
};
}; };
systemOpen = { systemOpen = {
@ -199,11 +205,23 @@ with builtins; {
debounceDelay = 50; debounceDelay = 50;
showOnDirs = false; showOnDirs = false;
showOnOpenDirs = true; showOnOpenDirs = true;
icons = {
hint = "";
info = "";
warning = "";
error = "";
};
severity = {
min = "HINT";
max = "ERROR";
};
}; };
type = types.submodule { type = types.submodule {
options = { options = {
enable = mkEnableOption "diagnostics"; enable = mkEnableOption "Enable diagnostics view in the signcolumn.";
debounceDelay = mkOption { debounceDelay = mkOption {
description = "Idle milliseconds between diagnostic event and update."; description = "Idle milliseconds between diagnostic event and update.";
@ -212,24 +230,17 @@ with builtins; {
showOnDirs = mkOption { showOnDirs = mkOption {
description = "Show diagnostic icons on parent directories."; description = "Show diagnostic icons on parent directories.";
type = types.bool;
}; };
showOnOpenDirs = mkOption { showOnOpenDirs = mkOption {
description = "Show diagnostics icons on directories that are open."; description = ''
type = types.bool; Show diagnostics icons on directories that are open.
Only relevant when `diagnostics.show_on_dirs` is `true`.
'';
}; };
icons = mkOption { icons = mkOption {
description = "Icons for diagnostic severity."; description = "Icons for diagnostic severity.";
default = {
hint = "";
info = "";
warning = "";
error = "";
};
type = types.submodule { type = types.submodule {
options = { options = {
hint = mkOption { hint = mkOption {
@ -253,13 +264,7 @@ with builtins; {
}; };
severity = mkOption { severity = mkOption {
description = "Severity for which the diagnostics will be displayed"; description = "Severity for which the diagnostics will be displayed. See `:help diagnostic-severity`";
default = {
min = "HINT";
max = "ERROR";
};
type = types.submodule { type = types.submodule {
options = { options = {
min = mkOption { min = mkOption {
@ -316,6 +321,7 @@ with builtins; {
description = "Indicate which file have unsaved modification."; description = "Indicate which file have unsaved modification.";
default = { default = {
enable = false;
showOnDirs = true; showOnDirs = true;
showOnOpenDirs = true; showOnOpenDirs = true;
}; };
@ -382,6 +388,7 @@ with builtins; {
view = mkOption { view = mkOption {
description = "Window / buffer setup."; description = "Window / buffer setup.";
default = { default = {
centralizeSelection = false; centralizeSelection = false;
cursorline = true; cursorline = true;
@ -405,6 +412,7 @@ with builtins; {
}; };
}; };
}; };
type = types.submodule { type = types.submodule {
options = { options = {
centralizeSelection = mkOption { centralizeSelection = mkOption {
@ -1066,13 +1074,6 @@ with builtins; {
options = { options = {
sync = mkOption { sync = mkOption {
description = "Configuration for syncing nvim-tree across tabs."; description = "Configuration for syncing nvim-tree across tabs.";
default = {
open = false;
close = false;
ignore = [];
};
type = types.submodule { type = types.submodule {
options = { options = {
open = mkOption { open = mkOption {
@ -1126,8 +1127,10 @@ with builtins; {
}; };
}; };
}; };
ui = mkOption { ui = mkOption {
description = "General UI configuration."; description = "General UI configuration.";
default = { default = {
confirm = { confirm = {
remove = true; remove = true;