my dotfiles for arch
1return {
2 "stevearc/conform.nvim",
3 event = { "BufReadPre", "BufNewFile" },
4 config = function()
5 local conform = require("conform")
6
7 conform.setup({
8 formatters_by_ft = {
9 javascript = { "prettierd" },
10 typescript = { "prettierd" },
11 javascriptreact = { "prettierd" },
12 typescriptreact = { "prettierd" },
13 svelte = { "prettierd" },
14 vue = { "prettierd" },
15 css = { "prettierd" },
16 html = { "prettierd" },
17 json = { "prettierd" },
18 yaml = { "prettierd" },
19 markdown = { "prettierd" },
20 graphql = { "prettierd" },
21 lua = { "stylua" },
22 python = { "isort", "black" },
23 astro = { "prettierd" },
24 nix = { "alejandra" },
25 },
26 format_on_save = function(bufnr)
27 -- Disable with a global or buffer-local variable
28 if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
29 return
30 end
31 return { timeout_ms = 1000, lsp_format = "fallback" }
32 end,
33 })
34
35 vim.api.nvim_create_user_command("Format", function(args)
36 local range = nil
37 if args.count ~= -1 then
38 local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
39 range = {
40 start = { args.line1, 0 },
41 ["end"] = { args.line2, end_line:len() },
42 }
43 end
44 require("conform").format({ async = true, lsp_fallback = true, range = range })
45 end, { range = true })
46
47 vim.api.nvim_create_user_command("FormatDisable", function(args)
48 if args.bang then
49 -- FormatDisable! will disable formatting just for this buffer
50 vim.b.disable_autoformat = true
51 else
52 vim.g.disable_autoformat = true
53 end
54 end, {
55 desc = "Disable autoformat-on-save",
56 bang = true,
57 })
58
59 vim.api.nvim_create_user_command("FormatEnable", function()
60 vim.b.disable_autoformat = false
61 vim.g.disable_autoformat = false
62 end, {
63 desc = "Re-enable autoformat-on-save",
64 })
65 end,
66}