Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use existing servers & define default servers #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,12 @@ require('lsp-setup').setup({
end,
-- Global capabilities
capabilities = vim.lsp.protocol.make_client_capabilities(),
-- Configuration of LSP servers
-- Install LSP servers automatically (requires mason and mason-lspconfig)
ensure_installed = {
"lua_ls"
},
-- Configuration of LSP servers
servers = {
-- Install LSP servers automatically (requires mason and mason-lspconfig)
-- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- pylsp = {},
-- rust_analyzer = {
Expand Down
15 changes: 10 additions & 5 deletions lua/lsp-setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ M.defaults = {
end,
--- @type table<string, table|function>
servers = {},
--- @type string[]
ensure_installed = {},
inlay_hints = inlay_hints.opts,
}

Expand All @@ -86,7 +88,7 @@ function M.setup(opts)
return
end

opts = vim.tbl_deep_extend('keep', opts, M.defaults)
opts = vim.tbl_deep_extend('force', M.defaults, opts)

vim.api.nvim_create_augroup('LspSetup', {})
vim.api.nvim_create_autocmd('LspAttach', {
Expand All @@ -98,7 +100,7 @@ function M.setup(opts)
mappings = vim.tbl_deep_extend('keep', mappings or {}, default_mappings)
end
utils.mappings(bufnr, mappings)
end
end,
})

inlay_hints.setup(opts.inlay_hints)
Expand All @@ -111,17 +113,20 @@ function M.setup(opts)
mason.setup()
end
mason_lspconfig.setup({
ensure_installed = utils.get_keys(opts.servers),
ensure_installed = vim.tbl_values(opts.ensure_installed),
})
mason_lspconfig.setup_handlers({
function(server_name)
local config = servers[server_name] or nil
local config = M.defaults.ensure_installed[server_name] or nil
if config == nil then
return
end
require('lspconfig')[server_name].setup(config)
end
end,
})
for server_name, config in pairs(servers) do
require('lspconfig')[server_name].setup(config)
end
return
else
for server_name, config in pairs(servers) do
Expand Down