53 lines
1.8 KiB
Lua
53 lines
1.8 KiB
Lua
-- Format on save and linters
|
|
return {
|
|
'nvimtools/none-ls.nvim',
|
|
dependencies = {
|
|
'nvimtools/none-ls-extras.nvim',
|
|
'gbprod/none-ls-shellcheck.nvim',
|
|
},
|
|
config = function()
|
|
local null_ls = require 'null-ls'
|
|
local formatting = null_ls.builtins.formatting -- to setup formatters
|
|
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
|
|
|
|
|
|
-- Note: Use Mason to manually install tools:
|
|
-- :MasonInstall checkmake prettier stylua eslint_d shfmt ruff goimports
|
|
|
|
local sources = {
|
|
diagnostics.checkmake,
|
|
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } }, -- removed 'templ' for debugging
|
|
formatting.stylua,
|
|
formatting.shfmt.with { args = { '-i', '4' } },
|
|
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
|
|
require 'none-ls.formatting.ruff_format',
|
|
formatting.goimports, -- Add goimports for Go files
|
|
}
|
|
|
|
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
|
|
null_ls.setup {
|
|
debug = false, -- Disable debug mode to reduce log spam
|
|
sources = sources,
|
|
-- you can reuse a shared lspconfig on_attach callback here
|
|
on_attach = function(client, bufnr)
|
|
if client.supports_method 'textDocument/formatting' then
|
|
-- Skip formatting for .templ files during debugging
|
|
local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
|
|
if filetype == 'templ' then
|
|
return
|
|
end
|
|
|
|
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
|
|
vim.api.nvim_create_autocmd('BufWritePre', {
|
|
group = augroup,
|
|
buffer = bufnr,
|
|
callback = function()
|
|
vim.lsp.buf.format { async = false }
|
|
end,
|
|
})
|
|
end
|
|
end,
|
|
}
|
|
end,
|
|
}
|