This commit is contained in:
asep komarudin 2023-02-19 16:41:10 +07:00
parent 90d02a0f5b
commit 2e6e87a71d
2 changed files with 27 additions and 16 deletions

View file

@ -2,7 +2,7 @@
require("user.options") require("user.options")
require("user.keymaps") require("user.keymaps")
require("user.autocommands") require("user.autocommands")
require("user.format") require("user.format_onsave")
-- require("user.colorscheme") -- require("user.colorscheme")
-- require("user.snip") -- require("user.snip")
-- require("user.bufferline") -- require("user.bufferline")

View file

@ -1,22 +1,33 @@
function format_filter(client) local run = 0
local filetype = vim.bo.filetype local data_exists, frmt = pcall(require, "custom.format_onsave")
local n = require("null-ls") if not data_exists then
local s = require("null-ls.sources") run = 1
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
end
end end
vim.cmd([[ if frmt.disable == 0 then
run = 1
end
if run == 1 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
end
end
vim.cmd([[
augroup _lsp augroup _lsp
autocmd! autocmd!
" autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms =200, filter=format_filter} " 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} autocmd BufWritePre * lua vim.lsp.buf.format{timeout_ms=1000 ,filter=format_filter}
augroup end augroup end
]]) ]])
end