aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-08-12 00:34:52 +0200
committerGitHub <noreply@github.com>2022-08-12 00:34:52 +0200
commit1eb0941ac121377042dc7c4b727a515e99832662 (patch)
tree3804eef3608f2b45f2d62fc4738fe1b8c249829b
parentfeat: add xmlformatter (#281) (diff)
downloadmason-1eb0941ac121377042dc7c4b727a515e99832662.tar
mason-1eb0941ac121377042dc7c4b727a515e99832662.tar.gz
mason-1eb0941ac121377042dc7c4b727a515e99832662.tar.bz2
mason-1eb0941ac121377042dc7c4b727a515e99832662.tar.lz
mason-1eb0941ac121377042dc7c4b727a515e99832662.tar.xz
mason-1eb0941ac121377042dc7c4b727a515e99832662.tar.zst
mason-1eb0941ac121377042dc7c4b727a515e99832662.zip
feat(ui): check for new package versions when opening :Mason (#285)
-rw-r--r--README.md3
-rw-r--r--doc/mason.txt23
-rw-r--r--lua/mason/settings.lua3
-rw-r--r--lua/mason/ui/instance.lua101
4 files changed, 74 insertions, 56 deletions
diff --git a/README.md b/README.md
index 82f2f70e..0bd511c4 100644
--- a/README.md
+++ b/README.md
@@ -153,6 +153,9 @@ require("mason").setup({
```lua
local DEFAULT_SETTINGS = {
ui = {
+ -- Whether to automatically check for new versions when opening the :Mason window.
+ check_outdated_packages_on_open = true,
+
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",
diff --git a/doc/mason.txt b/doc/mason.txt
index d9196f98..86ed02c4 100644
--- a/doc/mason.txt
+++ b/doc/mason.txt
@@ -18,10 +18,10 @@ linked to a single `bin/` directory, which `mason.nvim` will add to the
Neovim's PATH during setup, allowing easy access for the builtin
shell/terminal as well as other 3rd party plugins.
-API reference:
+API reference: ~
https://github.com/williamboman/mason.nvim/blob/main/doc/reference.md
-Extensions:
+Extensions: ~
- https://github.com/williamboman/mason-lspconfig.nvim
==============================================================================
@@ -145,6 +145,9 @@ Example:
local DEFAULT_SETTINGS = {
ui = {
+ -- Whether to automatically check for new versions when opening the :Mason window.
+ check_outdated_packages_on_open = true,
+
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",
@@ -278,10 +281,10 @@ is_installed({package_name})
this is a more efficient option than the Package:is_installed() method due
to a smaller amount of modules required to load.
- Parameters:
+ Parameters: ~
{package_name} - string
- Returns:
+ Returns: ~
boolean
*mason-registry.get_package()*
@@ -291,10 +294,10 @@ get_package({package_name})
This function errors if a package cannot be found.
- Parameters:
+ Parameters: ~
{package_name} - string
- Returns:
+ Returns: ~
Package
*mason-registry.get_installed_packages()*
@@ -302,7 +305,7 @@ get_installed_packages()
Returns all installed package instances. This is a slower function that
loads more modules.
- Returns:
+ Returns: ~
Package[]
*mason-registry.get_installed_package_names()*
@@ -310,7 +313,7 @@ get_installed_package_names()
Returns all installed package names. This is a fast function that doesn't
load any extra modules.
- Returns:
+ Returns: ~
string[]
*mason-registry.get_all_packages()*
@@ -318,7 +321,7 @@ get_all_packages()
Returns all package instances. This is a slower function that loads more
modules.
- Returns:
+ Returns: ~
Package[]
*mason-registry.get_all_package_names()*
@@ -326,7 +329,7 @@ get_all_package_names()
Returns all package names. This is a fast function that doesn't load any
extra modules.
- Returns:
+ Returns: ~
string[]
diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua
index 015c7b6d..0a980235 100644
--- a/lua/mason/settings.lua
+++ b/lua/mason/settings.lua
@@ -5,6 +5,9 @@ local M = {}
---@class MasonSettings
local DEFAULT_SETTINGS = {
ui = {
+ -- Whether to automatically check for new versions when opening the :Mason window.
+ check_outdated_packages_on_open = true,
+
-- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
border = "none",
diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua
index c3da5d47..6ac14d30 100644
--- a/lua/mason/ui/instance.lua
+++ b/lua/mason/ui/instance.lua
@@ -291,52 +291,6 @@ local function create_initial_package_state()
}
end
-for _, pkg in ipairs(packages) do
- -- hydrate initial state
- mutate_state(function(state)
- state.packages.states[pkg.name] = create_initial_package_state()
- state.packages.visible[pkg.name] = true
- table.insert(state.packages[pkg:is_installed() and "installed" or "uninstalled"], pkg)
- end)
-
- pkg:get_handle():if_present(setup_handle)
- pkg:on("handle", setup_handle)
-
- pkg:on("install:success", function()
- mutate_state(function(state)
- state.packages.states[pkg.name] = create_initial_package_state()
- if state.packages.expanded == pkg.name then
- hydrate_detailed_package_state(pkg)
- end
- end)
- mutate_package_grouping(pkg, "installed")
- vim.schedule_wrap(notify)(("%q was successfully installed."):format(pkg.name))
- end)
-
- pkg:on(
- "install:failed",
- ---@param handle InstallHandle
- function(handle)
- if handle.is_terminated then
- -- If installation was explicitly terminated - restore to "pristine" state
- mutate_state(function(state)
- state.packages.states[pkg.name] = create_initial_package_state()
- end)
- mutate_package_grouping(pkg, pkg:is_installed() and "installed" or "uninstalled")
- else
- mutate_package_grouping(pkg, "failed")
- end
- end
- )
-
- pkg:on("uninstall:success", function()
- mutate_state(function(state)
- state.packages.states[pkg.name] = create_initial_package_state()
- end)
- mutate_package_grouping(pkg, "uninstalled")
- end)
-end
-
local help_animation
do
local help_command = ":help"
@@ -603,11 +557,66 @@ local effects = {
["UPDATE_ALL_PACKAGES"] = update_all_packages,
}
+for _, pkg in ipairs(packages) do
+ -- hydrate initial state
+ mutate_state(function(state)
+ state.packages.states[pkg.name] = create_initial_package_state()
+ state.packages.visible[pkg.name] = true
+ table.insert(state.packages[pkg:is_installed() and "installed" or "uninstalled"], pkg)
+ end)
+
+ pkg:get_handle():if_present(setup_handle)
+ pkg:on("handle", setup_handle)
+
+ pkg:on("install:success", function()
+ mutate_state(function(state)
+ state.packages.states[pkg.name] = create_initial_package_state()
+ if state.packages.expanded == pkg.name then
+ hydrate_detailed_package_state(pkg)
+ end
+ end)
+ mutate_package_grouping(pkg, "installed")
+ vim.schedule_wrap(notify)(("%q was successfully installed."):format(pkg.name))
+ end)
+
+ pkg:on(
+ "install:failed",
+ ---@param handle InstallHandle
+ function(handle)
+ if handle.is_terminated then
+ -- If installation was explicitly terminated - restore to "pristine" state
+ mutate_state(function(state)
+ state.packages.states[pkg.name] = create_initial_package_state()
+ end)
+ mutate_package_grouping(pkg, pkg:is_installed() and "installed" or "uninstalled")
+ else
+ mutate_package_grouping(pkg, "failed")
+ end
+ end
+ )
+
+ pkg:on("uninstall:success", function()
+ mutate_state(function(state)
+ state.packages.states[pkg.name] = create_initial_package_state()
+ end)
+ mutate_package_grouping(pkg, "uninstalled")
+ end)
+end
+
window.init {
effects = effects,
highlight_groups = palette.highlight_groups,
}
+if settings.current.ui.check_outdated_packages_on_open then
+ vim.defer_fn(
+ a.scope(function()
+ check_new_visible_package_versions()
+ end),
+ 100
+ )
+end
+
return {
window = window,
set_view = function(view)