mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-12 20:11: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
|
|
@ -1,3 +1,4 @@
|
|||
{ pkgs }:
|
||||
{
|
||||
example = {
|
||||
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