modules/lsp: declare a stripped down servers."*" option

`"*"` 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.
This commit is contained in:
Matt Sturgeon 2025-04-30 22:05:34 +01:00
parent 04c3247144
commit f2e96b67a3
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 94 additions and 46 deletions

View file

@ -75,10 +75,40 @@ in
};
servers = lib.mkOption {
type = types.submodule {
freeformType = types.attrsOf (mkServerType { });
options = builtins.mapAttrs mkServerOption serverPackages;
};
type = types.submodule [
{
freeformType = types.attrsOf (mkServerType { });
}
{
options = builtins.mapAttrs mkServerOption serverPackages;
}
{
# `*` 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.
options."*" = lib.mkOption {
description = ''
Global configuration applied to all language servers.
'';
type = types.submodule (
lib.modules.importApply ./server-base.nix {
displayName = "all servers";
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 = "*"; };
default = { };
};
}
];
description = ''
LSP servers to enable and/or configure.
@ -152,7 +182,7 @@ in
''
vim.lsp.config(${luaName}, ${luaSettings})
''
+ lib.optionalString server.activate ''
+ lib.optionalString (server.activate or false) ''
vim.lsp.enable(${luaName})
'';
in

View file

@ -0,0 +1,55 @@
# Usage: lib.importApply ./server-base.nix { /*args*/ }
{
displayName ? "the language server",
settings ? null,
}:
{ lib, ... }:
let
inherit (lib) types;
in
{
options = {
enable = lib.mkEnableOption displayName;
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" ])
];
}

View file

@ -1,6 +1,6 @@
# Usage: lib.importApply ./server.nix { /*args*/ }
{
name ? null,
name ? "the language server",
package ? null,
settings ? null,
pkgs ? { },
@ -18,8 +18,6 @@ let
in
{
options = {
enable = lib.mkEnableOption displayName;
name = lib.mkOption {
type = types.maybeRaw types.str;
description = ''
@ -53,46 +51,11 @@ 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"
];
};
};
# 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" ])
(lib.modules.importApply ./server-base.nix {
inherit displayName settings;
})
];
}