-
Using Nvchad. Here is my ...
{
"jay-babu/mason-null-ls.nvim",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
"jose-elias-alvarez/null-ls.nvim",
"williamboman/mason.nvim",
},
opts = {
ensure_installed = nil,
automatic_installed = true,
},
config = function(_, opts)
require("mason-null-ls").setup(opts)
require "custom.configs.null-ls"
end,
},
...
and here is the local null_ls = require "null-ls"
local b = null_ls.builtins
local sources = {
b.formatting.stylua.with {
extra_args = { "--config-path", vim.fn.expand "~/.config/nvim/.stylua.toml" },
},
b.diagnostics.write_good.with {
diagnostics_postprocess = function(diagnostic)
diagnostic.severity = diagnostic.message:find "really" and vim.diagnostic.severity["ERROR"]
or vim.diagnostic.severity["WARN"]
end,
},
-- bash
b.formatting.shfmt,
b.code_actions.shellcheck.with {
diagnostic_config = {
-- see :help vim.diagnostic.config()
underline = true,
virtual_text = false,
signs = true,
update_in_insert = false,
severity_sort = true,
},
-- will show code and source name
diagnostics_format = "[#{c}] #{m} (#{s})",
},
-- webdev
b.formatting.prettier.with {
extra_filetypes = { "astro", "toml" },
-- condition = function(utils)
-- return utils.root_has_file "package.json"
-- or utils.root_has_file ".prettierrc"
-- or utils.root_has_file ".prettierrc.json"
-- or utils.root_has_file ".prettierrc.js"
-- end,
}, -- so prettier works only on these filetypes
b.diagnostics.eslint.with {
condition = function(utils)
return utils.root_has_file "package.json"
or utils.root_has_file ".eslintrc.json"
or utils.root_has_file ".eslintrc.js"
end,
filter = function(diagnostic)
return diagnostic.code ~= "prettier/prettier"
end,
},
-- python
b.diagnostics.mypy.with {
extra_args = function()
local virtual = os.getenv "VIRTUAL_ENV" or os.getenv "CONDA_DEFAULT_ENV" or "/usr"
return { "--python-executable", virtual .. "/bin/python" }
end,
prefer_local = true,
},
b.formatting.black,
b.formatting.isort,
}
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup {
debug = true,
sources = sources,
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 { async = false }
end,
})
end
end,
}
I cannot get |
Beta Was this translation helpful? Give feedback.
Answered by
jay-babu
Sep 11, 2023
Replies: 1 comment 1 reply
-
Makes sense it wouldn't work. Should be |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
jay-babu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makes sense it wouldn't work. Should be
automatic_installation