This commit is contained in:
asep komarudin 2023-02-19 16:10:17 +07:00
parent e52b14c920
commit 90d02a0f5b
5 changed files with 28 additions and 26 deletions

View file

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

View file

@ -1,5 +0,0 @@
local M = {
disable = 0, -- 0 ( format jalan) 1 (fromat off)
}
return M

View file

@ -0,0 +1,5 @@
local M = {
disable = 1, -- 0 ( format jalan) 1 (fromat off)
}
return M

7
lua/user/format.lua Normal file
View file

@ -0,0 +1,7 @@
local data_exists, frmt = pcall(require, "custom.format_onsave")
if not data_exists then
require("user.format_onsave")
end
if frmt.disable == 0 then
require("user.format_onsave")
end

View file

@ -1,27 +1,22 @@
local data_exists, frmt = pcall(require, "custom.format_onsave")
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)
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([[
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
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