]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/conform.lua
neovim: configure, using ghostty and tmux
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / conform.lua
1 -- Lightweight yet powerful formatter plugin for Neovim
2 -- https://github.com/stevearc/conform.nvim
3 vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
4 return {
5 "conform.nvim",
6 event = { "BufWritePre" },
7 cmd = { "ConformInfo" },
8 after = function()
9 require("conform").setup({
10 -- Map of filetype to formatters
11 formatters_by_ft = {
12 lua = { "stylua" },
13 -- Conform will run multiple formatters sequentially
14 go = { "goimports", "gofmt" },
15 haskell = { "fourmolu" },
16 nix = { "nixfmt" },
17 -- You can also customize some of the format options for the filetype
18 rust = { "rustfmt", lsp_format = "fallback" },
19 -- You can use a function here to determine the formatters dynamically
20 python = function(bufnr)
21 if require("conform").get_formatter_info("ruff_format", bufnr).available then
22 return { "ruff_format" }
23 else
24 return { "isort", "black" }
25 end
26 end,
27 sh = { "shfmt" },
28 -- Use the "*" filetype to run formatters on all filetypes.
29 ["*"] = { "codespell" },
30 -- Use the "_" filetype to run formatters on filetypes that don't
31 -- have other formatters configured.
32 ["_"] = { "trim_whitespace" },
33 },
34 -- Set this to change the default values when calling conform.format()
35 -- This will also affect the default values for format_on_save/format_after_save
36 default_format_opts = {
37 lsp_format = "fallback",
38 },
39 -- If this is set, Conform will run the formatter on save.
40 -- It will pass the table to conform.format().
41 -- This can also be a function that returns the table.
42 format_after_save = function()
43 if not vim.g.formatsave or vim.b.disableFormatSave then
44 return
45 else
46 return { lsp_format = "fallback" }
47 end
48 end,
49 format_on_save = function()
50 if not vim.g.formatsave or vim.b.disableFormatSave then
51 return
52 else
53 return { lsp_format = "fallback", timeout_ms = 500 }
54 end
55 end,
56 -- Set the log level. Use `:ConformInfo` to see the location of the log file.
57 log_level = vim.log.levels.ERROR,
58 -- Conform will notify you when a formatter errors
59 notify_on_error = true,
60 -- Conform will notify you when no formatters are available for the buffer
61 notify_no_formatters = true,
62 -- Custom formatters and overrides for built-in formatters
63 formatters = {
64 },
65 })
66 end,
67 }