From 9ad7503c32545ee6e8000e52d9ae4a93d49231fb Mon Sep 17 00:00:00 2001 From: Jay Patel <36803168+jay-babu@users.noreply.github.com> Date: Sat, 11 Feb 2023 18:27:37 -0500 Subject: [PATCH] chore: removing some useless code and adding memoization --- lua/mason-null-ls/automatic_installation.lua | 13 ++++--------- lua/mason-null-ls/mappings/source.lua | 8 ++++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lua/mason-null-ls/automatic_installation.lua b/lua/mason-null-ls/automatic_installation.lua index b03c207..72c72dd 100644 --- a/lua/mason-null-ls/automatic_installation.lua +++ b/lua/mason-null-ls/automatic_installation.lua @@ -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 @@ -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 diff --git a/lua/mason-null-ls/mappings/source.lua b/lua/mason-null-ls/mappings/source.lua index 055074e..f5e797b 100644 --- a/lua/mason-null-ls/mappings/source.lua +++ b/lua/mason-null-ls/mappings/source.lua @@ -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