feat(config): add editor config

This commit is contained in:
Matt Leong 2021-10-25 07:33:41 -07:00
parent ea2b4f0ca1
commit 01af4f41ce
4 changed files with 42 additions and 10 deletions

View file

@ -1,16 +1,21 @@
-- Override Cosmic configuration options
--[[
local config = {}
--[[ config.lsp = {
config.lsp = {
format_on_save = true,
servers = {
eslint = false,
efm = {
format = false -- disable formatting all together
disable_formatters = {'eslint', 'prettier', 'stylua'}
disable_formatters = {}, -- e.g. 'eslint', 'prettier', 'lua'
},
tsserver = {
format = false,
}
}
} ]]
}
return config
]]

View file

@ -0,0 +1,6 @@
-- Override Cosmic editor options
--[[ local opt = vim.opt
opt.tabstop = 4
opt.softtabstop = 4
opt.shiftwidth = 4 ]]

View file

@ -1,28 +1,42 @@
local user_config = require('cosmic.config.config')
local ok, user_config = pcall(require, 'cosmic.config.config')
if not ok then
error(string.format('Error loading user config...\n\n%s', user_config))
error('No user config, using default instead...')
end
if user_config == true then
user_config = {}
end
-- these settings will be merged with any settings definined in config.lua
local default_config = {
lsp = {
format_on_save = false,
servers = {
eslint = false,
eslint = true,
efm = {
format = true,
disable_formatters = {}, -- e.g. 'eslint', 'prettier', 'stylua'
disable_formatters = { 'eslint' }, -- e.g. 'eslint', 'prettier', 'stylua'
},
tsserver = {
format = false,
}
},
},
},
}
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 default_config.lsp.can_client_format(client_name)
return (config.lsp.servers[client_name] and config.lsp.servers[client_name].format and vim.tbl_contains(formatting_servers, client_name))
if not user_servers[client_name] or vim.tbl_contains(formatting_servers, client_name) then
return false
end
return (user_servers[client_name].format == true)
end
return config

View file

@ -3,3 +3,10 @@ require('cosmic.pluginsInit')
require('cosmic.compiled')
require('cosmic.mappings')
require('cosmic.editor')
do
local ok, err = pcall(require, 'cosmic.config.editor')
if not ok then
error(string.format('Error loading custor editor settings...\n\n%s', err))
end
end