mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
plugins/conform: add str type for option formatOnSave
This commit is contained in:
parent
7fbb9240de
commit
14f753cfb6
2 changed files with 64 additions and 18 deletions
|
@ -38,20 +38,28 @@ in {
|
||||||
'';
|
'';
|
||||||
|
|
||||||
formatOnSave =
|
formatOnSave =
|
||||||
helpers.defaultNullOpts.mkNullable (types.submodule {
|
helpers.defaultNullOpts.mkNullable
|
||||||
options = {
|
(
|
||||||
lspFallback = mkOption {
|
with types;
|
||||||
type = types.bool;
|
either
|
||||||
default = true;
|
str
|
||||||
description = "See :help conform.format for details.";
|
(
|
||||||
};
|
submodule {
|
||||||
timeoutMs = mkOption {
|
options = {
|
||||||
type = types.int;
|
lspFallback = mkOption {
|
||||||
default = 500;
|
type = types.bool;
|
||||||
description = "See :help conform.format for details.";
|
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"
|
"see documentation"
|
||||||
''
|
''
|
||||||
If this is set, Conform will run the formatter on save.
|
If this is set, Conform will run the formatter on save.
|
||||||
|
@ -96,10 +104,13 @@ in {
|
||||||
setupOptions = with cfg;
|
setupOptions = with cfg;
|
||||||
{
|
{
|
||||||
formatters_by_ft = formattersByFt;
|
formatters_by_ft = formattersByFt;
|
||||||
format_on_save = helpers.ifNonNull' formatOnSave {
|
format_on_save =
|
||||||
lsp_fallback = formatOnSave.lspFallback;
|
if builtins.isAttrs formatOnSave
|
||||||
timeout_ms = formatOnSave.timeoutMs;
|
then {
|
||||||
};
|
lsp_fallback = formatOnSave.lspFallback;
|
||||||
|
timeout_ms = formatOnSave.timeoutMs;
|
||||||
|
}
|
||||||
|
else helpers.mkRaw formatOnSave;
|
||||||
format_after_save = helpers.ifNonNull' formatOnSave {
|
format_after_save = helpers.ifNonNull' formatOnSave {
|
||||||
lsp_fallback = formatOnSave.lspFallback;
|
lsp_fallback = formatOnSave.lspFallback;
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,4 +59,39 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
custom_format_on_save_function = {
|
||||||
|
plugins.conform-nvim = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
formattersByFt = {
|
||||||
|
lua = ["stylua"];
|
||||||
|
python = ["isort" "black"];
|
||||||
|
javascript = [["prettierd" "prettier"]];
|
||||||
|
"*" = ["codespell"];
|
||||||
|
"_" = ["trimWhitespace"];
|
||||||
|
};
|
||||||
|
|
||||||
|
formatOnSave = ''
|
||||||
|
function(bufnr)
|
||||||
|
local ignore_filetypes = { "helm" }
|
||||||
|
if vim.tbl_contains(ignore_filetypes, vim.bo[bufnr].filetype) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Disable with a global or buffer-local variable
|
||||||
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Disable autoformat for files in a certain path
|
||||||
|
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||||
|
if bufname:match("/node_modules/") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return { timeout_ms = 500, lsp_fallback = true }
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue