feat(config): add editor config
This commit is contained in:
parent
ea2b4f0ca1
commit
01af4f41ce
4 changed files with 42 additions and 10 deletions
|
@ -1,16 +1,21 @@
|
||||||
|
-- Override Cosmic configuration options
|
||||||
|
|
||||||
|
--[[
|
||||||
local config = {}
|
local config = {}
|
||||||
--[[ config.lsp = {
|
config.lsp = {
|
||||||
format_on_save = true,
|
format_on_save = true,
|
||||||
servers = {
|
servers = {
|
||||||
eslint = false,
|
eslint = false,
|
||||||
efm = {
|
efm = {
|
||||||
format = false -- disable formatting all together
|
format = false -- disable formatting all together
|
||||||
disable_formatters = {'eslint', 'prettier', 'stylua'}
|
disable_formatters = {}, -- e.g. 'eslint', 'prettier', 'lua'
|
||||||
},
|
},
|
||||||
tsserver = {
|
tsserver = {
|
||||||
format = false,
|
format = false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ]]
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
6
lua/cosmic/config/editor.lua
Normal file
6
lua/cosmic/config/editor.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
-- Override Cosmic editor options
|
||||||
|
|
||||||
|
--[[ local opt = vim.opt
|
||||||
|
opt.tabstop = 4
|
||||||
|
opt.softtabstop = 4
|
||||||
|
opt.shiftwidth = 4 ]]
|
|
@ -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
|
-- these settings will be merged with any settings definined in config.lua
|
||||||
local default_config = {
|
local default_config = {
|
||||||
lsp = {
|
lsp = {
|
||||||
format_on_save = false,
|
format_on_save = false,
|
||||||
servers = {
|
servers = {
|
||||||
eslint = false,
|
eslint = true,
|
||||||
efm = {
|
efm = {
|
||||||
format = true,
|
format = true,
|
||||||
disable_formatters = {}, -- e.g. 'eslint', 'prettier', 'stylua'
|
disable_formatters = { 'eslint' }, -- e.g. 'eslint', 'prettier', 'stylua'
|
||||||
},
|
},
|
||||||
tsserver = {
|
tsserver = {
|
||||||
format = false,
|
format = false,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local config = vim.tbl_deep_extend('force', default_config, user_config)
|
local config = vim.tbl_deep_extend('force', default_config, user_config)
|
||||||
|
|
||||||
-- default servers that can be formatted
|
-- default servers that can be formatted
|
||||||
local formatting_servers = { 'efm', 'eslint', 'tsserver', 'sumneko_lua', 'rust_analyzer', 'gopls', 'pyright' }
|
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 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
|
end
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -3,3 +3,10 @@ require('cosmic.pluginsInit')
|
||||||
require('cosmic.compiled')
|
require('cosmic.compiled')
|
||||||
require('cosmic.mappings')
|
require('cosmic.mappings')
|
||||||
require('cosmic.editor')
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue