plugins/conform: add str type for option formatOnSave

This commit is contained in:
Alison Jenkins 2023-12-11 20:36:58 +00:00 committed by Gaétan Lepage
parent 7fbb9240de
commit 14f753cfb6
2 changed files with 64 additions and 18 deletions

View file

@ -38,20 +38,28 @@ in {
'';
formatOnSave =
helpers.defaultNullOpts.mkNullable (types.submodule {
options = {
lspFallback = mkOption {
type = types.bool;
default = true;
description = "See :help conform.format for details.";
};
timeoutMs = mkOption {
type = types.int;
default = 500;
description = "See :help conform.format for details.";
};
};
})
helpers.defaultNullOpts.mkNullable
(
with types;
either
str
(
submodule {
options = {
lspFallback = mkOption {
type = types.bool;
default = true;
description = "See :help conform.format for details.";
};
timeoutMs = mkOption {
type = types.int;
default = 500;
description = "See :help conform.format for details.";
};
};
}
)
)
"see documentation"
''
If this is set, Conform will run the formatter on save.
@ -96,10 +104,13 @@ in {
setupOptions = with cfg;
{
formatters_by_ft = formattersByFt;
format_on_save = helpers.ifNonNull' formatOnSave {
lsp_fallback = formatOnSave.lspFallback;
timeout_ms = formatOnSave.timeoutMs;
};
format_on_save =
if builtins.isAttrs formatOnSave
then {
lsp_fallback = formatOnSave.lspFallback;
timeout_ms = formatOnSave.timeoutMs;
}
else helpers.mkRaw formatOnSave;
format_after_save = helpers.ifNonNull' formatOnSave {
lsp_fallback = formatOnSave.lspFallback;
};