custom format onsave

This commit is contained in:
asep komarudin 2023-02-19 15:53:48 +07:00
parent 8bc9388d5b
commit e52b14c920
3 changed files with 34 additions and 32 deletions

View file

@ -1,25 +1,27 @@
local data_exists, frmt = pcall(require, "custom.format_onsave")
if data_exists and frmt.disable == false then
function format_filter(client)
local filetype = vim.bo.filetype
local n = require("null-ls")
local s = require("null-ls.sources")
local method = n.methods.FORMATTING
local available_formatters = s.get_available(filetype, method)
if data_exists then
if frmt.disable == 0 then
function format_filter(client)
local filetype = vim.bo.filetype
local n = require("null-ls")
local s = require("null-ls.sources")
local method = n.methods.FORMATTING
local available_formatters = s.get_available(filetype, method)
if #available_formatters > 0 then
return client.name == "null-ls"
elseif client.supports_method("textDocument/formatting") then
return true
else
return false
if #available_formatters > 0 then
return client.name == "null-ls"
elseif client.supports_method("textDocument/formatting") then
return true
else
return false
end
end
end
vim.cmd([[
vim.cmd([[
augroup _lsp
autocmd!
" autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter}
autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter}
augroup end
]])
end
end