This repository has been archived by the owner on Nov 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate with lspconfig's on_setup hook
- Loading branch information
1 parent
36b4467
commit b9a87a6
Showing
7 changed files
with
133 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
local util = require "lspconfig.util" | ||
local servers = require "nvim-lsp-installer.servers" | ||
local middleware = require "nvim-lsp-installer.middleware" | ||
|
||
describe("middleware", function() | ||
it("should register on_setup hook with lspconfig", function() | ||
-- 1. setup dummy server | ||
local default_options = { | ||
cmd = { "dummy-lsp" }, | ||
cmd_env = { PATH = "/keep/my/path/out/your/f/mouth" }, | ||
} | ||
local server = ServerGenerator { | ||
name = "dummy", | ||
default_options = default_options, | ||
} | ||
servers.register(server) | ||
|
||
-- 2. register hook | ||
middleware.register_lspconfig_hook() | ||
|
||
-- 3. call lspconfig hook | ||
local config = { | ||
name = "dummy", | ||
cmd = { "should", "be", "overwritten" }, | ||
custom = "setting", | ||
cmd_env = { SOME_DEFAULT_ENV = "important" }, | ||
} | ||
util.on_setup(config) | ||
assert.are.same({ | ||
cmd = { "dummy-lsp" }, | ||
name = "dummy", | ||
custom = "setting", | ||
cmd_env = { | ||
PATH = "/keep/my/path/out/your/f/mouth", | ||
SOME_DEFAULT_ENV = "important", | ||
}, | ||
}, config) | ||
end) | ||
end) |
Oops, something went wrong.