From 4cdac1381bfee7e3cf4f15e379805c8ecdbc30ec Mon Sep 17 00:00:00 2001 From: Mykhailo Nikiforov Date: Mon, 29 Dec 2025 10:19:20 +0200 Subject: [PATCH] feat(conform): re-enable auto formatting, fix #47 --- config/modules/plugins/conform-nvim.nix | 67 +++++++++++++++++++------ 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/config/modules/plugins/conform-nvim.nix b/config/modules/plugins/conform-nvim.nix index 873f390..346f8a2 100644 --- a/config/modules/plugins/conform-nvim.nix +++ b/config/modules/plugins/conform-nvim.nix @@ -1,8 +1,3 @@ -{ - lib, - pkgs, - ... -}: { config = { extraConfigLuaPre = @@ -48,6 +43,7 @@ enable = true; autoInstall.enable = true; settings = { + default_format_opts.lsp_format = "fallback"; formatters_by_ft = { html = { __unkeyed-1 = "prettierd"; @@ -81,7 +77,7 @@ }; python = [ "ruff_format" ]; lua = [ "stylua" ]; - nix = [ "nixfmt-rfc-style" ]; + nix = [ "nixfmt" ]; markdown = { __unkeyed-1 = "prettierd"; __unkeyed-2 = "prettier"; @@ -103,20 +99,61 @@ "goimports" "gofmt" ]; + # Auto correct misspelled words + # "*" = [ "codebook" ]; "_" = [ "trim_whitespace" ]; }; formatters = { - terraform_fmt = { - command = "${lib.getExe ( - pkgs.terraform.overrideAttrs (oldAttrs: { - meta = lib.recursiveUpdate oldAttrs.meta { - license = lib.licenses.gpl3Only; - }; - }) - )}"; - }; + # 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; + # }; + # }) + # )}"; + # }; }; + format_on_save = # Lua + '' + function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + + if slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + + local function on_format(err) + if err and err:match("timeout$") then + slow_format_filetypes[vim.bo[bufnr].filetype] = true + end + end + + return { timeout_ms = 200, lsp_fallback = true }, on_format + end + ''; + # 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 + # ''; + log_level = "warn"; + notify_on_error = true; + notify_no_formatters = false; }; }; keymaps = [