aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-core/EventEmitter.lua4
-rw-r--r--lua/mason-core/ui/display.lua22
-rw-r--r--lua/mason/ui/components/header.lua1
-rw-r--r--lua/mason/ui/components/main/package_list.lua11
-rw-r--r--lua/mason/ui/instance.lua26
5 files changed, 63 insertions, 1 deletions
diff --git a/lua/mason-core/EventEmitter.lua b/lua/mason-core/EventEmitter.lua
index 403628a0..7d95827f 100644
--- a/lua/mason-core/EventEmitter.lua
+++ b/lua/mason-core/EventEmitter.lua
@@ -5,6 +5,10 @@ local log = require "mason-core.log"
local EventEmitter = {}
EventEmitter.__index = EventEmitter
+function EventEmitter.new()
+ return EventEmitter.init(setmetatable({}, EventEmitter))
+end
+
---@generic T
---@param obj T
---@return T
diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua
index 009fb580..4c6a06c2 100644
--- a/lua/mason-core/ui/display.lua
+++ b/lua/mason-core/ui/display.lua
@@ -1,3 +1,4 @@
+local EventEmitter = require "mason-core.EventEmitter"
local log = require "mason-core.log"
local settings = require "mason.settings"
local state = require "mason-core.ui.state"
@@ -212,6 +213,8 @@ function M.new_view_only_win(name, filetype)
---@type WindowOpts
local window_opts = {}
+ local events = EventEmitter.new()
+
vim.diagnostic.config({
virtual_text = {
severity = { min = vim.diagnostic.severity.HINT, max = vim.diagnostic.severity.ERROR },
@@ -367,6 +370,24 @@ function M.new_view_only_win(name, filetype)
bufnr = vim.api.nvim_create_buf(false, true)
win_id = vim.api.nvim_open_win(bufnr, true, create_popup_window_opts(window_opts, false))
+ vim.api.nvim_create_autocmd("CmdLineEnter", {
+ buffer = bufnr,
+ callback = function()
+ if vim.v.event.cmdtype == "/" or vim.v.event.cmdtype == "?" then
+ events:emit "search:enter"
+ end
+ end,
+ })
+
+ vim.api.nvim_create_autocmd("CmdLineLeave", {
+ buffer = bufnr,
+ callback = function(args)
+ if vim.v.event.cmdtype == "/" or vim.v.event.cmdtype == "?" then
+ events:emit("search:leave", vim.fn.getcmdline())
+ end
+ end,
+ })
+
registered_effect_handlers = window_opts.effects
registered_keybinds = {}
registered_keymaps = {}
@@ -455,6 +476,7 @@ function M.new_view_only_win(name, filetype)
end
return {
+ events = events,
---@param _renderer fun(state: table): table
view = function(_renderer)
renderer = _renderer
diff --git a/lua/mason/ui/components/header.lua b/lua/mason/ui/components/header.lua
index fc2aeac6..5ef764d4 100644
--- a/lua/mason/ui/components/header.lua
+++ b/lua/mason/ui/components/header.lua
@@ -15,6 +15,7 @@ return function(state)
p.none((" "):rep(#state.header.title_prefix + 1)),
}, {
p.header " mason.nvim ",
+ state.view.is_searching and p.Comment " (search mode, press <Esc> to clear)" or p.none "",
}),
Ui.When(
state.view.is_showing_help,
diff --git a/lua/mason/ui/components/main/package_list.lua b/lua/mason/ui/components/main/package_list.lua
index a90af3e9..5066b2de 100644
--- a/lua/mason/ui/components/main/package_list.lua
+++ b/lua/mason/ui/components/main/package_list.lua
@@ -115,6 +115,8 @@ local function ExpandedPackageInfo(state, pkg, is_installed)
})
end
+local get_package_search_keywords = _.compose(_.join ", ", _.map(_.to_lower), _.path { "spec", "languages" })
+
---@param state InstallerUiState
---@param pkg Package
---@param opts { keybinds: KeybindHandlerNode[], icon: string[], is_installed: boolean, sticky: StickyCursorNode? }
@@ -125,7 +127,14 @@ local function PackageComponent(state, pkg, opts)
return Ui.Node {
Ui.HlTextNode {
- { opts.icon, label, p.none " ", p.Comment(table.concat(pkg:get_aliases(), ", ")) },
+ {
+ opts.icon,
+ label,
+ p.none " ",
+ p.Comment(table.concat(pkg:get_aliases(), ", ")),
+ state.view.is_searching and p.Comment(" // keywords: " .. get_package_search_keywords(pkg))
+ or p.none "",
+ },
},
opts.sticky or Ui.Node {},
Ui.When(pkg_state.is_checking_new_version, function()
diff --git a/lua/mason/ui/instance.lua b/lua/mason/ui/instance.lua
index be891af4..daf8647f 100644
--- a/lua/mason/ui/instance.lua
+++ b/lua/mason/ui/instance.lua
@@ -25,6 +25,7 @@ local function GlobalKeybinds(state)
Ui.Keybind("q", "CLOSE_WINDOW", nil, true),
Ui.When(not state.view.language_filter, Ui.Keybind("<Esc>", "CLOSE_WINDOW", nil, true)),
Ui.When(state.view.language_filter, Ui.Keybind("<Esc>", "CLEAR_LANGUAGE_FILTER", nil, true)),
+ Ui.When(state.view.is_searching, Ui.Keybind("<Esc>", "CLEAR_SEARCH_MODE", nil, true)),
Ui.Keybind(settings.current.ui.keymaps.apply_language_filter, "LANGUAGE_FILTER", nil, true),
Ui.Keybind(settings.current.ui.keymaps.update_all_packages, "UPDATE_ALL_PACKAGES", nil, true),
@@ -65,6 +66,7 @@ local INITIAL_STATE = {
registry_update_error = nil,
},
view = {
+ is_searching = false,
is_showing_help = false,
is_current_settings_expanded = false,
language_filter = nil,
@@ -144,6 +146,23 @@ window.view(
local mutate_state, get_state = window.state(INITIAL_STATE)
+window.events:on("search:enter", function()
+ mutate_state(function(state)
+ state.view.is_searching = true
+ end)
+ vim.schedule(function()
+ vim.cmd.redraw()
+ end)
+end)
+
+window.events:on("search:leave", function(search)
+ if search == "" then
+ mutate_state(function(state)
+ state.view.is_searching = false
+ end)
+ end
+end)
+
---@param pkg Package
---@param group string
---@param tail boolean? Whether to insert at the end.
@@ -551,6 +570,12 @@ local function clear_filter()
end)
end
+local function clear_search_mode()
+ mutate_state(function(state)
+ state.view.is_searching = false
+ end)
+end
+
local function toggle_expand_current_settings()
mutate_state(function(state)
state.view.is_current_settings_expanded = not state.view.is_current_settings_expanded
@@ -579,6 +604,7 @@ local effects = {
["CHECK_NEW_PACKAGE_VERSION"] = a.scope(_.compose(_.partial(pcall, check_new_package_version), _.prop "payload")),
["CHECK_NEW_VISIBLE_PACKAGE_VERSIONS"] = a.scope(check_new_visible_package_versions),
["CLEAR_LANGUAGE_FILTER"] = clear_filter,
+ ["CLEAR_SEARCH_MODE"] = clear_search_mode,
["CLOSE_WINDOW"] = window.close,
["INSTALL_PACKAGE"] = install_package,
["LANGUAGE_FILTER"] = filter,