nix-community.nixvim/plugins/lsp/language-servers/rust-analyzer.nix
sportshead 6a054de04d
Some checks are pending
Publish every Git push to main to FlakeHub / flakehub-publish (push) Waiting to run
Publish every git push to Flakestry / publish-flake (push) Waiting to run
Documentation / Build unstable (push) Waiting to run
Documentation / Build 24.11 (push) Waiting to run
Documentation / Build 25.05 (push) Waiting to run
Documentation / Combine builds (push) Blocked by required conditions
Documentation / Deploy (push) Blocked by required conditions
plugins/lsp: add packageFallback option
https://github.com/nix-community/nixvim/pull/3445#pullrequestreview-2908615597
2025-06-16 17:19:27 +00:00

83 lines
2.5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.plugins.lsp.servers.rust_analyzer;
inherit (lib) mkPackageOption types;
inherit (lib.nixvim) mkNullOrOption';
extraPackages =
lib.optional (cfg.installCargo == true) cfg.cargoPackage
++ lib.optional (cfg.installRustc == true) cfg.rustcPackage
++ lib.optional (cfg.installRustfmt == true) cfg.rustfmtPackage;
in
{
options.plugins.lsp.servers.rust_analyzer = {
# https://github.com/nix-community/nixvim/issues/674
installCargo = mkNullOrOption' {
type = types.bool;
example = true;
description = "Whether to install `cargo`.";
};
# TODO: make nullable?
cargoPackage = lib.mkPackageOption pkgs "cargo" { };
installRustc = mkNullOrOption' {
type = types.bool;
example = true;
description = "Whether to install `rustc`.";
};
# TODO: make nullable
rustcPackage = mkPackageOption pkgs "rustc" { };
installRustfmt = mkNullOrOption' {
type = types.bool;
example = true;
description = "Whether to install `rustfmt`.";
};
# TODO: make nullable
rustfmtPackage = mkPackageOption pkgs "rustfmt" { };
};
config = lib.mkIf cfg.enable {
warnings = lib.nixvim.mkWarnings "plugins.lsp.servers.rust_analyzer" [
{
when = cfg.installCargo == null;
message = ''
`rust_analyzer` relies on `cargo`.
- Set `plugins.lsp.servers.rust_analyzer.installCargo = true` to install it automatically
with Nixvim.
You can customize which package to install by changing
`plugins.lsp.servers.rust_analyzer.cargoPackage`.
- Set `plugins.lsp.servers.rust_analyzer.installCargo = false` to not have it install
through Nixvim.
By doing so, you will dismiss this warning.
'';
}
{
when = cfg.installRustc == null;
message = ''
`rust_analyzer` relies on `rustc`.
- Set `plugins.lsp.servers.rust_analyzer.installRustc = true` to install it automatically
with Nixvim.
You can customize which package to install by changing
`plugins.lsp.servers.rust_analyzer.rustcPackage`.
- Set `plugins.lsp.servers.rust_analyzer.installRustc = false` to not have it install
through Nixvim.
By doing so, you will dismiss this warning.
'';
}
];
extraPackages = lib.optionals (!cfg.packageFallback) extraPackages;
extraPackagesAfter = lib.optionals cfg.packageFallback extraPackages;
};
}