.config/nvim/lua/plugins/formatter.lua

Mon, 20 May 2024 12:53:43 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 20 May 2024 12:53:43 -0500
changeset 1170
915a78d501d5
parent 1163
40367220022e
permissions
-rw-r--r--

Bump nvim-treesitter to more recent commit

return {
  {
    "stevearc/conform.nvim",
    opts = {
      formatters_by_ft = {
        lua = { "stylua" },
        mail = { "pandoc_markdown" },
        markdown = { "pandoc_markdown" },
        perl = { "perltidy" },
        ruby = { { "standardrb", "rubocop" } },
        sh = { "shfmt" },
        sql = { "pg_format" },
        -- LSP-handled:
        -- elixir = { "mix" },
        -- go = { "goimports", "gofumpt" },
      },
      formatters = {
        pandoc_markdown = {
          command = "pandoc",
          args = { "-f", "markdown", "-t", "markdown" },
          stdin = true,
        },
        shfmt = {
          prepend_args = function(_, ctx)
            return { "-i", vim.bo[ctx.buf].shiftwidth }
          end,
        },
        perltidy = {
          prepend_args = function(_, ctx)
            return { "-i", vim.bo[ctx.buf].shiftwidth }
          end,
        },
      },
      format_on_save = function(bufnr)
        local autoformat_filetypes = { "elixir", "go" }

        if not vim.tbl_contains(autoformat_filetypes, vim.bo[bufnr].filetype) then
          return
        end

        return {
          timeout_ms = 500,
          lsp_fallback = true,
        }
      end
    },
  },
}

mercurial