mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-01 03:47:19 +00:00
feat(nvim): reworked lsp, theme, cleanup
Signed-off-by: Ismo Vuorinen <ismo@ivuorinen.net>
This commit is contained in:
66
config/nvim/lua/plugins/conform.lua
Normal file
66
config/nvim/lua/plugins/conform.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
return {
|
||||
{
|
||||
'stevearc/conform.nvim',
|
||||
event = 'BufWritePre',
|
||||
config = function()
|
||||
local conform = require 'conform'
|
||||
|
||||
conform.setup {
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
},
|
||||
format_on_save = function(bufnr)
|
||||
-- Disable autoformat for files in a certain paths
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
if bufname:match '/dist|node_modules|vendor/' then return end
|
||||
|
||||
local disable_lsp = {
|
||||
c = true,
|
||||
cpp = true,
|
||||
}
|
||||
return {
|
||||
lsp_fallback = not disable_lsp[vim.bo[bufnr].filetype],
|
||||
timeout_ms = 500,
|
||||
}
|
||||
end,
|
||||
notify_on_error = true,
|
||||
}
|
||||
|
||||
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
||||
|
||||
-- Autoformat toggle keybinding
|
||||
local autoformat = true
|
||||
vim.g.autoformat_enabled = autoformat
|
||||
|
||||
vim.api.nvim_create_user_command('ToggleFormat', function()
|
||||
autoformat = not autoformat
|
||||
vim.g.autoformat_enabled = autoformat
|
||||
vim.notify('Autoformat on save: ' .. (autoformat and 'enabled' or 'disabled'))
|
||||
end, {})
|
||||
|
||||
vim.keymap.set(
|
||||
'n',
|
||||
'<leader>tf',
|
||||
':ToggleFormat<CR>',
|
||||
{ desc = 'Toggle autoformat on save' }
|
||||
)
|
||||
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
callback = function(args)
|
||||
if autoformat then
|
||||
conform.format {
|
||||
bufnr = args.buf,
|
||||
async = true,
|
||||
lsp_format = 'fallback',
|
||||
}
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Global statusline helper function
|
||||
function _G.autoformat_status()
|
||||
return vim.g.autoformat_enabled and '[ fmt:on]' or '[ fmt:off]'
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user