Skip to content

Commit

Permalink
feat: add .get_mappings() (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Oct 29, 2022
1 parent 0fd9fbe commit a910b4d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
58 changes: 33 additions & 25 deletions doc/mason-lspconfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,31 +219,30 @@ setup_handlers({handlers})
mason's package names, so for example instead of "lua-language-server"
it's "sumneko_lua".

Example: ~

require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {}
end,
-- Next, you can provide targeted overrides for specific servers.
["rust_analyzer"] = function ()
require("rust-tools").setup {}
end,
["sumneko_lua"] = function ()
lspconfig.sumneko_lua.setup {
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
}
end,
})
Example: ~
require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup {}
end,
-- Next, you can provide targeted overrides for specific servers.
["rust_analyzer"] = function ()
require("rust-tools").setup {}
end,
["sumneko_lua"] = function ()
lspconfig.sumneko_lua.setup {
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
}
end,
})

See also: ~
You may achieve similar behaviour by manually looping through the
Expand Down Expand Up @@ -292,5 +291,14 @@ get_available_servers({filter})
|mason-registry.get_all_packages()|
|mason-registry.get_all_package_names()|

*mason-lspconfig.get_mappings()*
get_mappings()
Returns the server name mappings between lspconfig and Mason.

Returns: ~
{
lspconfig_to_mason: table<string, string>,
mason_to_lspconfig: table<string, string>
}

vim:tw=78:ft=help:norl:expandtab:sw=4
10 changes: 10 additions & 0 deletions lua/mason-lspconfig/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,14 @@ function M.get_available_servers(filter)
end, registry.get_all_package_names())
end

---Returns the "lspconfig <-> mason" mapping tables.
---@return { lspconfig_to_mason: table<string, string>, mason_to_lspconfig: table<string, string> }
function M.get_mappings()
local mappings = require "mason-lspconfig.mappings.server"
return {
lspconfig_to_mason = mappings.lspconfig_to_package,
mason_to_lspconfig = mappings.package_to_lspconfig,
}
end

return M

0 comments on commit a910b4d

Please sign in to comment.