1
0
Fork 0

detect correct formatter

This commit is contained in:
Luca Bilke 2022-12-20 18:14:15 +01:00
commit d86c6ac9f4
3 changed files with 38 additions and 16 deletions
.config/nvim/lua

View file

@ -22,6 +22,18 @@ function M.lazy_load(tb)
})
end
function M.on_file_open(plugin_name)
M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugin = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end
function M.gitsigns()
vim.api.nvim_create_autocmd({ "BufRead" }, {
group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }),
@ -37,18 +49,6 @@ function M.gitsigns()
})
end
function M.on_file_open(plugin_name)
M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugin = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end
function M.bootstrap()
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
@ -100,6 +100,28 @@ function M.map(section)
end
end
function M.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
function M.format(opts)
opts = opts or {}
opts.filter = opts.filter or M.format_filter
return vim.lsp.buf.format(opts)
end
-- Modified version of a function stolen from LunarVim
function M.buf_kill(kill_command, bufnr, force)
kill_command = kill_command or "bd"