Skip to content

Commit

Permalink
plugins/lsp: use a no-default option when there is no default provided
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Oct 10, 2024
1 parent 0d2751b commit 88302aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
22 changes: 19 additions & 3 deletions plugins/lsp/language-servers/_mk-lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name,
description ? "Enable ${name}.",
serverName ? name,
package ? name,
package ? null,
url ? null,
cmd ? (cfg: null),
settings ? (cfg: cfg),
Expand Down Expand Up @@ -50,16 +50,32 @@ in
package =
if lib.isOption package then
package
else
else if args ? package then
lib.mkPackageOption pkgs name {
nullable = true;
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 {
type = with types; nullOr (listOf str);
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 = ''
A list where each entry corresponds to the blankspace delimited part of the command that
launches the server.
Expand Down
18 changes: 7 additions & 11 deletions plugins/lsp/language-servers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,6 @@ let

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 [
lib.importJSON
(lib.map (
Expand All @@ -200,8 +191,13 @@ let
inherit name;
description = desc;
}
// (getLspPackage name)
// (lspExtraArgs.${name} or { })
// lib.optionalAttrs (lspPackages.packages ? ${name}) {
package = lspPackages.packages.${name};
}
// lib.optionalAttrs (lspPackages.customCmd ? ${name}) {
inherit (lspPackages.customCmd.${name}) package cmd;
}
// lspExtraArgs.${name} or { }
))
];
in
Expand Down

0 comments on commit 88302aa

Please sign in to comment.