plugins/lsp: use a no-default option when there is no default provided

This commit is contained in:
Matt Sturgeon 2024-10-10 19:43:40 +01:00
parent 0d2751b53c
commit 88302aa17a
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 26 additions and 14 deletions

View file

@ -8,7 +8,7 @@
name, name,
description ? "Enable ${name}.", description ? "Enable ${name}.",
serverName ? name, serverName ? name,
package ? name, package ? null,
url ? null, url ? null,
cmd ? (cfg: null), cmd ? (cfg: null),
settings ? (cfg: cfg), settings ? (cfg: cfg),
@ -50,16 +50,32 @@ in
package = package =
if lib.isOption package then if lib.isOption package then
package package
else else if args ? package then
lib.mkPackageOption pkgs name { lib.mkPackageOption pkgs name {
nullable = true; nullable = true;
default = package; default = package;
}
else
# If we're not provided a package, we should provide a no-default option
lib.mkOption {
type = types.nullOr types.package;
description = ''
The package to use for ${name}. Has no default, but can be set to null.
'';
}; };
cmd = mkOption { cmd = mkOption {
type = with types; nullOr (listOf str); type = with types; nullOr (listOf str);
default = default =
if (cfg.package or null) != null then if builtins.isFunction cmd then cmd cfg else cmd else null; # TODO: do we really only want the default `cmd` when `package` is non-null?
if !(opt.package.isDefined or false) then
null
else if cfg.package == null then
null
else if builtins.isFunction cmd then
cmd cfg
else
cmd;
description = '' description = ''
A list where each entry corresponds to the blankspace delimited part of the command that A list where each entry corresponds to the blankspace delimited part of the command that
launches the server. launches the server.

View file

@ -179,15 +179,6 @@ let
lspPackages = import ../lsp-packages.nix; lspPackages = import ../lsp-packages.nix;
getLspPackage =
name:
if lib.hasAttr name lspPackages.packages then
{ package = lspPackages.packages.${name}; }
else if lib.hasAttr name lspPackages.customCmd then
{ inherit (lspPackages.customCmd.${name}) package cmd; }
else
{ package = null; };
generatedServers = lib.pipe ../../../generated/lspconfig-servers.json [ generatedServers = lib.pipe ../../../generated/lspconfig-servers.json [
lib.importJSON lib.importJSON
(lib.map ( (lib.map (
@ -200,8 +191,13 @@ let
inherit name; inherit name;
description = desc; description = desc;
} }
// (getLspPackage name) // lib.optionalAttrs (lspPackages.packages ? ${name}) {
// (lspExtraArgs.${name} or { }) package = lspPackages.packages.${name};
}
// lib.optionalAttrs (lspPackages.customCmd ? ${name}) {
inherit (lspPackages.customCmd.${name}) package cmd;
}
// lspExtraArgs.${name} or { }
)) ))
]; ];
in in