mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-11 11:31:08 +01:00
modules/lsp: fix mkServerOption homepage tryEval evaluation
`lib.pipe` strictly evaluates intermediate steps using `foldl'`. As a result, piping `(opts: opts.package.default or null)` → `(package: (tryEval package).value)` is ineffective because `opts.package.default` is evaluated before `tryEval` can catch exceptions. Instead, inline `opts.package.default` directly into the `tryEval` expression, ensuring missing package errors caught correctly. Resolves errors when building NixOS or nix-darwin docs that include Nixvim options. Adds a regression test.
This commit is contained in:
parent
6ab2b305da
commit
463fb0ad5d
2 changed files with 52 additions and 4 deletions
|
|
@ -40,10 +40,10 @@ let
|
||||||
# Get suboptions of `lsp.servers.<name>`
|
# Get suboptions of `lsp.servers.<name>`
|
||||||
(opts: opts.${name}.type.getSubOptions opts.${name}.loc)
|
(opts: opts.${name}.type.getSubOptions opts.${name}.loc)
|
||||||
# Get the default package
|
# Get the default package
|
||||||
(opts: opts.package.default or null)
|
#
|
||||||
# The default throws if mkPackageOption can't find the package
|
# Use tryEval to catch throws when mkPackageOption can't find the package,
|
||||||
# E.g. mismatched nixpkgs revision
|
# e.g., due to a mismatched nixpkgs revision
|
||||||
(package: (builtins.tryEval package).value)
|
(opts: (builtins.tryEval (opts.package.default or null)).value)
|
||||||
# Get package's homepage
|
# Get package's homepage
|
||||||
(package: package.meta.homepage or null)
|
(package: package.meta.homepage or null)
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
{ pkgs }:
|
||||||
{
|
{
|
||||||
example = {
|
example = {
|
||||||
lsp.servers = {
|
lsp.servers = {
|
||||||
|
|
@ -254,4 +255,51 @@
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Regression test for mkServerOption:
|
||||||
|
# Ensures tryEval catches missing packages when evaluating the description.
|
||||||
|
# See https://github.com/nix-community/nixvim/issues/4033
|
||||||
|
missing-package =
|
||||||
|
{ lib, options, ... }:
|
||||||
|
let
|
||||||
|
# `lsp.servers.lua_ls` option
|
||||||
|
serverOpt = lib.pipe options.lsp.servers [
|
||||||
|
(opt: opt.type.getSubOptions opt.loc)
|
||||||
|
(opts: opts.lua_ls)
|
||||||
|
];
|
||||||
|
|
||||||
|
# `lsp.servers.lua_ls.package` option
|
||||||
|
packageOpt = (serverOpt.type.getSubOptions serverOpt.loc).package;
|
||||||
|
|
||||||
|
# The lua_ls package attr to remove from pkgs
|
||||||
|
packageName = lib.pipe ../../../plugins/lsp/lsp-packages.nix [
|
||||||
|
import
|
||||||
|
(lib.getAttr "packages")
|
||||||
|
(lib.getAttr "lua_ls")
|
||||||
|
lib.toList
|
||||||
|
lib.head
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# Remove lua_ls's package
|
||||||
|
_module.args.pkgs = lib.mkOverride 0 (lib.removeAttrs pkgs [ packageName ]);
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
# Expect the lua_ls description to evaluate without a link
|
||||||
|
assertion = serverOpt.description == "The lua_ls language server.\n";
|
||||||
|
message = ''
|
||||||
|
Wrong description for `${serverOpt}`. Found:
|
||||||
|
${serverOpt.description}
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# Expect the package default to throw
|
||||||
|
assertion = !(builtins.tryEval packageOpt.default).success;
|
||||||
|
message = "Expected `${packageOpt}`'s default to throw.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
test.buildNixvim = false;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue