diff options
| author | William Boman <william@redwill.se> | 2022-07-07 01:59:09 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2022-07-07 01:59:09 +0200 |
| commit | e94d3e0670e6f524e306a811d77aa12d138a8762 (patch) | |
| tree | f809f739927a647cd48f2bcf595afdfd8c1dbc1f /lua | |
| parent | feat(ui): implement keybind to update all outdated packages (diff) | |
| download | mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar.gz mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar.bz2 mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar.lz mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar.xz mason-e94d3e0670e6f524e306a811d77aa12d138a8762.tar.zst mason-e94d3e0670e6f524e306a811d77aa12d138a8762.zip | |
chore: s/package/pkg/
As to not accidentally access the actual package global 😬
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-lspconfig/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason/core/installer/handle.lua | 6 | ||||
| -rw-r--r-- | lua/mason/core/installer/init.lua | 12 | ||||
| -rw-r--r-- | lua/mason/core/installer/linker.lua | 12 | ||||
| -rw-r--r-- | lua/mason/core/managers/cargo/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason/core/managers/composer/init.lua | 14 | ||||
| -rw-r--r-- | lua/mason/core/managers/dotnet/init.lua | 14 | ||||
| -rw-r--r-- | lua/mason/core/managers/go/init.lua | 4 | ||||
| -rw-r--r-- | lua/mason/core/managers/luarocks/init.lua | 8 | ||||
| -rw-r--r-- | lua/mason/core/managers/pip3/init.lua | 20 | ||||
| -rw-r--r-- | lua/mason/core/receipt.lua | 6 | ||||
| -rw-r--r-- | lua/mason/ui/components/json-schema.lua | 10 | ||||
| -rw-r--r-- | lua/mason/ui/components/main/package_list.lua | 26 |
13 files changed, 70 insertions, 70 deletions
diff --git a/lua/mason-lspconfig/init.lua b/lua/mason-lspconfig/init.lua index b81bef70..ad177be6 100644 --- a/lua/mason-lspconfig/init.lua +++ b/lua/mason-lspconfig/init.lua @@ -10,9 +10,9 @@ local M = {} ---@param lspconfig_server_name string function M.resolve_package(lspconfig_server_name) return Optional.of_nilable(server_mapping.lspconfig_to_package[lspconfig_server_name]):map(function(package_name) - local ok, package = pcall(require, ("mason.packages.%s"):format(package_name)) + local ok, pkg = pcall(require, ("mason.packages.%s"):format(package_name)) if ok then - return package + return pkg end end) end diff --git a/lua/mason/core/installer/handle.lua b/lua/mason/core/installer/handle.lua index 174f7ed6..302668d7 100644 --- a/lua/mason/core/installer/handle.lua +++ b/lua/mason/core/installer/handle.lua @@ -59,11 +59,11 @@ local function new_sink(handle) } end ----@param package Package -function InstallHandle.new(package) +---@param pkg Package +function InstallHandle.new(pkg) local self = EventEmitter.init(setmetatable({}, InstallHandleMt)) self.state = "IDLE" - self.package = package + self.package = pkg self.spawninfo_stack = {} self.stdio = new_sink(self) self.is_terminated = false diff --git a/lua/mason/core/installer/init.lua b/lua/mason/core/installer/init.lua index 5203f381..c4bca124 100644 --- a/lua/mason/core/installer/init.lua +++ b/lua/mason/core/installer/init.lua @@ -27,7 +27,7 @@ end ---@async ---@param context InstallContext local function write_receipt(context) - log.fmt_debug("Writing receipt for %s", package) + log.fmt_debug("Writing receipt for %s", context.package) context.receipt :with_name(context.package.name) :with_schema_version("1.0") @@ -104,10 +104,10 @@ function M.execute(handle, opts) log.fmt_trace("Activating handle %s", handle) handle:active() - local package = handle.package + local pkg = handle.package local context = InstallContext.new(handle, opts) - log.fmt_info("Executing installer for %s", package) + log.fmt_info("Executing installer for %s", pkg) return Result.run_catching(function() -- 1. run installer a.wait(function(resolve, reject) @@ -117,7 +117,7 @@ function M.execute(handle, opts) else reject(result) end - end, context, package.spec.install) + end, context, pkg.spec.install) handle:once("terminate", function() handle:once("closed", function() @@ -139,11 +139,11 @@ function M.execute(handle, opts) :on_success(function() permit:forget() handle:close() - log.fmt_info("Installation succeeded for %s", package) + log.fmt_info("Installation succeeded for %s", pkg) end) :on_failure(function(failure) permit:forget() - log.fmt_error("Installation failed for %s error=%s", package, failure) + log.fmt_error("Installation failed for %s error=%s", pkg, failure) context.stdio_sink.stderr(tostring(failure)) context.stdio_sink.stderr "\n" diff --git a/lua/mason/core/installer/linker.lua b/lua/mason/core/installer/linker.lua index e81f81a5..8ecb3cae 100644 --- a/lua/mason/core/installer/linker.lua +++ b/lua/mason/core/installer/linker.lua @@ -6,20 +6,20 @@ local fs = require "mason.core.fs" local M = {} ----@param package Package +---@param pkg Package ---@param links InstallReceiptLinks -local function unlink_bin(package, links) +local function unlink_bin(pkg, links) for executable in pairs(links.bin) do local bin_path = path.bin_prefix(executable) fs.sync.unlink(bin_path) end end ----@param package Package +---@param pkg Package ---@param links InstallReceiptLinks -function M.unlink(package, links) - log.fmt_debug("Unlinking %s", package) - unlink_bin(package, links) +function M.unlink(pkg, links) + log.fmt_debug("Unlinking %s", pkg) + unlink_bin(pkg, links) end ---@param to string diff --git a/lua/mason/core/managers/cargo/init.lua b/lua/mason/core/managers/cargo/init.lua index aeab65ab..abb24730 100644 --- a/lua/mason/core/managers/cargo/init.lua +++ b/lua/mason/core/managers/cargo/init.lua @@ -125,8 +125,8 @@ function M.get_installed_primary_package_version(receipt, install_dir) if vim.in_fast_event() then a.scheduler() -- needed because vim.fn.* call end - local package = vim.fn.fnamemodify(receipt.primary_source.package, ":t") - return Optional.of_nilable(installed_crates[package]):or_else_throw "Failed to find cargo package version." + local pkg = vim.fn.fnamemodify(receipt.primary_source.package, ":t") + return Optional.of_nilable(installed_crates[pkg]):or_else_throw "Failed to find cargo package version." end) end diff --git a/lua/mason/core/managers/composer/init.lua b/lua/mason/core/managers/composer/init.lua index 98419b8c..aabf2ef3 100644 --- a/lua/mason/core/managers/composer/init.lua +++ b/lua/mason/core/managers/composer/init.lua @@ -88,16 +88,16 @@ function M.check_outdated_primary_package(receipt, install_dir) }) :map_catching(function(result) local outdated_packages = vim.json.decode(result.stdout) - local outdated_package = _.find_first(function(package) - return package.name == receipt.primary_source.package + local outdated_package = _.find_first(function(pkg) + return pkg.name == receipt.primary_source.package end, outdated_packages.installed) return Optional.of_nilable(outdated_package) - :map(function(package) - if package.version ~= package.latest then + :map(function(pkg) + if pkg.version ~= pkg.latest then return { - name = package.name, - current_version = package.version, - latest_version = package.latest, + name = pkg.name, + current_version = pkg.version, + latest_version = pkg.latest, } end end) diff --git a/lua/mason/core/managers/dotnet/init.lua b/lua/mason/core/managers/dotnet/init.lua index 658143bf..91c79b46 100644 --- a/lua/mason/core/managers/dotnet/init.lua +++ b/lua/mason/core/managers/dotnet/init.lua @@ -17,18 +17,18 @@ local function with_receipt(package) end ---@async ----@param package string +---@param pkg string ---@param opt { bin: string[] | nil } | nil -function M.package(package, opt) +function M.package(pkg, opt) return function() - return M.install(package, opt).with_receipt() + return M.install(pkg, opt).with_receipt() end end ---@async ----@param package string +---@param pkg string ---@param opt { bin: string[] | nil } | nil -function M.install(package, opt) +function M.install(pkg, opt) local ctx = installer.context() ctx.spawn.dotnet { "tool", @@ -40,7 +40,7 @@ function M.install(package, opt) return { "--version", version } end) :or_else(vim.NIL), - package, + pkg, } if opt and opt.bin then @@ -52,7 +52,7 @@ function M.install(package, opt) end return { - with_receipt = with_receipt(package), + with_receipt = with_receipt(pkg), } end diff --git a/lua/mason/core/managers/go/init.lua b/lua/mason/core/managers/go/init.lua index fe5c7289..b9b4898a 100644 --- a/lua/mason/core/managers/go/init.lua +++ b/lua/mason/core/managers/go/init.lua @@ -17,8 +17,8 @@ local function with_receipt(packages) ctx.receipt:with_primary_source(ctx.receipt.go(packages[1])) -- Install secondary packages for i = 2, #packages do - local package = packages[i] - ctx.receipt:with_secondary_source(ctx.receipt.go(package)) + local pkg = packages[i] + ctx.receipt:with_secondary_source(ctx.receipt.go(pkg)) end end end diff --git a/lua/mason/core/managers/luarocks/init.lua b/lua/mason/core/managers/luarocks/init.lua index 7ce172a3..7888ba4b 100644 --- a/lua/mason/core/managers/luarocks/init.lua +++ b/lua/mason/core/managers/luarocks/init.lua @@ -26,9 +26,9 @@ function M.package(package, opts) end ---@async ----@param package string @The luarock package to install. +---@param pkg string @The luarock package to install. ---@param opts {dev: boolean}|nil -function M.install(package, opts) +function M.install(pkg, opts) opts = opts or {} local ctx = installer.context() ctx:promote_cwd() @@ -37,11 +37,11 @@ function M.install(package, opts) "--tree", ctx.cwd:get(), opts.dev and "--dev" or vim.NIL, - package, + pkg, ctx.requested_version:or_else(vim.NIL), } return { - with_receipt = with_receipt(package), + with_receipt = with_receipt(pkg), } end diff --git a/lua/mason/core/managers/pip3/init.lua b/lua/mason/core/managers/pip3/init.lua index 62755d93..a599b8a7 100644 --- a/lua/mason/core/managers/pip3/init.lua +++ b/lua/mason/core/managers/pip3/init.lua @@ -82,11 +82,11 @@ function M.install(packages) } end ----@param package string +---@param pkg string ---@return string -function M.normalize_package(package) +function M.normalize_package(pkg) -- https://stackoverflow.com/a/60307740 - local s = package:gsub("%[.*%]", "") + local s = pkg:gsub("%[.*%]", "") return s end @@ -119,11 +119,11 @@ function M.check_outdated_primary_package(receipt, install_dir) end, packages) return Optional.of_nilable(outdated_primary_package) - :map(function(package) + :map(function(pkg) return { name = normalized_package, - current_version = assert(package.version), - latest_version = assert(package.latest_version), + current_version = assert(pkg.version), + latest_version = assert(pkg.latest_version), } end) :or_else_throw "Primary package is not outdated." @@ -149,12 +149,12 @@ function M.get_installed_primary_package_version(receipt, install_dir) :map_catching(function(result) local pip_packages = vim.json.decode(result.stdout) local normalized_pip_package = M.normalize_package(receipt.primary_source.package) - local pip_package = _.find_first(function(package) - return package.name == normalized_pip_package + local pip_package = _.find_first(function(pkg) + return pkg.name == normalized_pip_package end, pip_packages) return Optional.of_nilable(pip_package) - :map(function(package) - return package.version + :map(function(pkg) + return pkg.version end) :or_else_throw "Unable to find pip package." end) diff --git a/lua/mason/core/receipt.lua b/lua/mason/core/receipt.lua index 233715fe..76cd7449 100644 --- a/lua/mason/core/receipt.lua +++ b/lua/mason/core/receipt.lua @@ -117,9 +117,9 @@ end ---@param type InstallReceiptSourceType local function package_source(type) - ---@param package string - return function(package) - return { type = type, package = package } + ---@param pkg string + return function(pkg) + return { type = type, package = pkg } end end diff --git a/lua/mason/ui/components/json-schema.lua b/lua/mason/ui/components/json-schema.lua index 8bb0e05d..98908280 100644 --- a/lua/mason/ui/components/json-schema.lua +++ b/lua/mason/ui/components/json-schema.lua @@ -36,7 +36,7 @@ local function Indent(indentation, children) return Ui.CascadingStyleNode(indent, children) end ----@param package Package +---@param pkg Package ---@param schema_id string ---@param state UiPackageState ---@param schema table @@ -44,13 +44,13 @@ end ---@param level number|nil ---@param key_width number|nil @The width the key should occupate in the UI to produce an even column. ---@param compound_key string|nil -local function JsonSchema(package, schema_id, state, schema, key, level, key_width, compound_key) +local function JsonSchema(pkg, schema_id, state, schema, key, level, key_width, compound_key) level = level or 0 compound_key = ("%s%s"):format(compound_key or "", key or "") local toggle_expand_keybind = Ui.Keybind( settings.current.ui.keymaps.toggle_package_expand, "TOGGLE_JSON_SCHEMA_KEY", - { package = package, schema_id = schema_id, key = compound_key } + { package = pkg, schema_id = schema_id, key = compound_key } ) local node_is_expanded = state.expanded_json_schema_keys[schema_id][compound_key] local key_prefix = node_is_expanded and "↓ " or "→ " @@ -80,7 +80,7 @@ local function JsonSchema(package, schema_id, state, schema, key, level, key_wid for _, property in ipairs(sorted_properties) do nodes[#nodes + 1] = Indent(level, { JsonSchema( - package, + pkg, schema_id, state, schema.properties[property], @@ -97,7 +97,7 @@ local function JsonSchema(package, schema_id, state, schema, key, level, key_wid local nodes = {} for i, alternative_schema in ipairs(schema.oneOf) do nodes[#nodes + 1] = JsonSchema( - package, + pkg, schema_id, state, alternative_schema, diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua index 68d954cd..ffd9647b 100644 --- a/lua/mason/ui/components/main/package_list.lua +++ b/lua/mason/ui/components/main/package_list.lua @@ -9,9 +9,9 @@ local JsonSchema = require "mason.ui.components.json-schema" local function PackageListContainer(props) local items = {} for i = 1, #props.packages do - local package = props.packages[i] - if props.state.packages.visible[package.name] then - items[#items + 1] = props.list_item_renderer(package) + local pkg = props.packages[i] + if props.state.packages.visible[pkg.name] then + items[#items + 1] = props.list_item_renderer(pkg) end end @@ -47,12 +47,12 @@ local function ExecutablesTable(executables) end ---@param state InstallerUiState ----@param package Package +---@param pkg Package ---@param is_installed boolean -local function ExpandedPackageInfo(state, package, is_installed) - local pkg_state = state.packages.states[package.name] +local function ExpandedPackageInfo(state, pkg, is_installed) + local pkg_state = state.packages.states[pkg.name] return Ui.CascadingStyleNode({ "INDENT" }, { - Ui.HlTextNode(p.Comment(package.spec.desc)), + Ui.HlTextNode(p.Comment(pkg.spec.desc)), Ui.EmptyLine(), Ui.Table(_.concat( _.filter(_.identity, { @@ -67,18 +67,18 @@ local function ExpandedPackageInfo(state, package, is_installed) }, { p.muted "homepage", - package.spec.homepage and p.highlight(package.spec.homepage) or p.muted "-", + pkg.spec.homepage and p.highlight(pkg.spec.homepage) or p.muted "-", }, { p.muted "languages", - #package.spec.languages > 0 and p.Bold(table.concat(package.spec.languages, ", ")) or p.muted "-", + #pkg.spec.languages > 0 and p.Bold(table.concat(pkg.spec.languages, ", ")) or p.muted "-", }, { p.muted "categories", - #package.spec.categories > 0 and p.Bold(table.concat(package.spec.categories, ", ")) or p.muted "-", + #pkg.spec.categories > 0 and p.Bold(table.concat(pkg.spec.categories, ", ")) or p.muted "-", }, }), - ExecutablesTable(is_installed and pkg_state.linked_executables or package.spec.executables) + ExecutablesTable(is_installed and pkg_state.linked_executables or pkg.spec.executables) )), -- ExecutablesTable(is_installed and pkg_state.linked_executables or package.spec.executables), Ui.When(pkg_state.lsp_settings_schema, function() @@ -94,7 +94,7 @@ local function ExpandedPackageInfo(state, package, is_installed) Ui.Keybind( settings.current.ui.keymaps.toggle_package_expand, "TOGGLE_JSON_SCHEMA", - { package = package, schema_id = "lsp" } + { package = pkg, schema_id = "lsp" } ), Ui.When(has_expanded, function() return Ui.CascadingStyleNode({ "INDENT" }, { @@ -102,7 +102,7 @@ local function ExpandedPackageInfo(state, package, is_installed) p.muted "This is a read-only overview of the settings this server accepts. Note that some settings might not apply to neovim." ), Ui.EmptyLine(), - JsonSchema(package, "lsp", pkg_state, pkg_state.lsp_settings_schema), + JsonSchema(pkg, "lsp", pkg_state, pkg_state.lsp_settings_schema), }) end), } |
