-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat request: possibility to update notification window #43
Comments
Hmm I do like this idea. I definitely prefer the 2nd option you've suggested (the first would require some awkward state handling). As you suggested it could reset the timeout each time that it is called but that has the disadvantage of requiring the caller to constantly update to avoid it timing out. Alternatively the local notify_obj = notify("Hello world", "info", {timeout = false})
notify_obj.update("This is the new text to show!")
local timer = vim.loop.new_timer()
timer:start(2000, 0, notify_obj.update) -- Closes the window by not providing update text I'll probably put some more thought into it before implementing it, The API could instead have an |
This would be super useful. I just spent a couple hours making it so that my LSP diagnostics for a line appear in a notify window on hover and refresh on line change and the hacky stuff I had to put together with global variables and nvim_win_close is honestly terrifying. |
I think the My use case is similar to @hassec's, i.e. I want to show the progress of the background indexing for an LSP server.
I would even go as far and say:
Aspect (2) is optional in my opinion, it's just convenience and I could work this out outside of As an additional feature, I would like to see all the in-between progress notifications in my notification history ( |
Sorry there's been no movement on this, been away and quite busy but glad to see some discussion on it!
This actually changes my mind on how this might work. Internally these would be totally separate notifications, the only difference being that they share the same window. I'd like to keep this transparent so instead of the returned object having properties to call, there would be another module function local notify = require("notify")
local notify_obj = notify("1st message", "info", {
title = "First Title",
timeout = false, -- Won't close itself
on_close = function()
print("This is closed when replaced")
end,
})
local next_notify_obj = notify.replace(notify_obj, "2nd message", nil, {
on_close = function()
print("This is also closed when replaced")
end,
})
notify.replace(next_notify_obj, "3rd message", nil, {
title = "Last Title",
timeout = 1000,
on_close = function()
print("This is closed when timeout occurs")
end,
}) |
No worries. Your latest API draft sounds great to me, and afaict would suit my use case perfectly.
I don't really see any big benefits of "new option" over "new separate function", so I am posting this mostly to make sure we explored a larger design space before committing to a new API. This would be very close to option (1) from @hassec's original post, except the "key" object would be generated by the notify-library instead of by the caller. But, I guess with key objects generated by the library the "awkward state handling" (mentioned in the 2nd post) would no longer be an issue |
OK so I've got a branch with this feature. I've gone with the
Fear no more @zbirenbaum, went with the same use case for an example of the functionality. Not the cleanest in the world but it works 😁 local client_notifs = {}
local spinner_frames = { "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" }
local function update_spinner(client_id, token)
local notif_data = client_notifs[client_id][token]
if notif_data and notif_data.spinner then
local new_spinner = (notif_data.spinner + 1) % #spinner_frames
local new_notif = vim.notify(
nil,
nil,
{ hide_from_history = true, icon = spinner_frames[new_spinner], replace = notif_data.notification }
)
client_notifs[client_id][token] = {
notification = new_notif,
spinner = new_spinner,
}
vim.defer_fn(function()
update_spinner(client_id, token)
end, 100)
end
end
local function format_title(title, client)
return client.name .. (#title > 0 and ": " .. title or "")
end
local function format_message(message, percentage)
return (percentage and percentage .. "%\t" or "") .. (message or "")
end
vim.lsp.handlers["$/progress"] = function(_, result, ctx)
local client_id = ctx.client_id
local val = result.value
if val.kind then
if not client_notifs[client_id] then
client_notifs[client_id] = {}
end
local notif_data = client_notifs[client_id][result.token]
if val.kind == "begin" then
local message = format_message(val.message, val.percentage)
local notification = vim.notify(message, "info", {
title = format_title(val.title, vim.lsp.get_client_by_id(client_id)),
icon = spinner_frames[1],
timeout = false,
hide_from_history,
})
client_notifs[client_id][result.token] = {
notification = notification,
spinner = 1,
}
update_spinner(client_id, result.token)
elseif val.kind == "report" and notif_data then
local new_notif = vim.notify(
format_message(val.message, val.percentage),
"info",
{ replace = notif_data.notification, hide_from_history = false }
)
client_notifs[client_id][result.token] = {
notification = new_notif,
spinner = notif_data.spinner,
}
elseif val.kind == "end" and notif_data then
local new_notif = vim.notify(
val.message and format_message(val.message) or "Complete",
"info",
{ icon = "", replace = notif_data.notification, timeout = 3000 }
)
client_notifs[client_id][result.token] = {
notification = new_notif,
}
end
end
end |
Awesome!! Can't wait to test it out. Thanks so much for the features |
I have been using your exact example snippet for a couple of days now. |
It's a little noisy for me, never realised how many status updates Pyright and lua language server give 😅 For anyone using it currently, I've changed |
For |
BREAKING CHANGE: Async return value now nests events under `events` key. Adds the ability to replace existing notifications and omit notifications from the history. See #43
OK this has now been merged, feel free to show any use cases below that could be added to the wiki 😁 |
Use the lsp notify function from rcarriga/nvim-notify#43 to render lsp progress
Here is a snippet to display progress notifications from DAP. For loading a medium-sized binary in Screen.Recording.2022-03-14.at.00.41.11.movGiven that I also modified the LSP snippet to reuse some of the functionality, I also included my (slightly modified) version of LSP progress reporting
|
A possible use case I was thinking about is using a notification popup to show the status of the LSP startup progress.
E.g at first "LSP Started" and then it would update to show the progress of the background indexing.
I'm not sure if something like that would already be possible?
I could think about two possible interfaces:
notify()
return a function that can be called to update the notification and reset timeoutWDYT, @rcarriga, does any of the above sound reasonable to you?
The text was updated successfully, but these errors were encountered: