diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index 522f9b33..b1c38e02 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -24,7 +24,7 @@ in { }; diagnostic = mkOption { - type = types.attrsOf types.str; + type = with types; attrsOf (either str attrs); description = "Mappings for `vim.diagnostic.` functions."; example = { "k" = "goto_prev"; @@ -34,7 +34,7 @@ in { }; lspBuf = mkOption { - type = types.attrsOf types.str; + type = with types; attrsOf (either str attrs); description = "Mappings for `vim.lsp.buf.` functions."; example = { "gd" = "definition"; @@ -111,27 +111,28 @@ in { extraPlugins = [pkgs.vimPlugins.nvim-lspconfig]; maps.normal = let - diagnosticMaps = + mkMaps = prefix: mapAttrs - (key: action: { - inherit (cfg.keymaps) silent; - action = "vim.diagnostic.${action}"; - lua = true; - }) - cfg.keymaps.diagnostic; - - lspBuf = - mapAttrs - (key: action: { - inherit (cfg.keymaps) silent; - action = "vim.lsp.buf.${action}"; - lua = true; - }) - cfg.keymaps.lspBuf; + (key: action: let + actionStr = + if isString action + then action + else action.action; + actionProps = + if isString action + then {} + else filterAttrs (n: v: n != "action") action; + in + { + inherit (cfg.keymaps) silent; + action = prefix + actionStr; + lua = true; + } + // actionProps); in mkMerge [ - diagnosticMaps - lspBuf + (mkMaps "vim.diagnostic." cfg.keymaps.diagnostic) + (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf) ]; # Enable all LSP servers diff --git a/tests/test-sources/plugins/lsp/nvim-lsp.nix b/tests/test-sources/plugins/lsp/nvim-lsp.nix index f62c60c0..b9147d16 100644 --- a/tests/test-sources/plugins/lsp/nvim-lsp.nix +++ b/tests/test-sources/plugins/lsp/nvim-lsp.nix @@ -11,7 +11,10 @@ silent = true; diagnostic = { "k" = "goto_prev"; - "j" = "goto_next"; + "j" = { + action = "goto_next"; + desc = "Go to next diagnostic"; + }; }; lspBuf = { @@ -19,7 +22,10 @@ "gD" = "references"; "gt" = "type_definition"; "gi" = "implementation"; - "K" = "hover"; + "K" = { + action = "hover"; + desc = "Hover"; + }; }; };