2023-01-15 00:17:41 +07:00
|
|
|
local null_ls_status_ok, null_ls = pcall(require, "null-ls")
|
|
|
|
if not null_ls_status_ok then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
|
|
|
|
local formatting = null_ls.builtins.formatting
|
|
|
|
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
|
|
|
|
local diagnostics = null_ls.builtins.diagnostics
|
|
|
|
|
|
|
|
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
|
|
|
|
2023-02-19 18:43:34 +07:00
|
|
|
local sources = {}
|
2023-03-06 14:11:29 +07:00
|
|
|
local ensure_installed = {}
|
2023-02-19 18:43:34 +07:00
|
|
|
|
2023-03-11 09:32:27 +07:00
|
|
|
local data_ok, data_sources = pcall(require, "custom.null-ls")
|
|
|
|
if data_ok then
|
|
|
|
for _, cfg in pairs(data_sources.sources) do
|
|
|
|
table.insert(sources, cfg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-05 17:34:12 +07:00
|
|
|
local data_exists, data = pcall(require, "core.config")
|
2023-02-19 18:43:34 +07:00
|
|
|
if data_exists then
|
2023-03-06 14:11:29 +07:00
|
|
|
-- load data null-ls
|
|
|
|
for _, nullls in pairs(data.null_ls_ensure_installed) do
|
|
|
|
table.insert(ensure_installed, nullls)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local mason_ok, mason_null_ls = pcall(require, "mason-null-ls")
|
|
|
|
if mason_ok then
|
|
|
|
mason_null_ls.setup({
|
|
|
|
ensure_installed = ensure_installed,
|
|
|
|
})
|
2023-02-19 18:43:34 +07:00
|
|
|
end
|
|
|
|
|
2023-03-01 22:16:37 +07:00
|
|
|
local run = 0
|
2023-03-05 17:34:12 +07:00
|
|
|
local ok, frmt = pcall(require, "core.config")
|
|
|
|
if not ok then
|
2023-03-01 22:16:37 +07:00
|
|
|
run = 1
|
|
|
|
end
|
2023-03-05 17:34:12 +07:00
|
|
|
if frmt.format_on_save == 1 then
|
2023-03-01 22:16:37 +07:00
|
|
|
run = 1
|
|
|
|
end
|
2023-01-15 00:17:41 +07:00
|
|
|
|
2023-03-01 22:16:37 +07:00
|
|
|
if run == 1 then
|
|
|
|
null_ls.setup({
|
|
|
|
debug = false,
|
2023-03-06 14:11:29 +07:00
|
|
|
ensure_installed = ensure_installed,
|
2023-03-01 22:16:37 +07:00
|
|
|
sources = sources,
|
|
|
|
--sources = {
|
|
|
|
--formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }),
|
|
|
|
--formatting.prettier,
|
|
|
|
-- formatting.prettierd,
|
|
|
|
-- formatting.black.with({ extra_args = { "--fast" } }),
|
|
|
|
-- formatting.stylua,
|
|
|
|
-- formatting.eslint_d,
|
|
|
|
-- formatting.google_java_format,
|
|
|
|
-- formatting.phpcbf,
|
|
|
|
-- formatting.clang_format,
|
|
|
|
-- diagnostics.flake8
|
|
|
|
-- diagnostics.eslint_d,
|
|
|
|
--},
|
|
|
|
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
--if client.resolved_capabilities.document_formatting then
|
|
|
|
--vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.format{async=true}")
|
|
|
|
--end
|
|
|
|
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 })
|
|
|
|
-- vim.lsp.buf.formatting_sync()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
null_ls.setup({
|
|
|
|
debug = false,
|
2023-03-06 14:11:29 +07:00
|
|
|
ensure_installed = ensure_installed,
|
2023-03-01 22:16:37 +07:00
|
|
|
sources = sources,
|
|
|
|
})
|
|
|
|
end
|