fix null-ls format onsave

This commit is contained in:
asep komarudin 2023-03-01 22:16:37 +07:00
parent 3a8ccb5ffb
commit 0c12f6e382
2 changed files with 61 additions and 33 deletions

View file

@ -19,7 +19,17 @@ if data_exists then
end
end
null_ls.setup({
local run = 0
local data_exists, frmt = pcall(require, "custom.format_onsave")
if not data_exists then
run = 1
end
if frmt.disable == 0 then
run = 1
end
if run == 1 then
null_ls.setup({
debug = false,
sources = sources,
--sources = {
@ -36,20 +46,26 @@ null_ls.setup({
-- 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,
})
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,
sources = sources,
})
end

View file

@ -7,6 +7,18 @@ local material_icon_ok, material_icon = pcall(require, "nvim-material-icon")
if not material_icon_ok then
return
end
material_icon.setup({
override = {
["mjs"] = {
icon = "",
color = "#efd81d",
cterm_color = "220",
name = "Mjs",
},
},
color_icons = true,
default = true,
})
web_devicons.setup({
override = material_icon.get_icons(),