Add format function for LSP progress
Contributing guidelines
- [X] I have read CONTRIBUTING.md
- [X] I have read CODE_OF_CONDUCT.md
Module(s)
mini.notify
Description
Currently the LSP progress message format is hardcoded. See https://github.com/echasnovski/mini.nvim/blob/df1559e2ed7ece458e0a97a8bb9556d465d1c775/lua/mini/notify.lua#L678
It would be nice to make this more dynamic, via a format function.
Please see https://github.com/echasnovski/mini.nvim/pull/1276
Thanks for the suggestion!
I think the proper way is to add some kind of source field to notification specification. One small issue is that add() was not really designed to be extensible (mostly by design to limit complexity). I'd take some time to think if adding source as fourth argument is worth it.
Fair enough. My current workaround is quite hacky:
notify.setup({
content = {
format = function (str)
local parts = vim.split(str.msg, ': ')
if #parts == 2 then
return parts[2]
end
return string.format('\n %s \n', str.msg)
end,
},
window = {
winblend = 0,
config = function ()
local pad = vim.o.cmdheight + (vim.o.laststatus > 0 and 1 or 0)
return {
row = vim.o.lines - pad - 1,
col = vim.o.columns,
border = 'none',
anchor = 'SE',
}
end,
}
})
})
https://gitlab.com/kaspervdheijden/kickstart/-/blob/master/lua/plugins-enabled/mini-nvim.lua?ref_type=heads#L78
Fair enough. My current workaround is quite hacky:
I don't find the code particularly hacky, on the contrary even - quite concise and to the point. The fact that it is applied to any notification and not only to the ones coming from LSP progress - yeah, maybe.
This should now be cleanly possible on latest main through new data field of notifications. All notifications from built-in LSP progress handler set the following fields in data, which includes source. Here is an example of how to write content.format that behaves differently for notifications from LSP progress.
@echasnovski Thank you, I have changed the function to the snippet below which works perfectly! 🥳
content = {
format = function (notification)
if notification.data.source == 'lsp_progress' then
local s_pos, e_pos = string.find(notification.msg, notification.data.client_name .. ': ', 1, true)
if s_pos ~= nil and e_pos ~= nil then
return string.sub(notification.msg, e_pos + 1)
end
end
return notification.msg
end,
}