fix(config): actually format on save

This commit is contained in:
Matt Leong 2021-10-25 10:50:07 -07:00
parent be8518df04
commit e3c96ce353
2 changed files with 8 additions and 6 deletions

View file

@ -33,15 +33,17 @@ local default_config = {
local config = vim.tbl_deep_extend('force', default_config, user_config)
-- default servers that can be formatted
local formatting_servers = { 'efm', 'eslint', 'tsserver', 'sumneko_lua', 'rust_analyzer', 'gopls', 'pyright' }
local user_servers = vim.tbl_keys(config.lsp.servers)
function config.lsp.can_client_format(client_name)
if not user_servers[client_name] or vim.tbl_contains(formatting_servers, client_name) then
return false
if (config.lsp.servers[client_name] == true) then
return true
end
return (user_servers[client_name].format == true)
if vim.tbl_contains(user_servers, client_name) and config.lsp.servers[client_name] then
return (config.lsp.servers[client_name].format == true)
end
return true
end
return config

View file

@ -25,7 +25,7 @@ function M.on_attach(client, bufnr)
else
format_filetypes = '*'
end
vim.cmd(string.format('autocomd BufWritePre %s lua vim.lsp.buf.formatting()', format_filetypes))
vim.cmd(string.format('autocmd BufWritePre %s lua vim.lsp.buf.formatting()', format_filetypes))
end
else
client.resolved_capabilities.document_formatting = false