diff --git a/modules/lsp/default.nix b/modules/lsp/default.nix index 1697a7f5..b64720d4 100644 --- a/modules/lsp/default.nix +++ b/modules/lsp/default.nix @@ -85,28 +85,12 @@ in { # `*` is effectively a meta server, where shared config & defaults can be set. # It shouldn't have options like `activate` or `package` which relate to "real" servers. - # Therefore, we'll use `server-base.nix` directly, instead of the full `server.nix` module. + # Therefore, we use a bespoke `global-server.nix`, which is inspired by the full `server.nix` module. options."*" = lib.mkOption { description = '' Global configuration applied to all language servers. ''; - type = types.submodule ( - lib.modules.importApply ./server-base.nix { - displayName = "all servers"; - enable.name = "the `*` server config"; - enable.default = true; - settings.extraDescription = '' - Will be merged by neovim using the behaviour of [`vim.tbl_deep_extend()`](https://neovim.io/doc/user/lua.html#vim.tbl_deep_extend()). - ''; - settings.example = { - root_markers = [ ".git" ]; - capabilities.textDocument.semanticTokens = { - multilineTokenSupport = true; - }; - }; - } - ); - apply = value: value // { name = "*"; }; + type = types.submodule ./global-server.nix; default = { }; }; } diff --git a/modules/lsp/global-server.nix b/modules/lsp/global-server.nix new file mode 100644 index 00000000..5b64ad45 --- /dev/null +++ b/modules/lsp/global-server.nix @@ -0,0 +1,49 @@ +{ lib, ... }: +let + inherit (lib) types; +in +{ + options = { + enable = lib.mkOption { + type = types.bool; + description = "Whether to enable global defaults shared by all servers."; + default = true; + example = false; + }; + + name = lib.mkOption { + type = types.str; + description = '' + The name to use for global defaults shared by all servers. + + Supplied to functions like `vim.lsp.config()`. + + Will always be `"*"`. + ''; + readOnly = true; + }; + + settings = lib.mkOption { + type = with types; attrsOf anything; + description = '' + Default configuration shared by all servers. + + Will be merged by neovim using the behaviour of [`vim.tbl_deep_extend()`](https://neovim.io/doc/user/lua.html#vim.tbl_deep_extend()). + ''; + default = { }; + example = { + root_markers = [ ".git" ]; + capabilities.textDocument.semanticTokens = { + multilineTokenSupport = true; + }; + }; + }; + }; + + imports = [ + ./server-renames.nix + ]; + + # Define the read-only `name` here, instead of via `default`, to avoid documenting it twice + config.name = "*"; +} diff --git a/modules/lsp/server-base.nix b/modules/lsp/server-base.nix deleted file mode 100644 index 664f6672..00000000 --- a/modules/lsp/server-base.nix +++ /dev/null @@ -1,61 +0,0 @@ -# Usage: lib.importApply ./server-base.nix { /*args*/ } -{ - displayName ? "the language server", - settings ? null, - enable ? null, -}: -{ lib, ... }: -let - inherit (lib) types; -in -{ - options = { - enable = lib.mkOption rec { - type = types.bool; - description = "Whether to enable ${enable.name or displayName}. ${enable.extraDescription or ""}"; - default = enable.default or false; - example = enable.example or (!default); - }; - - settings = lib.mkOption { - type = with types; attrsOf anything; - description = '' - Configurations for ${displayName}. ${settings.extraDescription or ""} - ''; - default = { }; - example = - settings.example or { - cmd = [ - "clangd" - "--background-index" - ]; - root_markers = [ - "compile_commands.json" - "compile_flags.txt" - ]; - filetypes = [ - "c" - "cpp" - ]; - }; - }; - - # NOTE: we need a warnings option for `mkRenamedOptionModule` to warn about unexpected definitions - # This can be removed when all rename aliases are gone - warnings = lib.mkOption { - type = with types; listOf str; - description = "Warnings to propagate to nixvim's `warnings` option."; - default = [ ]; - internal = true; - visible = false; - }; - }; - - imports = [ - # TODO: rename added 2025-04-30 (during the 25.05 cycle) - # The previous name `config` was introduced 2025-04-28 (during the 25.05 cycle) - # Because the previous name `config` never made it into a stable release, - # we could consider dropping this alias sooner than normal. - (lib.mkRenamedOptionModule [ "config" ] [ "settings" ]) - ]; -} diff --git a/modules/lsp/server-renames.nix b/modules/lsp/server-renames.nix new file mode 100644 index 00000000..e97c0332 --- /dev/null +++ b/modules/lsp/server-renames.nix @@ -0,0 +1,21 @@ +{ lib, ... }: +{ + # NOTE: we need a warnings option for `mkRenamedOptionModule` to warn about unexpected definitions + # This can be removed when all rename aliases are gone + options.warnings = lib.mkOption { + type = with lib.types; listOf str; + description = "Warnings to propagate to nixvim's `warnings` option."; + default = [ ]; + internal = true; + visible = false; + }; + + imports = [ + # TODO: rename added 2025-04-30 (during the 25.05 cycle) + # The previous name `config` was introduced 2025-04-28 (during the 25.05 cycle) + # Because the previous name `config` never made it into a stable release, + # we could consider dropping this alias sooner than normal. + (lib.mkRenamedOptionModule [ "config" ] [ "settings" ]) + ]; + +} diff --git a/modules/lsp/server.nix b/modules/lsp/server.nix index 93433848..b0d368af 100644 --- a/modules/lsp/server.nix +++ b/modules/lsp/server.nix @@ -18,6 +18,8 @@ let in { options = { + enable = lib.mkEnableOption displayName; + name = lib.mkOption { type = types.maybeRaw types.str; description = '' @@ -51,11 +53,32 @@ in Alternatively, ${displayName} should be installed on your `$PATH`. ''; }; + + settings = lib.mkOption { + type = with types; attrsOf anything; + description = '' + Configurations for ${displayName}. ${settings.extraDescription or ""} + ''; + default = { }; + example = + settings.example or { + cmd = [ + "clangd" + "--background-index" + ]; + root_markers = [ + "compile_commands.json" + "compile_flags.txt" + ]; + filetypes = [ + "c" + "cpp" + ]; + }; + }; }; imports = [ - (lib.modules.importApply ./server-base.nix { - inherit displayName settings; - }) + ./server-renames.nix ]; }