diff --git a/plugins/lsp/default.nix b/plugins/lsp/default.nix index edd7d704b1..1bf4e1d24b 100644 --- a/plugins/lsp/default.nix +++ b/plugins/lsp/default.nix @@ -29,7 +29,7 @@ in }; diagnostic = mkOption { - type = with types; attrsOf (either str attrs); + type = with types; attrsOf (either str (attrsOf anything)); description = "Mappings for `vim.diagnostic.` functions to be added when an LSP is attached."; example = { "k" = "goto_prev"; @@ -39,7 +39,7 @@ in }; lspBuf = mkOption { - type = with types; attrsOf (either str attrs); + type = with types; attrsOf (either str (attrsOf anything)); description = "Mappings for `vim.lsp.buf.` functions to be added when an LSP it attached."; example = { "gd" = "definition"; @@ -106,7 +106,7 @@ in }; extraOptions = mkOption { - type = attrs; + type = attrsOf anything; description = "Extra options for the server"; }; }; diff --git a/tests/test-sources/plugins/lsp/_lsp.nix b/tests/test-sources/plugins/lsp/_lsp.nix index a4fca20488..263f232180 100644 --- a/tests/test-sources/plugins/lsp/_lsp.nix +++ b/tests/test-sources/plugins/lsp/_lsp.nix @@ -156,4 +156,114 @@ } ]; }; + + settings-merge = + { config, lib, ... }: + { + test.runNvim = false; + + plugins = { + lsp = { + enable = true; + servers.nil_ls = { + enable = true; + settings.formatting.command = lib.mkForce [ + "real" + "example" + ]; + }; + enabledServers = lib.mkAfter [ + { + name = "second"; + extraOptions.settings = lib.mkIf false { + should.be = "missing"; + }; + } + { + name = "third"; + extraOptions.settings = lib.mkIf true { + should.be = "present"; + }; + } + ]; + }; + }; + + assertions = + let + toLua = lib.nixvim.lua.toLua' { + removeNullAttrValues = true; + removeEmptyAttrValues = true; + removeEmptyListEntries = false; + removeNullListEntries = false; + multiline = true; + }; + + print = lib.generators.toPretty { + multiline = true; + }; + + serverCount = builtins.length config.plugins.lsp.enabledServers; + expectedCount = 3; + + nilServer = builtins.head config.plugins.lsp.enabledServers; + nilSettings = toLua nilServer.extraOptions.settings; + expectedNilSettings = toLua { + nil.formatting.command = [ + "real" + "example" + ]; + }; + + secondServer = builtins.elemAt config.plugins.lsp.enabledServers 1; + expectedSecondServer = { + name = "second"; + capabilities = null; + extraOptions = { }; + }; + + thirdServer = builtins.elemAt config.plugins.lsp.enabledServers 2; + expectedThirdServer = { + name = "third"; + capabilities = null; + extraOptions.settings.should.be = "present"; + }; + in + [ + { + assertion = serverCount == expectedCount; + message = "Expected ${toString expectedCount} enabled LSP server!"; + } + { + assertion = nilSettings == expectedNilSettings; + message = '' + nil's `extraOptions.settings` does not match expected value. + + Expected: ${expectedNilSettings} + + Actual: ${nilSettings} + ''; + } + { + assertion = secondServer == expectedSecondServer; + message = '' + `secondServer` does not match expected value. + + Expected: ${print expectedSecondServer} + + Actual: ${print secondServer} + ''; + } + { + assertion = secondServer == expectedSecondServer; + message = '' + `thirdServer` does not match expected value. + + Expected: ${print expectedThirdServer} + + Actual: ${print thirdServer} + ''; + } + ]; + }; }