Skip to content

Commit

Permalink
chore: removing some useless code and adding memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-babu committed Feb 11, 2023
1 parent 13c6ab4 commit 9ad7503
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 4 additions & 9 deletions lua/mason-null-ls/automatic_installation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ local function auto_get_packages()
sources = vim.list_extend(sources, vim.tbl_keys(require('null-ls.builtins').code_actions))
sources = vim.list_extend(sources, vim.tbl_keys(require('null-ls.builtins').completion))
sources = vim.list_extend(sources, vim.tbl_keys(require('null-ls.builtins').hover))
local tools = _.uniq_by(_.identity, sources)
return tools
sources = _.uniq_by(_.identity, sources)
return sources
end

---@param null_ls_source_name string
Expand Down Expand Up @@ -60,17 +60,12 @@ return function()
end

for _, source_identifier in ipairs(sources) do
local Package = require('mason-core.package')

local source_name, version = Package.Parse(source_identifier)
resolve_package(source_name):if_present(
resolve_package(source_identifier):if_present(
-- -@param pkg Package
function(pkg)
if not pkg:is_installed() then
vim.notify(('[mason-null-ls] automatically installing %s'):format(pkg.name))
pkg:install({
version = version,
}):once(
pkg:install():once(
'closed',
vim.schedule_wrap(function()
if pkg:is_installed() then
Expand Down
8 changes: 4 additions & 4 deletions lua/mason-null-ls/mappings/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ local package_to_null_ls = _.invert(null_ls_to_package)

---@param source string: Source Name from NullLs
---@return string: Package Name from Mason
M.getPackageFromNullLs = function(source)
M.getPackageFromNullLs = _.memoize(function(source)
return Optional.of_nilable(null_ls_to_package[source]):or_else_get(_.always(source:gsub('%_', '-')))
end
end)

---@param package string: Package Name from Mason
---@return string: NullLs Source Name
M.getNullLsFromPackage = function(package)
M.getNullLsFromPackage = _.memoize(function(package)
return Optional.of_nilable(package_to_null_ls[package]):or_else_get(_.always(package:gsub('%-', '_')))
end
end)

return M

0 comments on commit 9ad7503

Please sign in to comment.