summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/conform.lua
blob: 6356c9595430166f76ec69ab8c09d277fc5422e7 (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
return {
    'stevearc/conform.nvim',
    event = 'VeryLazy',
    cmd = { 'ConformInfo' },
    keys = {
        { '<leader>ft', '<cmd>FormatToggle<cr>', desc = '[F]ormat [T]oggle Globally' },
        { '<leader>fT', '<cmd>FormatToggle!<cr>', desc = '[F]ormat [T]oggle Locally' },
        { '<leader>ff', '<cmd>Format<cr>', desc = '[F]ormat [F]ile' },
    },
    ---@module "conform"
    ---@type conform.setupOpts
    opts = {
        formatters_by_ft = {
            ['lua'] = { 'stylua' },
            ['c'] = { 'clang-format' },
            -- ['python'] = { 'isort', 'black' },
            -- ['rust'] = { 'rustfmt' },
            ['go'] = { 'gofumpt', 'goimports-reviser' },
            ['markdown'] = { 'prettierd', 'prettier', stop_after_first = true },
            ['yaml'] = { 'prettierd' },
            ['json'] = { 'jq' },
            ['html'] = { 'prettierd', 'prettier', stop_after_first = true },
            ['css'] = { 'prettierd', 'prettier', stop_after_first = true },
            ['javascript'] = { 'prettierd', 'prettier', stop_after_first = true },
            ['typescript'] = { 'prettierd', 'prettier', stop_after_first = true },
        },
        format_on_save = function(bufnr)
            -- Disable with a global or buffer local variable
            if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
                return
            end
            return { timeout_ms = 500, lsp_fallback = true }
        end,
        notify_on_error = true,
        lsp_fallback = true,
    },
}