mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-25 02:08:48 +02:00
custom format onsave
This commit is contained in:
parent
8bc9388d5b
commit
e52b14c920
3 changed files with 34 additions and 32 deletions
|
@ -1,5 +1,5 @@
|
||||||
local M = {
|
local M = {
|
||||||
disable = false,
|
disable = 0, -- 0 ( format jalan) 1 (fromat off)
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
local data_exists, frmt = pcall(require, "custom.format_onsave")
|
local data_exists, frmt = pcall(require, "custom.format_onsave")
|
||||||
if data_exists and frmt.disable == false then
|
if data_exists then
|
||||||
|
if frmt.disable == 0 then
|
||||||
function format_filter(client)
|
function format_filter(client)
|
||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
local n = require("null-ls")
|
local n = require("null-ls")
|
||||||
|
@ -22,4 +23,5 @@ if data_exists and frmt.disable == false then
|
||||||
autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter}
|
autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter}
|
||||||
augroup end
|
augroup end
|
||||||
]])
|
]])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,20 +26,20 @@ null_ls.setup({
|
||||||
-- diagnostics.eslint_d,
|
-- diagnostics.eslint_d,
|
||||||
},
|
},
|
||||||
|
|
||||||
on_attach = function(client, bufnr)
|
-- on_attach = function(client, bufnr)
|
||||||
--if client.resolved_capabilities.document_formatting then
|
-- --if client.resolved_capabilities.document_formatting then
|
||||||
--vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.format{async=true}")
|
-- --vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.format{async=true}")
|
||||||
--end
|
-- --end
|
||||||
if client.supports_method("textDocument/formatting") then
|
-- if client.supports_method("textDocument/formatting") then
|
||||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
-- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
-- vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
group = augroup,
|
-- group = augroup,
|
||||||
buffer = bufnr,
|
-- buffer = bufnr,
|
||||||
callback = function()
|
-- callback = function()
|
||||||
vim.lsp.buf.format({ bufnr = bufnr })
|
-- vim.lsp.buf.format({ bufnr = bufnr })
|
||||||
-- vim.lsp.buf.formatting_sync()
|
-- -- vim.lsp.buf.formatting_sync()
|
||||||
end,
|
-- end,
|
||||||
})
|
-- })
|
||||||
end
|
-- end
|
||||||
end,
|
-- end,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue