This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Hey all, local present, null_ls = pcall(require, "null-ls")
if not present then
return
end
local b = null_ls.builtins
-- copied from the null_ls docs
-- required for format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local sources = {
-- webdev stuff
b.formatting.deno_fmt,
b.formatting.prettier,
b.diagnostics.eslint,
-- Lua
b.formatting.stylua,
-- Rust
b.formatting.rustfmt,
}
-- format on save
null_ls.setup {
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
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 { bufnr = bufnr }
end,
})
end
end,
debug = true,
sources = sources,
} |
Beta Was this translation helpful? Give feedback.
Answered by
fitrh
Jul 14, 2023
Replies: 1 comment 1 reply
-
You can use local sources = {
b.formatting.deno_fmt.with({
condition = function(u)
return u.root_has_file({ 'deno.json' })
end,
}),
} You can read BUILTIN_CONFIG.md#conditional-sources for the details |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Callumk7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
condition
You can read BUILTIN_CONFIG.md#conditional-sources for the details