From 4f19ac004567322440b92c6a127b811d74dcea3c Mon Sep 17 00:00:00 2001 From: Kasper van der Heijden Date: Sun, 13 Oct 2024 14:49:58 +0200 Subject: [PATCH] feat(notify) add lsp progress formatter --- lua/mini/notify.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lua/mini/notify.lua b/lua/mini/notify.lua index 18ecf8c7..01f8079f 100644 --- a/lua/mini/notify.lua +++ b/lua/mini/notify.lua @@ -221,6 +221,9 @@ MiniNotify.config = { -- Whether to enable showing enable = true, + -- Function to format the progress message + format = nil, + -- Duration (in ms) of how long last message should be shown duration_last = 1000, }, @@ -518,6 +521,20 @@ MiniNotify.default_format = function(notif) return string.format('%s │ %s', time, notif.msg) end +--- Default LSP progress formatter +--- +--- Used by default as `config.lsp_progress.format`. +--- +--- @param client_name string +--- @param title string +--- @param message string +--- @param percentage string|integer +--- +--- @return string Formatted LSP progress message. +MiniNotify.default_format_lsp_progress = function(client_name, title, message, percentage) + return string.format('%s: %s %s (%s%%)', client_name, title, message, percentage) +end + --- Default content sort --- --- Used by default as `config.content.sort`. First sorts by notification's `level` @@ -674,11 +691,8 @@ H.lsp_progress_handler = function(err, result, ctx, config) if value.kind == 'begin' then progress_data.title = value.title end -- Make notification - --stylua: ignore - local msg = string.format( - '%s: %s %s (%s%%)', - client_name, progress_data.title or '', value.message or '', progress_data.percentage - ) + local format = vim.is_callable(lsp_progress_config.format) and lsp_progress_config.format or MiniNotify.default_format_lsp_progress + local msg = format(client_name, progress_data.title or '', value.message or '', progress_data.percentage) if progress_data.notif_id == nil then progress_data.notif_id = MiniNotify.add(msg)