diff options
| author | William Boman <william@redwill.se> | 2025-04-22 16:23:55 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-04-22 16:23:55 +0200 |
| commit | 0d297a1932e0c8d1f079d4f5bc302535d7a2c96d (patch) | |
| tree | c28af9a3f74431c35f34f2316ab810ef05872fe6 | |
| parent | feat(ui): support 'winborder' (diff) | |
| download | mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar.gz mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar.bz2 mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar.lz mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar.xz mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.tar.zst mason-0d297a1932e0c8d1f079d4f5bc302535d7a2c96d.zip | |
feat(ui): display purl information
First step towards surfacing more package source information.
| -rw-r--r-- | lua/mason-core/receipt.lua | 6 | ||||
| -rw-r--r-- | lua/mason/ui/components/main/package_list.lua | 7 | ||||
| -rw-r--r-- | lua/mason/ui/instance.lua | 3 | ||||
| -rw-r--r-- | tests/mason-core/receipt_spec.lua | 10 |
4 files changed, 26 insertions, 0 deletions
diff --git a/lua/mason-core/receipt.lua b/lua/mason-core/receipt.lua index 847b8011..ecd20a2c 100644 --- a/lua/mason-core/receipt.lua +++ b/lua/mason-core/receipt.lua @@ -56,6 +56,12 @@ function InstallReceipt:get_source() return self.primary_source --[[@as InstallReceiptSource]] end +---@return string? +function InstallReceipt:get_installed_purl() + local source = self:get_source() + return source.id +end + function InstallReceipt:get_raw_source() if self:is_schema_min "2.0" then return self.source.raw diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua index 55cbe41c..11f0d174 100644 --- a/lua/mason/ui/components/main/package_list.lua +++ b/lua/mason/ui/components/main/package_list.lua @@ -72,6 +72,13 @@ local function ExpandedPackageInfo(state, pkg, is_installed) p.muted "latest version", p.muted(pkg_state.new_version), }, + pkg_state.installed_purl and { + p.muted "installed purl", + p.highlight(pkg_state.installed_purl), + } or { + p.muted "purl", + p.highlight(pkg.spec.source.id), + }, { p.muted "homepage", pkg.spec.homepage and p.highlight(pkg.spec.homepage) or p.muted "-", diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua index a49c585b..0c68b032 100644 --- a/lua/mason/ui/instance.lua +++ b/lua/mason/ui/instance.lua @@ -47,6 +47,7 @@ end ---@field has_failed boolean ---@field latest_spawn string? ---@field linked_executables table<string, string>? +---@field installed_purl string? ---@field lsp_settings_schema table? ---@field new_version string? ---@field short_tailed_output string? @@ -213,6 +214,7 @@ local function create_initial_package_state() has_failed = false, latest_spawn = nil, linked_executables = nil, + installed_purl = nil, lsp_settings_schema = nil, new_version = nil, short_tailed_output = nil, @@ -304,6 +306,7 @@ local function hydrate_detailed_package_state(pkg) function(receipt) mutate_state(function(state) state.packages.states[pkg.name].linked_executables = receipt:get_links().bin + state.packages.states[pkg.name].installed_purl = receipt:get_installed_purl() end) end ) diff --git a/tests/mason-core/receipt_spec.lua b/tests/mason-core/receipt_spec.lua index 5cb01d5b..4436233b 100644 --- a/tests/mason-core/receipt_spec.lua +++ b/tests/mason-core/receipt_spec.lua @@ -70,6 +70,16 @@ describe("receipt ::", function() assert.is_true(receipt:is_schema_min "2.0") end) + it("should retrieve purl information", function() + local receipt_1_0 = InstallReceipt:new(fixture "1.0.json") + local receipt_1_1 = InstallReceipt:new(fixture "1.1.json") + local receipt_2_0 = InstallReceipt:new(fixture "2.0.json") + + assert.is_nil(receipt_1_0:get_installed_purl()) + assert.equals("pkg:npm/%40angular/language-server@16.1.8", receipt_1_1:get_installed_purl()) + assert.equals("pkg:npm/%40angular/language-server@19.1.0", receipt_2_0:get_installed_purl()) + end) + describe("schema versions ::", function() it("should check minimum compatibility", function() local receipt_1_0 = InstallReceipt:new { schema_version = "1.0" } |
