From 6c92f6cec5a69a99ebbbc6feac148a67cf0734be Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 30 Sep 2024 21:58:48 +0200 Subject: [PATCH] trouble: lazy load --- modules/plugins/lsp/trouble/config.nix | 33 +++++++++++++------------ modules/plugins/lsp/trouble/trouble.nix | 3 +++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/plugins/lsp/trouble/config.nix b/modules/plugins/lsp/trouble/config.nix index dd853e3..1a7eb46 100644 --- a/modules/plugins/lsp/trouble/config.nix +++ b/modules/plugins/lsp/trouble/config.nix @@ -3,9 +3,8 @@ lib, ... }: let - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.dag) entryAnywhere; - inherit (lib.nvim.binds) addDescriptionsToMappings mkSetBinding pushDownDefault; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault; cfg = config.vim.lsp; @@ -15,15 +14,22 @@ in { config = mkIf (cfg.enable && cfg.trouble.enable) { vim = { - startPlugins = ["trouble"]; + lazy.plugins = [ + { + package = "trouble"; + setupModule = "trouble"; + inherit (cfg.trouble) setupOpts; - maps.normal = mkMerge [ - (mkSetBinding mappings.toggle "TroubleToggle") - (mkSetBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") - (mkSetBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") - (mkSetBinding mappings.lspReferences "TroubleToggle lsp_references") - (mkSetBinding mappings.quickfix "TroubleToggle quickfix") - (mkSetBinding mappings.locList "TroubleToggle loclist") + cmd = "Trouble"; + keys = [ + (mkSetLznBinding mappings.toggle "TroubleToggle") + (mkSetLznBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") + (mkSetLznBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") + (mkSetLznBinding mappings.lspReferences "TroubleToggle lsp_references") + (mkSetLznBinding mappings.quickfix "TroubleToggle quickfix") + (mkSetLznBinding mappings.locList "TroubleToggle loclist") + ]; + } ]; binds.whichKey.register = pushDownDefault { @@ -31,11 +37,6 @@ in { "x" = "+Trouble"; "lw" = "Workspace"; }; - - pluginRC.trouble = entryAnywhere '' - -- Enable trouble diagnostics viewer - require("trouble").setup {} - ''; }; }; } diff --git a/modules/plugins/lsp/trouble/trouble.nix b/modules/plugins/lsp/trouble/trouble.nix index bd16c67..04bd506 100644 --- a/modules/plugins/lsp/trouble/trouble.nix +++ b/modules/plugins/lsp/trouble/trouble.nix @@ -1,11 +1,14 @@ {lib, ...}: let inherit (lib.options) mkEnableOption; inherit (lib.nvim.binds) mkMappingOption; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.lsp = { trouble = { enable = mkEnableOption "trouble diagnostics viewer"; + setupOpts = mkPluginSetupOption "Trouble" {}; + mappings = { toggle = mkMappingOption "Toggle trouble [trouble]" "xx"; workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "lwd";