Skip to content

Commit

Permalink
feat: add get_available_servers (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylo252 committed Aug 2, 2022
1 parent f87c579 commit c3f16f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lua/mason-lspconfig/api/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,15 @@ end, {

_G.mason_lspconfig_completion = {
available_server_completion = function()
local registry = require "mason-registry"
local server_mapping = require "mason-lspconfig.mappings.server"
local available_servers = require("mason-lspconfig").get_available_servers()
local language_mapping = require "mason.mappings.language"

local package_names = _.filter_map(function(pkg_name)
return Optional.of_nilable(server_mapping.package_to_lspconfig[pkg_name])
end, registry.get_all_package_names())
local completion =
_.compose(_.sort_by(_.identity), _.uniq_by(_.identity), _.concat(_.keys(language_mapping)))(package_names)
return table.concat(completion, "\n")
local sort_deduped = _.compose(_.sort_by(_.identity), _.uniq_by(_.identity))
local completions = sort_deduped(_.concat(_.keys(language_mapping), available_servers))
return table.concat(completions, "\n")
end,
installed_server_completion = function()
local registry = require "mason-registry"
local server_mapping = require "mason-lspconfig.mappings.server"

local server_names = _.filter_map(function(pkg_name)
return Optional.of_nilable(server_mapping.package_to_lspconfig[pkg_name])
end, registry.get_installed_package_names())
table.sort(server_names)
return table.concat(server_names, "\n")
local installed_servers = require("mason-lspconfig").get_installed_servers()
return table.concat(installed_servers, "\n")
end,
}

Expand Down
12 changes: 12 additions & 0 deletions lua/mason-lspconfig/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,16 @@ function M.get_installed_servers()
end, registry.get_installed_package_names())
end

---Get a list of available servers in mason-registry
---@return string[]
function M.get_available_servers()
local registry = require "mason-registry"
local server_mapping = require "mason-lspconfig.mappings.server"
local Optional = require "mason-core.optional"
local server_names = _.filter_map(function(pkg_name)
return Optional.of_nilable(server_mapping.package_to_lspconfig[pkg_name])
end, registry.get_all_package_names())
return server_names
end

return M

0 comments on commit c3f16f5

Please sign in to comment.