plugins, keymaps + fix formatting
This commit is contained in:
parent
ec6733a0ea
commit
b402f79541
10 changed files with 220 additions and 43 deletions
32
lua/utils/formatting.lua
Normal file
32
lua/utils/formatting.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
local M = {}
|
||||
|
||||
---filter passed to vim.lsp.buf.format
|
||||
---always selects null-ls if it's available and caches the value per buffer
|
||||
---@param client table client attached to a buffer
|
||||
---@return boolean if client matches
|
||||
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
|
||||
|
||||
---Simple wrapper for vim.lsp.buf.format() to provide defaults
|
||||
---@param opts table|nil
|
||||
function M.format(opts)
|
||||
opts = opts or {}
|
||||
opts.filter = opts.filter or M.format_filter
|
||||
|
||||
return vim.lsp.buf.format(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue