2025-10-24 10:35:01 +03:00
|
|
|
{
|
|
|
|
|
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;
|
2025-11-12 17:09:40 +02:00
|
|
|
autoInstall.enable = true;
|
2025-10-24 10:35:01 +03:00
|
|
|
settings = {
|
2025-12-29 10:19:20 +02:00
|
|
|
default_format_opts.lsp_format = "fallback";
|
2025-10-24 10:35:01 +03:00
|
|
|
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;
|
|
|
|
|
};
|
2025-11-12 17:09:40 +02:00
|
|
|
python = [ "ruff_format" ];
|
2025-10-24 10:35:01 +03:00
|
|
|
lua = [ "stylua" ];
|
2025-12-29 10:19:20 +02:00
|
|
|
nix = [ "nixfmt" ];
|
2025-10-24 10:35:01 +03:00
|
|
|
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" ];
|
2025-11-12 17:09:40 +02:00
|
|
|
go = [
|
|
|
|
|
"goimports"
|
|
|
|
|
"gofmt"
|
|
|
|
|
];
|
2025-12-29 10:19:20 +02:00
|
|
|
# Auto correct misspelled words
|
|
|
|
|
# "*" = [ "codebook" ];
|
2025-10-24 10:35:01 +03:00
|
|
|
"_" = [ "trim_whitespace" ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formatters = {
|
2025-12-29 10:19:20 +02:00
|
|
|
# Disabling because if project has a project limitatiton, then
|
|
|
|
|
# formatter not working at all
|
|
|
|
|
# terraform_fmt = {
|
|
|
|
|
# command = "${lib.getExe (
|
|
|
|
|
# pkgs.terraform.overrideAttrs (oldAttrs: {
|
|
|
|
|
# meta = lib.recursiveUpdate oldAttrs.meta {
|
|
|
|
|
# license = lib.licenses.gpl3Only;
|
|
|
|
|
# };
|
|
|
|
|
# })
|
|
|
|
|
# )}";
|
|
|
|
|
# };
|
2025-10-24 10:35:01 +03:00
|
|
|
};
|
2025-12-29 10:19:20 +02:00
|
|
|
format_on_save = # Lua
|
|
|
|
|
''
|
|
|
|
|
function(bufnr)
|
|
|
|
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2025-12-29 12:27:55 +02:00
|
|
|
if slow_format_filetypes[vim.bo[bufnr].filetype] then
|
|
|
|
|
return
|
|
|
|
|
end
|
2025-12-29 10:19:20 +02:00
|
|
|
|
|
|
|
|
local function on_format(err)
|
2025-12-29 12:27:55 +02:00
|
|
|
if err and err:match("timeout$") then
|
|
|
|
|
slow_format_filetypes[vim.bo[bufnr].filetype] = true
|
|
|
|
|
end
|
2025-12-29 10:19:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return { timeout_ms = 200, lsp_fallback = true }, on_format
|
|
|
|
|
end
|
|
|
|
|
'';
|
2025-12-29 12:27:55 +02:00
|
|
|
format_after_save = # Lua
|
|
|
|
|
''
|
|
|
|
|
function(bufnr)
|
|
|
|
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return { lsp_fallback = true }
|
|
|
|
|
end
|
|
|
|
|
'';
|
2025-12-29 10:19:20 +02:00
|
|
|
log_level = "warn";
|
|
|
|
|
notify_on_error = true;
|
|
|
|
|
notify_no_formatters = false;
|
2025-10-24 10:35:01 +03:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
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)";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
};
|
2025-10-23 19:50:10 +03:00
|
|
|
}
|