feat: conform.nvim

This commit is contained in:
punkfairie 2024-12-15 12:21:28 -08:00
parent 83af9ac2ac
commit 7393fc696a
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
4 changed files with 85 additions and 0 deletions

View file

@ -60,6 +60,9 @@ with final.pkgs.lib; let
ts-comments-nvim ts-comments-nvim
mini-ai mini-ai
# Formatting
conform-nvim
# Treesitter # Treesitter
nvim-treesitter-textobjects nvim-treesitter-textobjects
nvim-ts-autotag nvim-ts-autotag
@ -104,6 +107,10 @@ with final.pkgs.lib; let
# Language servers # Language servers
lua-language-server lua-language-server
nixd nixd
# Formatters
shfmt
stylua
]; ];
in { in {
# This is the neovim derivation returned by the overlay. # This is the neovim derivation returned by the overlay.

View file

@ -0,0 +1,43 @@
return {
'conform.nvim',
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<LEADER>cf',
function()
require('conform').format()
end,
desc = 'format',
},
{
'<LEADER>cF',
function()
require('conform').format({
formatters = { 'injected' },
timeout_ms = 3000,
})
end,
mode = { 'n', 'v' },
desc = 'format injected langs',
},
},
after = function()
require('conform').setup({
format_on_save = function(buf)
if (vim.g.autoformat == false) or (vim.b[buf].autoformat == false) then
return
end
return { timeout_ms = 3000, lsp_format = 'fallback' }
end,
formatters_by_ft = {
lua = { 'stylua' },
fish = { 'fish_indent' },
sh = { 'shfmt' },
},
})
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -0,0 +1,5 @@
local req = MarleyVim.local_require('plugins.formatting')
return {
req('conform-nvim'),
}

View file

@ -61,6 +61,36 @@ if vim.lsp.inlay_hint then
toggle.inlay_hints():map('<LEADER>uh') toggle.inlay_hints():map('<LEADER>uh')
end end
toggle({
name = 'auto format (global)',
get = function()
return vim.g.autoformat == nil or vim.g.autoformat
end,
set = function(enable)
vim.g.autoformat = (enable == nil and true) or enable
vim.b.autoformat = nil
end,
}):map('<LEADER>uf')
toggle({
name = 'auto format (buffer)',
get = function()
local buf = vim.api.nvim_get_current_buf()
local gopt = vim.g.autoformat
local bopt = vim.b[buf].autoformat
if bopt ~= nil then
return bopt
end
return gopt == nil or gopt
end,
set = function(enable)
vim.b.autoformat = (enable == nil and true) or enable
end,
}):map('<LEADER>uF')
-- Git -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Git -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>gb', function() set({ 'n' }, '<LEADER>gb', function()