aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/middleware.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-05-30 01:57:00 +0200
committerGitHub <noreply@github.com>2022-05-30 01:57:00 +0200
commit9cc15aa044e26e4947a46b691a74664621331228 (patch)
treea8a93742a15e4825b6957b05dfa940d2a6d1da4e /lua/nvim-lsp-installer/middleware.lua
parentrefactor(pip3): use with_paths to set venv path (#736) (diff)
downloadmason-9cc15aa044e26e4947a46b691a74664621331228.tar
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.gz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.bz2
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.lz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.xz
mason-9cc15aa044e26e4947a46b691a74664621331228.tar.zst
mason-9cc15aa044e26e4947a46b691a74664621331228.zip
refactor: specify commands independently, not via lspconfig (#737)
This is not a desirable solution, but it's better than as-is. There's a couple of reasons for this: 1) lspconfig only enables these commands upon successful attachment of servers, which doesn't really fit their use case. 2) We gain direct access to new Lua APIs for defining user commands, allowing us to leverage Lua callbacks and functions instead of intermediary global variables.
Diffstat (limited to 'lua/nvim-lsp-installer/middleware.lua')
-rw-r--r--lua/nvim-lsp-installer/middleware.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/middleware.lua b/lua/nvim-lsp-installer/middleware.lua
index 44af9f0f..04ffe2a9 100644
--- a/lua/nvim-lsp-installer/middleware.lua
+++ b/lua/nvim-lsp-installer/middleware.lua
@@ -1,4 +1,5 @@
local util = require "lspconfig.util"
+local _ = require "nvim-lsp-installer.core.functional"
local notify = require "nvim-lsp-installer.notify"
local servers = require "nvim-lsp-installer.servers"
local settings = require "nvim-lsp-installer.settings"
@@ -38,6 +39,17 @@ local function should_auto_install(server_name)
return false
end
+local registered_server_hooks = {}
+
+---@param server_name string
+---@param fn fun(config: table)
+function M.register_server_hook(server_name, fn)
+ if not registered_server_hooks[server_name] then
+ registered_server_hooks[server_name] = {}
+ end
+ table.insert(registered_server_hooks[server_name], fn)
+end
+
function M.register_lspconfig_hook()
util.on_setup = util.add_hook_before(util.on_setup, function(config)
local ok, server = servers.get_server(config.name)
@@ -49,6 +61,15 @@ function M.register_lspconfig_hook()
server:install()
end
end
+
+ if registered_server_hooks[config.name] then
+ _.each(function(fn)
+ local ok, err = pcall(fn, config)
+ if not ok then
+ notify(err, vim.log.levels.ERROR)
+ end
+ end, registered_server_hooks[config.name])
+ end
end)
end