.dotfiles/configs/nvim/lua/formatter-conf.lua

58 lines
1.5 KiB
Lua
Raw Normal View History

2021-12-18 14:41:37 +01:00
local cmd = vim.cmd
2022-03-14 19:21:46 +01:00
local g = vim.g
2022-01-26 20:42:58 +01:00
2022-03-14 19:21:46 +01:00
local function tablelength(T)
2022-01-26 20:42:58 +01:00
local count = 0
for _ in pairs(T) do
count = count + 1
end
return count
end
local function select_client(method)
local all_clients = vim.tbl_values(vim.lsp.buf_get_clients())
local supported_client
local found_client = false
for _, client in ipairs(all_clients) do
local supports = client.supports_method(method)
if supports then
found_client = true
supported_client = client
end
end
if not found_client then
return nil
end
return supported_client
end
2022-03-14 19:21:46 +01:00
g.neoformat_enabled_glsl = {}
2022-01-26 20:42:58 +01:00
function FormattingSync()
vim.cmd("Neoformat")
-- local client = select_client("textDocument/formatting")
-- if client == nil then
-- vim.notify("No LSP Client with formatting connected")
-- end
-- vim.notify("Formatting with LSP")
-- local params = util.make_formatting_params({})
-- local result, err = client.request_sync("textDocument/formatting", params, 500, vim.api.nvim_get_current_buf())
-- if result and result.result then
-- util.apply_text_edits(result.result)
-- elseif err then
-- vim.notify("vim.lsp.buf.formatting_sync: " .. err, vim.log.levels.WARN)
-- end
end
vim.cmd [[command! Format lua FormattingSync()]]
2021-11-22 18:45:07 +01:00
cmd [[
augroup auto_format
au!
2022-01-26 20:42:58 +01:00
au BufWritePre * lua FormattingSync()
2021-11-22 18:45:07 +01:00
augroup END
]]