trouble: lazy load

This commit is contained in:
Ching Pei Yang 2024-09-30 21:58:48 +02:00 committed by Ching Pei Yang
parent 0608e107cd
commit 6c92f6cec5
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9
2 changed files with 20 additions and 16 deletions

View file

@ -3,9 +3,8 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault;
cfg = config.vim.lsp; cfg = config.vim.lsp;
@ -15,15 +14,22 @@
in { in {
config = mkIf (cfg.enable && cfg.trouble.enable) { config = mkIf (cfg.enable && cfg.trouble.enable) {
vim = { vim = {
startPlugins = ["trouble"]; lazy.plugins = [
{
package = "trouble";
setupModule = "trouble";
inherit (cfg.trouble) setupOpts;
maps.normal = mkMerge [ cmd = "Trouble";
(mkSetBinding mappings.toggle "<cmd>TroubleToggle<CR>") keys = [
(mkSetBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>") (mkSetLznBinding mappings.toggle "<cmd>TroubleToggle<CR>")
(mkSetBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>") (mkSetLznBinding mappings.workspaceDiagnostics "<cmd>TroubleToggle workspace_diagnostics<CR>")
(mkSetBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>") (mkSetLznBinding mappings.documentDiagnostics "<cmd>TroubleToggle document_diagnostics<CR>")
(mkSetBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>") (mkSetLznBinding mappings.lspReferences "<cmd>TroubleToggle lsp_references<CR>")
(mkSetBinding mappings.locList "<cmd>TroubleToggle loclist<CR>") (mkSetLznBinding mappings.quickfix "<cmd>TroubleToggle quickfix<CR>")
(mkSetLznBinding mappings.locList "<cmd>TroubleToggle loclist<CR>")
];
}
]; ];
binds.whichKey.register = pushDownDefault { binds.whichKey.register = pushDownDefault {
@ -31,11 +37,6 @@ in {
"<leader>x" = "+Trouble"; "<leader>x" = "+Trouble";
"<leader>lw" = "Workspace"; "<leader>lw" = "Workspace";
}; };
pluginRC.trouble = entryAnywhere ''
-- Enable trouble diagnostics viewer
require("trouble").setup {}
'';
}; };
}; };
} }

View file

@ -1,11 +1,14 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.lsp = { options.vim.lsp = {
trouble = { trouble = {
enable = mkEnableOption "trouble diagnostics viewer"; enable = mkEnableOption "trouble diagnostics viewer";
setupOpts = mkPluginSetupOption "Trouble" {};
mappings = { mappings = {
toggle = mkMappingOption "Toggle trouble [trouble]" "<leader>xx"; toggle = mkMappingOption "Toggle trouble [trouble]" "<leader>xx";
workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd"; workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd";