Files
nvim/config/modules/plugins/conform-nvim.nix
Mykhailo Nikiforov b614474c26
All checks were successful
check-commits / Check commits (pull_request) Successful in 8s
build-flake / build (pull_request) Successful in 4m2s
feat: add venv-selector, update blink config
2025-11-12 18:03:44 +02:00

142 lines
3.9 KiB
Nix

{
lib,
pkgs,
...
}:
{
config = {
extraConfigLuaPre =
# lua
''
local slow_format_filetypes = {}
vim.api.nvim_create_user_command("FormatDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end, {
desc = "Disable autoformat-on-save",
bang = true,
})
vim.api.nvim_create_user_command("FormatEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})
vim.api.nvim_create_user_command("FormatToggle", function(args)
local Snacks = require("Snacks");
if args.bang then
-- Toggle formatting for current buffer
vim.b.disable_autoformat = not vim.b.disable_autoformat
Snacks.notify.notify("[Buffer] Autoformat enabled: " .. tostring(not vim.b.disable_autoformat))
else
-- Toggle formatting globally
vim.g.disable_autoformat = not vim.g.disable_autoformat
Snacks.notify.notify("[Global] Autoformat enabled: " .. tostring(not vim.g.disable_autoformat))
end
end, {
desc = "Toggle autoformat-on-save",
bang = true,
})
'';
plugins.conform-nvim = {
enable = true;
autoInstall.enable = true;
settings = {
formatters_by_ft = {
html = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
css = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
javascript = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
javascriptreact = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
typescript = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
typescriptreact = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
python = [ "ruff_format" ];
lua = [ "stylua" ];
nix = [ "nixfmt-rfc-style" ];
markdown = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
yaml = {
__unkeyed-1 = "prettierd";
__unkeyed-2 = "prettier";
stop_after_first = true;
};
terraform = [ "terraform_fmt" ];
bash = [
"shellcheck"
"shellharden"
"shfmt"
];
json = [ "jq" ];
go = [
"goimports"
"gofmt"
];
"_" = [ "trim_whitespace" ];
};
formatters = {
terraform_fmt = {
command = "${lib.getExe (
pkgs.terraform.overrideAttrs (oldAttrs: {
meta = lib.recursiveUpdate oldAttrs.meta {
license = lib.licenses.gpl3Only;
};
})
)}";
};
};
};
};
keymaps = [
{
mode = "n";
key = "<leader>uf";
action = "<cmd>FormatToggle<cr>";
options = {
desc = "Toggle Format (Global)";
};
}
{
mode = "n";
key = "<leader>uF";
action = "<cmd>FormatToggle!<cr>";
options = {
desc = "Toggle Format (Buffer)";
};
}
];
};
}