diff --git a/lua/custom/format_onsave.lua b/lua/custom/format_onsave.lua index cc63b0c..085c4ef 100644 --- a/lua/custom/format_onsave.lua +++ b/lua/custom/format_onsave.lua @@ -1,5 +1,5 @@ local M = { - disable = false, + disable = 0, -- 0 ( format jalan) 1 (fromat off) } return M diff --git a/lua/user/format_onsave.lua b/lua/user/format_onsave.lua index b836522..9d46249 100644 --- a/lua/user/format_onsave.lua +++ b/lua/user/format_onsave.lua @@ -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 diff --git a/lua/user/lsp/null-ls.lua b/lua/user/lsp/null-ls.lua index 2a5a296..e49ed63 100644 --- a/lua/user/lsp/null-ls.lua +++ b/lua/user/lsp/null-ls.lua @@ -26,20 +26,20 @@ null_ls.setup({ -- diagnostics.eslint_d, }, - on_attach = function(client, bufnr) - --if client.resolved_capabilities.document_formatting then - --vim.cmd("autocmd BufWritePre 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 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, })