languages: allow listOf format.type

This commit is contained in:
Ching Pei Yang 2025-08-23 16:04:51 +02:00
commit 70555904a0
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
22 changed files with 265 additions and 357 deletions

View file

@ -9,7 +9,7 @@
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.types) mkGrammarOption diagnostics singleOrListOf;
inherit (lib.types) package enum;
inherit (lib.types) enum;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.ruby;
@ -49,11 +49,10 @@
# testing
defaultFormat = "rubocop";
defaultFormat = ["rubocop"];
formats = {
rubocop = {
# TODO: is this right?
package = pkgs.rubyPackages.rubocop;
command = getExe pkgs.rubyPackages.rubocop;
};
};
@ -87,16 +86,10 @@ in {
enable = mkEnableOption "Ruby formatter support" // {default = config.vim.languages.enableFormat;};
type = mkOption {
type = enum (attrNames formats);
type = singleOrListOf (enum (attrNames formats));
default = defaultFormat;
description = "Ruby formatter to use";
};
package = mkOption {
type = package;
default = formats.${cfg.format.type}.package;
description = "Ruby formatter package";
};
};
extraDiagnostics = {
@ -130,10 +123,13 @@ in {
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts.formatters_by_ft.ruby = [cfg.format.type];
setupOpts.formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
setupOpts.formatters_by_ft.ruby = cfg.format.type;
setupOpts.formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
})