|  | @@ -16,29 +16,27 @@ function M.init_defaults(languages)
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | ----Resolve the configuration for a server based on both common and user configuration
 | 
	
		
			
				|  |  | ----@param name string
 | 
	
		
			
				|  |  | ----@param user_config table [optional]
 | 
	
		
			
				|  |  | +---Resolve the configuration for a server by merging with the default config
 | 
	
		
			
				|  |  | +---@param server_name string
 | 
	
		
			
				|  |  | +---@vararg any config table [optional]
 | 
	
		
			
				|  |  |  ---@return table
 | 
	
		
			
				|  |  | -local function resolve_config(name, user_config)
 | 
	
		
			
				|  |  | -  local config = {
 | 
	
		
			
				|  |  | +local function resolve_config(server_name, ...)
 | 
	
		
			
				|  |  | +  local defaults = {
 | 
	
		
			
				|  |  |      on_attach = require("lvim.lsp").common_on_attach,
 | 
	
		
			
				|  |  |      on_init = require("lvim.lsp").common_on_init,
 | 
	
		
			
				|  |  |      on_exit = require("lvim.lsp").common_on_exit,
 | 
	
		
			
				|  |  |      capabilities = require("lvim.lsp").common_capabilities(),
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  local has_custom_provider, custom_config = pcall(require, "lvim/lsp/providers/" .. name)
 | 
	
		
			
				|  |  | +  local has_custom_provider, custom_config = pcall(require, "lvim/lsp/providers/" .. server_name)
 | 
	
		
			
				|  |  |    if has_custom_provider then
 | 
	
		
			
				|  |  | -    Log:debug("Using custom configuration for requested server: " .. name)
 | 
	
		
			
				|  |  | -    config = vim.tbl_deep_extend("force", config, custom_config)
 | 
	
		
			
				|  |  | +    Log:debug("Using custom configuration for requested server: " .. server_name)
 | 
	
		
			
				|  |  | +    defaults = vim.tbl_deep_extend("force", defaults, custom_config)
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  if user_config then
 | 
	
		
			
				|  |  | -    config = vim.tbl_deep_extend("force", config, user_config)
 | 
	
		
			
				|  |  | -  end
 | 
	
		
			
				|  |  | +  defaults = vim.tbl_deep_extend("force", defaults, ...)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  return config
 | 
	
		
			
				|  |  | +  return defaults
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  -- manually start the server and don't wait for the usual filetype trigger from lspconfig
 | 
	
	
		
			
				|  | @@ -62,47 +60,52 @@ local function client_is_configured(server_name, ft)
 | 
	
		
			
				|  |  |    return false
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +local function launch_server(server_name, config)
 | 
	
		
			
				|  |  | +  pcall(function()
 | 
	
		
			
				|  |  | +    require("lspconfig")[server_name].setup(config)
 | 
	
		
			
				|  |  | +    buf_try_add(server_name)
 | 
	
		
			
				|  |  | +  end)
 | 
	
		
			
				|  |  | +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
 | 
	
		
			
				|  |  | +---@param user_config table? when available it will take predence over any default configurations
 | 
	
		
			
				|  |  |  function M.setup(server_name, user_config)
 | 
	
		
			
				|  |  |    vim.validate { name = { server_name, "string" } }
 | 
	
		
			
				|  |  | +  user_config = user_config or {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    if lvim_lsp_utils.is_client_active(server_name) or client_is_configured(server_name) then
 | 
	
		
			
				|  |  |      return
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  local config = resolve_config(server_name, user_config)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    local servers = require "nvim-lsp-installer.servers"
 | 
	
		
			
				|  |  | -  local server_available, requested_server = servers.get_server(server_name)
 | 
	
		
			
				|  |  | +  local server_available, server = servers.get_server(server_name)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    if not server_available then
 | 
	
		
			
				|  |  | -    pcall(function()
 | 
	
		
			
				|  |  | -      require("lspconfig")[server_name].setup(config)
 | 
	
		
			
				|  |  | -      buf_try_add(server_name)
 | 
	
		
			
				|  |  | -    end)
 | 
	
		
			
				|  |  | +    local config = resolve_config(server_name, user_config)
 | 
	
		
			
				|  |  | +    launch_server(server_name, config)
 | 
	
		
			
				|  |  |      return
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  local install_notification = false
 | 
	
		
			
				|  |  | +  local install_in_progress = false
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  if not requested_server:is_installed() then
 | 
	
		
			
				|  |  | +  if not server:is_installed() then
 | 
	
		
			
				|  |  |      if lvim.lsp.automatic_servers_installation then
 | 
	
		
			
				|  |  |        Log:debug "Automatic server installation detected"
 | 
	
		
			
				|  |  | -      requested_server:install()
 | 
	
		
			
				|  |  | -      install_notification = true
 | 
	
		
			
				|  |  | +      server:install()
 | 
	
		
			
				|  |  | +      install_in_progress = true
 | 
	
		
			
				|  |  |      else
 | 
	
		
			
				|  |  | -      Log:debug(requested_server.name .. " is not managed by the automatic installer")
 | 
	
		
			
				|  |  | +      Log:debug(server.name .. " is not managed by the automatic installer")
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  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)
 | 
	
		
			
				|  |  | +  server:on_ready(function()
 | 
	
		
			
				|  |  | +    if install_in_progress then
 | 
	
		
			
				|  |  | +      vim.notify(string.format("Installation complete for [%s] server", server.name), vim.log.levels.INFO)
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  | -    install_notification = false
 | 
	
		
			
				|  |  | -    requested_server:setup(config)
 | 
	
		
			
				|  |  | +    install_in_progress = false
 | 
	
		
			
				|  |  | +    local config = resolve_config(server_name, server:get_default_options(), user_config)
 | 
	
		
			
				|  |  | +    launch_server(server_name, config)
 | 
	
		
			
				|  |  |    end)
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 |