diff options
| author | William Boman <william@redwill.se> | 2022-04-27 21:20:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-27 21:20:45 +0200 |
| commit | 090c8a87b31de5c5a21eebc55adb22ddab625015 (patch) | |
| tree | 3c92027c937bcca88547d2654d91f24574653634 /lua/nvim-lsp-installer/middleware.lua | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar.gz mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar.bz2 mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar.lz mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar.xz mason-090c8a87b31de5c5a21eebc55adb22ddab625015.tar.zst mason-090c8a87b31de5c5a21eebc55adb22ddab625015.zip | |
feat: integrate with lspconfig's on_setup hook (#631)
* feat: integrate with lspconfig's on_setup hook
* fix!: don't use aliased installation directories if new .setup() fn is used
This makes it so servers are always installed in a directory name that
corresponds with the server name. The reason aliased installation directories
is supported is lost on me, but it's legacy and complicates things
unnecessarily.
This is a breaking change for users who previously were using the `.on_server_ready()`
hook, and now transitioned to setting up servers directly via lspconfig.
These users will need to reinstall the server.
* fix: block usage of the deprecated server:setup() method if new setup method is used
* fix: allow passing no arg to setup()
* docs: ok final.v3 readme
Diffstat (limited to 'lua/nvim-lsp-installer/middleware.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/middleware.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer/middleware.lua b/lua/nvim-lsp-installer/middleware.lua new file mode 100644 index 00000000..3e01b976 --- /dev/null +++ b/lua/nvim-lsp-installer/middleware.lua @@ -0,0 +1,32 @@ +local util = require "lspconfig.util" +local servers = require "nvim-lsp-installer.servers" + +local M = {} + +---@param t1 table +---@param t2 table +local function merge_in_place(t1, t2) + for k, v in pairs(t2) do + if type(v) == "table" then + if type(t1[k]) == "table" and not vim.tbl_islist(t1[k]) then + merge_in_place(t1[k], v) + else + t1[k] = v + end + else + t1[k] = v + end + end + return t1 +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) + if ok then + merge_in_place(config, server._default_options) + end + end) +end + +return M |
