1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-08 19:46:06 +01:00

modules/lsp: port packageFallback option from plugins.lsp

Added to `plugins.lsp` in 6a054de04d
This commit is contained in:
Matt Sturgeon 2025-09-28 22:36:42 +01:00
parent 4cec67651a
commit 167ea865e5
3 changed files with 68 additions and 1 deletions

View file

@ -138,9 +138,16 @@ in
(builtins.catAttrs "warnings") (builtins.catAttrs "warnings")
builtins.concatLists builtins.concatLists
]; ];
packages = lib.pipe enabledServers [
(builtins.filter (server: server ? package))
(builtins.groupBy (server: if server.packageFallback then "suffix" else "prefix"))
(builtins.mapAttrs (_: builtins.catAttrs "package"))
];
in in
{ {
extraPackages = builtins.catAttrs "package" enabledServers; extraPackages = lib.mkIf (packages.prefix or [ ] != [ ]) packages.prefix;
extraPackagesAfter = lib.mkIf (packages.suffix or [ ] != [ ]) packages.suffix;
lsp.luaConfig.content = lsp.luaConfig.content =
let let

View file

@ -54,6 +54,16 @@ in
''; '';
}; };
packageFallback = lib.mkOption {
type = types.bool;
default = false;
description = ''
When enabled, the language server package will be added to the end of the `PATH` _(suffix)_ instead of the beginning _(prefix)_.
This can be useful if you want local versions of the language server (e.g. from a devshell) to override the nixvim version.
'';
};
settings = lib.mkOption { settings = lib.mkOption {
type = with types; attrsOf anything; type = with types; attrsOf anything;
description = '' description = ''

View file

@ -28,4 +28,54 @@
}; };
}; };
}; };
package-fallback =
{ lib, config, ... }:
{
test.buildNixvim = false;
lsp = {
servers = {
nil_ls.enable = true;
rust_analyzer = {
enable = true;
packageFallback = true;
};
hls = {
enable = true;
packageFallback = true;
};
};
};
assertions =
let
assertPrefix = name: pkg: [
{
assertion = lib.all (x: x == pkg) config.extraPackages;
message = "Expected `${name}` to be in extraPackages";
}
{
assertion = lib.any (x: x != pkg) config.extraPackagesAfter;
message = "Expected `${name}` not to be in extraPackagesAfter";
}
];
assertSuffix = name: pkg: [
{
assertion = lib.all (x: x != pkg) config.extraPackages;
message = "Expected `${name}` not to be in extraPackages";
}
{
assertion = lib.any (x: x == pkg) config.extraPackagesAfter;
message = "Expected `${name}` to be in extraPackagesAfter";
}
];
in
with config.lsp.servers;
(
assertPrefix "nil" nil_ls.package
++ assertSuffix "rust-analyzer" rust_analyzer.package
++ assertSuffix "haskell-language-server" hls.package
);
};
} }