summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/manager.lua
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2021-11-08 23:13:05 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2021-11-08 23:13:05 +0100
commitc9e2adbbc8fd7a5398c8c66d21f0e02dc7b60203 (patch)
tree274263ba15e0197180af8bb681e22c4780d5de05 /.config/nvim/lua/lsp/manager.lua
parente4ea22e223bbd6b4091610c6fa093862cbd32f75 (diff)
Add new lunarvin updates
Diffstat (limited to '.config/nvim/lua/lsp/manager.lua')
-rw-r--r--.config/nvim/lua/lsp/manager.lua70
1 files changed, 38 insertions, 32 deletions
diff --git a/.config/nvim/lua/lsp/manager.lua b/.config/nvim/lua/lsp/manager.lua
index a7d6892..24fb6e3 100644
--- a/.config/nvim/lua/lsp/manager.lua
+++ b/.config/nvim/lua/lsp/manager.lua
@@ -15,15 +15,6 @@ function M.init_defaults(languages)
end
end
-local function is_overridden(server)
- local overrides = options.lsp.override
- if type(overrides) == "table" then
- if vim.tbl_contains(overrides, server) then
- return true
- end
- end
-end
-
---Resolve the configuration for a server based on both common and user configuration
---@param name string
---@param user_config table [optional]
@@ -35,11 +26,8 @@ local function resolve_config(name, user_config)
capabilities = require("lsp").common_capabilities(),
}
- local status_ok, custom_config = pcall(
- require,
- "lsp/providers/" .. name
- )
- if status_ok then
+ local has_custom_provider, custom_config = pcall(require, "lsp/providers/" .. name)
+ if has_custom_provider then
Log:debug("Using custom configuration for requested server: " .. name)
config = vim.tbl_deep_extend("force", config, custom_config)
end
@@ -51,38 +39,56 @@ local function resolve_config(name, user_config)
return config
end
+-- manually start the server and don't wait for the usual filetype trigger from lspconfig
+local function buf_try_add(server_name, bufnr)
+ bufnr = bufnr or vim.api.nvim_get_current_buf()
+ require("lspconfig")[server_name].manager.try_add_wrapper(bufnr)
+end
+
---Setup a language server by providing a name
---@param server_name string name of the language server
---@param user_config table [optional] when available it will take predence over any default configurations
function M.setup(server_name, user_config)
vim.validate { name = { server_name, "string" } }
- if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then
+ if lsp_utils.is_client_active(server_name) then
return
end
+ local servers = require "nvim-lsp-installer.servers"
local config = resolve_config(server_name, user_config)
- local server_available, requested_server = require("nvim-lsp-installer.servers").get_server(server_name)
+ local server_available, requested_server = servers.get_server(server_name)
- local function ensure_installed(server)
- if server:is_installed() then
- return true
- end
- if not lvim.lsp.automatic_servers_installation then
- Log:debug(server.name .. " is not managed by the automatic installer")
- return false
+ if server_available then
+ local install_notification = false
+
+ if not requested_server:is_installed() then
+ if options.lsp.automatic_servers_installation then
+ Log:debug "Automatic server installation detected"
+ requested_server:install()
+ install_notification = true
+ else
+ Log:debug(requested_server.name .. " is not managed by the automatic installer")
+ end
end
- Log:debug(string.format("Installing [%s]", server.name))
- server:install()
- vim.schedule(function()
- vim.cmd [[LspStart]]
- end)
- end
- if server_available and ensure_installed(requested_server) then
- requested_server:setup(config)
+ requested_server:on_ready(function()
+ if install_notification then
+ vim.notify(
+ string.format("Installation complete for [%s] server", requested_server.name),
+ vim.log.levels.INFO
+ )
+ end
+ install_notification = false
+ requested_server:setup(config)
+ end)
else
- require("lspconfig")[server_name].setup(config)
+ -- since it may not be installed, don't attempt to configure the LSP unless there is a custom provider
+ local has_custom_provider, _ = pcall(require, "lsp/providers/" .. server_name)
+ if has_custom_provider then
+ require("lspconfig")[server_name].setup(config)
+ buf_try_add(server_name)
+ end
end
end