aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/server.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/nvim-lsp-installer/server.lua')
-rw-r--r--lua/nvim-lsp-installer/server.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua
index 26679023..38ffc52f 100644
--- a/lua/nvim-lsp-installer/server.lua
+++ b/lua/nvim-lsp-installer/server.lua
@@ -20,6 +20,7 @@ M.get_server_root_path = servers.get_server_install_path
---@field public homepage string|nil @The homepage where users can find more information. This is shown to users in the UI.
---@field public deprecated ServerDeprecation|nil @The existence (not nil) of this field indicates this server is depracted.
---@field private _installer ServerInstallerFunction
+---@field private _on_ready_handlers fun(server: Server)[]
---@field private _default_options table @The server's default options. This is used in @see Server#setup.
---@field private _pre_setup fun()|nil @Function to be called in @see Server#setup, before trying to setup.
---@field private _post_setup fun()|nil @Function to be called in @see Server#setup, after successful setup.
@@ -34,6 +35,7 @@ function M.Server:new(opts)
root_dir = opts.root_dir,
homepage = opts.homepage,
deprecated = opts.deprecated,
+ _on_ready_handlers = {},
_installer = type(opts.installer) == "function" and opts.installer or installers.pipe(opts.installer),
_default_options = opts.default_options,
_pre_setup = opts.pre_setup,
@@ -66,6 +68,15 @@ function M.Server:setup(opts)
end
end
+---Registers a handler (callback) to be executed when the server is ready to be setup.
+---@param handler fun(server: Server)
+function M.Server:on_ready(handler)
+ table.insert(self._on_ready_handlers, handler)
+ if self:is_installed() then
+ handler(self)
+ end
+end
+
---@return table @A deep copy of this server's default options. Note that these default options are nvim-lsp-installer specific, and does not include any default options provided by lspconfig.
function M.Server:get_default_options()
return vim.deepcopy(self._default_options)
@@ -134,6 +145,9 @@ function M.Server:install_attached(context, callback)
if rename_ok then
vim.schedule(function()
dispatcher.dispatch_server_ready(self)
+ for _, on_ready_handler in ipairs(self._on_ready_handlers) do
+ on_ready_handler(self)
+ end
end)
else
log.fmt_error(