feat(config): add ability to add custom lsp server options

This commit is contained in:
Matt Leong 2021-10-29 13:02:18 -07:00
parent f4e75710ea
commit 8dde6a3f09
2 changed files with 18 additions and 4 deletions

View file

@ -35,12 +35,20 @@ config.lsp = {
-- enable/disable server + formatting
eslint = false,
-- enable non-default servers (todo: support for custom server configs)
-- enable non-default servers, use default lsp config
-- check here for configs that will be used: https://github.com/williamboman/nvim-lsp-installer/tree/main/lua/nvim-lsp-installer/servers
rust_analyzer = true,
tsserver = {
-- disable formatting
format = false,
-- OR add/override server options
opts = {
on_attach = function(client, bufnr) end,
flags = {
debounce_text_changes = 150,
}
}
},
efm = {

View file

@ -51,17 +51,16 @@ for _, requested_server in pairs(requested_servers) do
end
end
-- print(vim.inspect(requested_servers))
-- print(vim.inspect(disabled_servers))
lsp_installer.on_server_ready(function(server)
local opts = default_config
-- disable server if config disabled server list says so
opts.autostart = true
if vim.tbl_contains(disabled_servers, server.name) then
opts.autostart = false
end
-- set up default cosmic options
if server.name == 'tsserver' then
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.tsserver'))
elseif server.name == 'efm' then
@ -72,6 +71,13 @@ lsp_installer.on_server_ready(function(server)
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.eslint'))
end
-- override options if user definds them
if config.lsp.servers[server.name] then
if config.lsp.servers[server.name].opts ~= nil then
opts = config.lsp.servers[server.name].opts
end
end
-- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart)
server:setup(opts)
vim.cmd([[ do User LspAttachBuffers ]])