mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
plugins/conform: add str type for formatAfterSave
This commit is contained in:
parent
ace360b5de
commit
e9564ac336
2 changed files with 51 additions and 14 deletions
|
@ -40,9 +40,9 @@ in {
|
||||||
formatOnSave =
|
formatOnSave =
|
||||||
helpers.defaultNullOpts.mkNullable
|
helpers.defaultNullOpts.mkNullable
|
||||||
(
|
(
|
||||||
with types;
|
with helpers.nixvimTypes;
|
||||||
either
|
either
|
||||||
str
|
strLuaFn
|
||||||
(
|
(
|
||||||
submodule {
|
submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -69,15 +69,23 @@ in {
|
||||||
'';
|
'';
|
||||||
|
|
||||||
formatAfterSave =
|
formatAfterSave =
|
||||||
helpers.defaultNullOpts.mkNullable (types.submodule {
|
helpers.defaultNullOpts.mkNullable
|
||||||
options = {
|
(
|
||||||
lspFallback = mkOption {
|
with helpers.nixvimTypes;
|
||||||
type = types.bool;
|
either
|
||||||
default = true;
|
strLuaFn
|
||||||
description = "See :help conform.format for details.";
|
(
|
||||||
};
|
submodule {
|
||||||
};
|
options = {
|
||||||
})
|
lspFallback = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "See :help conform.format for details.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
"see documentation"
|
"see documentation"
|
||||||
''
|
''
|
||||||
If this is set, Conform will run the formatter asynchronously after save.
|
If this is set, Conform will run the formatter asynchronously after save.
|
||||||
|
@ -110,9 +118,12 @@ in {
|
||||||
timeout_ms = formatOnSave.timeoutMs;
|
timeout_ms = formatOnSave.timeoutMs;
|
||||||
}
|
}
|
||||||
else helpers.mkRaw formatOnSave;
|
else helpers.mkRaw formatOnSave;
|
||||||
format_after_save = helpers.ifNonNull' formatAfterSave {
|
format_after_save =
|
||||||
lsp_fallback = formatAfterSave.lspFallback;
|
if builtins.isAttrs formatAfterSave
|
||||||
};
|
then {
|
||||||
|
lsp_fallback = formatOnSave.lspFallback;
|
||||||
|
}
|
||||||
|
else helpers.mkRaw formatAfterSave;
|
||||||
log_level = logLevel;
|
log_level = logLevel;
|
||||||
notify_on_error = notifyOnError;
|
notify_on_error = notifyOnError;
|
||||||
inherit formatters;
|
inherit formatters;
|
||||||
|
|
|
@ -94,4 +94,30 @@
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
custom_format_after_save_function = {
|
||||||
|
plugins.conform-nvim = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
formattersByFt = {
|
||||||
|
lua = ["stylua"];
|
||||||
|
python = ["isort" "black"];
|
||||||
|
javascript = [["prettierd" "prettier"]];
|
||||||
|
"*" = ["codespell"];
|
||||||
|
"_" = ["trimWhitespace"];
|
||||||
|
};
|
||||||
|
|
||||||
|
formatAfterSave = ''
|
||||||
|
function(bufnr)
|
||||||
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not _conform_slow_format_filetypes[vim.bo[bufnr].filetype] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return { lsp_fallback = true }
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue