format.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. return {
  2. "stevearc/conform.nvim",
  3. event = {
  4. "BufReadPre",
  5. "BufNewFile",
  6. },
  7. config = function()
  8. require("conform").setup({
  9. formatters_by_ft = {
  10. graphql = { "prettierd", "prettier" },
  11. njk = { "prettierd", "prettier" },
  12. svelte = { lsp_format = "fallback" },
  13. html = { "prettierd", "prettier" },
  14. typescript = { "prettierd", "prettier" },
  15. typescriptreact = { "prettierd", "prettier" },
  16. javascript = { "prettierd", "prettier", stop_after_first = true },
  17. json = { "prettierd", "prettier" },
  18. htmlhugo = { "prettierd", "prettier" },
  19. markdown = { "prettierd", "prettier" },
  20. lua = { "stylua" },
  21. sh = { "shfmt" },
  22. bash = { "shfmt" },
  23. tex = { "latexindent" },
  24. go = { "gofumpt", "goimports-reviser", "golines" },
  25. cs = { "csharpier" },
  26. templ = { "templ" },
  27. c = { "clang-format" },
  28. cpp = { "clang-format" },
  29. hcl = { "hcl" },
  30. toml = { "taplo" },
  31. typst = { "prettypst" },
  32. java = { "google-java-format" },
  33. nix = { "nixfmt" },
  34. },
  35. formatters = {
  36. csharpier = {
  37. command = "dotnet-csharpier",
  38. args = { "--write-stdout" },
  39. },
  40. ["clang-format"] = {
  41. meta = {
  42. url = "https://clang.llvm.org/docs/ClangFormat.html",
  43. description = "Format C/C++/JavaScript/JSON/Objective-C/Protobuf code.",
  44. },
  45. command = "clang-format",
  46. args = {
  47. "--style={BasedOnStyle: LLVM, BreakBeforeBraces: Attach, AllowShortFunctionsOnASingleLine: None}",
  48. },
  49. },
  50. },
  51. format_on_save = {
  52. timeout_ms = 500,
  53. lsp_fallback = true,
  54. async = false,
  55. },
  56. notify_on_error = false,
  57. })
  58. vim.api.nvim_set_keymap(
  59. "n",
  60. "<leader>cf",
  61. '<cmd>lua require("conform").format()<CR>',
  62. { noremap = true, silent = true }
  63. )
  64. end,
  65. }