Skip to content

Commit

Permalink
feat: register package aliases (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
avegancafe committed Apr 5, 2023
1 parent 1e653e0 commit 4b9cb43
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/mason-lspconfig/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ function M.setup(config)
require "mason-lspconfig.ensure_installed"()
end

local registry = require "mason-registry"
if registry.register_package_aliases then
registry.register_package_aliases(_.map(function(server_name)
return { server_name }
end, require("mason-lspconfig.mappings.server").package_to_lspconfig))
end

require "mason-lspconfig.api.command"
end

Expand Down
25 changes: 25 additions & 0 deletions tests/helpers/lua/test_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ function async_test(suspend_fn)
end
end

local TableMock = {}
TableMock.__index = TableMock

function TableMock.new(tbl, key)
return setmetatable({
tbl = tbl,
key = key,
}, TableMock)
end

function TableMock:apply(value)
self.original_value = self.tbl[self.key]
self.tbl[self.key] = value
end

function TableMock:revert()
self.tbl[self.key] = self.original_value
end

-- selene: allow(incorrect_standard_library_use)
mockx = {
just_runs = function() end,
Expand All @@ -29,6 +48,12 @@ mockx = {
error(exception, 2)
end
end,
table = function(tbl, key, new_value)
local mock = TableMock.new(tbl, key)
mock:apply(new_value)
assert:add_spy(mock)
return mock
end,
}

---@param package_name string
Expand Down
18 changes: 18 additions & 0 deletions tests/mason-lspconfig/setup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ describe("mason-lspconfig setup", function()

assert.same({ name = "dummylsp", cmd = { "user-cmd" } }, config)
end)

it("should set up package aliases", function()
stub(registry, "register_package_aliases")

local mapping_mock = mockx.table(require "mason-lspconfig.mappings.server", "package_to_lspconfig", {
["rust-analyzer"] = "rust_analyzer",
["typescript-language-server"] = "tsserver",
})

mason_lspconfig.setup {}

assert.spy(registry.register_package_aliases).was_called(1)
assert.spy(registry.register_package_aliases).was_called_with {
["rust-analyzer"] = { "rust_analyzer" },
["typescript-language-server"] = { "tsserver" },
}
mapping_mock:revert()
end)
end)

describe("mason-lspconfig setup_handlers", function()
Expand Down
5 changes: 5 additions & 0 deletions vim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ globals:
mockx.returns:
args:
- type: any
mockx.table:
args:
- type: table
- type: string
- type: any

describe:
args:
Expand Down

0 comments on commit 4b9cb43

Please sign in to comment.