chore(configs): clean up
This commit is contained in:
parent
fb512d0036
commit
9e72bafe0f
3 changed files with 35 additions and 14 deletions
|
@ -1,19 +1,33 @@
|
|||
-- Override Cosmic configuration options
|
||||
|
||||
--[[ local config = {}
|
||||
--[[
|
||||
local config = {}
|
||||
|
||||
config.lsp = {
|
||||
format_on_save = true,
|
||||
|
||||
-- true/false or table of filetypes {'.ts', '.js',}
|
||||
format_on_save = false,
|
||||
|
||||
servers = {
|
||||
|
||||
-- enable/disable server
|
||||
eslint = false,
|
||||
|
||||
-- enable non-default servers (todo: support for custom server configs)
|
||||
rust_analyzer = true,
|
||||
|
||||
efm = {
|
||||
format = false, -- disable formatting all together
|
||||
disable_formatters = {}, -- e.g. 'eslint', 'prettier', 'lua'
|
||||
-- specifc to efm, e.g. 'eslint', 'prettier', 'lua'
|
||||
disable_formatters = {},
|
||||
},
|
||||
|
||||
tsserver = {
|
||||
-- disable formatting all together
|
||||
format = false,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
]]
|
||||
]]
|
||||
|
|
|
@ -12,15 +12,16 @@ end
|
|||
-- these settings will be merged with any settings definined in config.lua
|
||||
local default_config = {
|
||||
lsp = {
|
||||
format_on_save = false,
|
||||
format_on_save = false, -- true/false or table of filetypes {'.ts', '.js',}
|
||||
servers = {
|
||||
eslint = true,
|
||||
eslint = true, -- enable/disable server
|
||||
-- rust_analyzer = true, -- enable non-default servers (todo: support for custom server configs)
|
||||
efm = {
|
||||
format = true,
|
||||
format = true, -- true or false
|
||||
disable_formatters = { 'eslint' }, -- e.g. 'eslint', 'prettier', 'stylua'
|
||||
},
|
||||
tsserver = {
|
||||
format = false,
|
||||
format = false, -- disable formatting all together
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -31,7 +32,7 @@ local config = vim.tbl_deep_extend('force', default_config, user_config)
|
|||
local formatting_servers = { 'efm', 'eslint', 'tsserver', 'sumneko_lua', 'rust_analyzer', 'gopls', 'pyright' }
|
||||
local user_servers = vim.tbl_keys(config.lsp.servers)
|
||||
|
||||
function default_config.lsp.can_client_format(client_name)
|
||||
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
|
||||
end
|
||||
|
|
|
@ -14,12 +14,18 @@ function M.on_attach(client, bufnr)
|
|||
if config.lsp.can_client_format(client.name) then
|
||||
client.resolved_capabilities.document_formatting = true
|
||||
client.resolved_capabilities.document_range_formatting = true
|
||||
-- auto format on save
|
||||
-- check user config to see if we can format on save
|
||||
if config.lsp.format_on_save and not auto_format_lock then
|
||||
auto_format_lock = true -- just run autocommand once
|
||||
vim.cmd([[
|
||||
autocmd BufWritePre * lua vim.lsp.buf.formatting()
|
||||
]])
|
||||
local format_filetypes = ''
|
||||
if (vim.tbl_islist(config.lsp.format_on_save)) then
|
||||
for _, ft in pairs(config.lsp.format_on_save) do
|
||||
format_filetypes = format_filetypes .. '*' .. ft
|
||||
end
|
||||
else
|
||||
format_filetypes = '*'
|
||||
end
|
||||
vim.cmd(string.format('autocomd BufWritePre %s lua vim.lsp.buf.formatting()', format_filetypes))
|
||||
end
|
||||
else
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
|
|
Loading…
Add table
Reference in a new issue