summaryrefslogtreecommitdiff
path: root/lua/plugins/formatter.lua
blob: cc600e5ed452143987a144348ea4e2b8f4c1418f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
return {
    {
        "conform.nvim",
        event = { "BufReadPre", "BufNewFile" },
        for_cats = "core.general",
        after = function()
            local conform = require("conform")

            conform.setup({
                format_after_save = {
                    lsp_format = "fallback",
                    quiet = true,
                },

                formatters_by_ft = {
                    lua = { "stylua" },
                    go = { "gofmt" },
                    rust = { "rustfmt" },
                    toml = { "tombi" },
                    java = { "google-java-format" },
                    cmake = { "cmake_format" },
                    typescript = { "prettierd" },
                    javascript = { "prettierd" },
                    c = { "clang-format" },
                    cpp = { "clang-format" },
                    python = { "ruff_fix", "ruff_organize_imports", "ruff_format" },
                },

                formatters = {
                    ["google-java-format"] = {
                        prepend_args = { "--aosp" },
                    },
                    ["clang-format"] = {
                        prepend_args = { "-style={BasedOnStyle: LLVM, IndentWidth: 4, TabWidth: 4, UseTab: Never}" },
                    },
                },
            })

            vim.keymap.set({ "n", "v" }, "<leader>lf", function()
                conform.format({ async = true })
            end, {
                desc = "Language format",
            })
        end,
    },
}