-
Notifications
You must be signed in to change notification settings - Fork 0
Home
krap edited this page Mar 31, 2023
·
1 revision
Welcome to the knit wiki!
You can install dprint
via pnpm i
in project root.
return function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.dprint,
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
local format_augroup = vim.api.nvim_create_augroup("format_augroup", { clear = true })
vim.api.nvim_create_autocmd("BufWritePre", {
group = format_augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
filter = function(_client)
return _client.name == "null-ls"
end,
})
end,
})
end
end,
})
end
local supported_types = { 'js', 'jsx', 'ts', 'tsx', 'json', 'yaml' }
local filetype = vim.bo.filetype
if not vim.tbl_contains(supported_types, filetype) then
return
end
local has_dprint = vim.fn.executable('dprint')
if has_dprint then
vim.cmd("augroup dprint_autogroup")
vim.cmd("autocmd!")
vim.cmd("autocmd BufWritePre * silent! !dprint fmt %")
vim.cmd("augroup END")
end