From e9ccf782c0b4e9f7df47cc30972185e048e0ea67 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 26 Oct 2022 23:55:39 +0200 Subject: [PATCH] feat: added configurable commands --- lua/noice/commands.lua | 33 +++++++++++++++++++++------------ lua/noice/config/init.lua | 35 +++++++++++++++++++++++++++++------ lua/noice/config/views.lua | 7 ++++--- 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/lua/noice/commands.lua b/lua/noice/commands.lua index 588528c..9349bed 100644 --- a/lua/noice/commands.lua +++ b/lua/noice/commands.lua @@ -6,10 +6,25 @@ local Config = require("noice.config") local Util = require("noice.util") local Message = require("noice.message") +---@class NoiceCommand: NoiceRouteConfig +---@field filter_opts NoiceMessageOpts + local M = {} ----@type NoiceView? -M._history_view = nil +---@param command NoiceCommand +function M.command(command) + return function() + local view = View.get_view(command.view, command.opts) + view:display(Manager.get( + command.filter, + vim.tbl_deep_extend("force", { + history = true, + sort = true, + }, command.filter_opts or {}) + )) + view:show() + end +end function M.setup() local commands = { @@ -41,18 +56,12 @@ function M.setup() message:set(vim.inspect(Config.options)) Manager.add(message) end, - history = function() - if not M._history_view then - M._history_view = View.get_view(Config.options.history.view, Config.options.history.opts) - end - M._history_view:display(Manager.get(Config.options.history.filter, { - history = true, - sort = true, - })) - M._history_view:show() - end, } + for name, command in pairs(Config.options.commands) do + commands[name] = M.command(command) + end + vim.api.nvim_create_user_command("Noice", function(args) local cmd = vim.trim(args.args or "") if commands[cmd] then diff --git a/lua/noice/config/init.lua b/lua/noice/config/init.lua index aeb1856..eb72ad6 100644 --- a/lua/noice/config/init.lua +++ b/lua/noice/config/init.lua @@ -47,12 +47,29 @@ M.defaults = { -- Icons for completion item kinds (see defaults at noice.config.icons.kinds) kind_icons = {}, -- set to `false` to disable icons }, - ---@type NoiceRouteConfig - history = { - -- options for the message history that you get with `:Noice` - view = "split", - opts = { enter = true, format = "details" }, - filter = { event = { "msg_show", "notify" }, ["not"] = { kind = { "search_count", "echo" } } }, + ---@type table + commands = { + history = { + -- options for the message history that you get with `:Noice` + view = "split", + opts = { enter = true, format = "details" }, + filter = { event = { "msg_show", "notify" }, ["not"] = { kind = { "search_count", "echo" } } }, + }, + -- :Noice last + last = { + view = "popup", + opts = { enter = true, format = "details" }, + filter = { event = { "msg_show", "notify" }, ["not"] = { kind = { "search_count", "echo" } } }, + filter_opts = { count = 1 }, + }, + -- :Noice errors + errors = { + -- options for the message history that you get with `:Noice` + view = "popup", + opts = { enter = true, format = "details" }, + filter = { error = true }, + filter_opts = { reverse = true }, + }, }, notify = { -- Noice can be used as `vim.notify` so you can route any notification like other messages @@ -185,6 +202,12 @@ function M.fix_legacy(opts) if opts.lsp_progress then opts.lsp = opts.lsp or {} opts.lsp.progress = opts.lsp_progress + opts.lsp_progress = nil + end + if opts.history then + opts.commands = opts.commands or {} + opts.commands.history = opts.history + opts.history = nil end end diff --git a/lua/noice/config/views.lua b/lua/noice/config/views.lua index 46af941..ad556ec 100644 --- a/lua/noice/config/views.lua +++ b/lua/noice/config/views.lua @@ -85,18 +85,19 @@ M.defaults = { }, popup = { backend = "popup", + relative = "editor", close = { events = { "BufLeave" }, keys = { "q" }, }, enter = true, border = { - style = "single", + style = "rounded", }, position = "50%", size = { - width = "80%", - height = "60%", + width = "120", + height = "20", }, win_options = { winhighlight = { Normal = "NoicePopup", FloatBorder = "NoicePopupBorder" },