rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
2.97k stars 78 forks source link

Cancel or Disable notifications for specific source or specific message #164

Open RichestHumanAlive opened 1 year ago

RichestHumanAlive commented 1 year ago

Would it be possible to have a feature to filter or disable notifications from a specific source or based on the notification message?

rcarriga commented 1 year ago

Duplicate of #114, see the solution here https://github.com/rcarriga/nvim-notify/issues/114#issuecomment-1179754969

RichestHumanAlive commented 1 year ago

@rcarriga Thanks ! It work's perfectly 💯

chrisgrieser commented 1 year ago

I came here for the same problem, but I am looking to specifically block notifications from a specific sender. The solution at #114 can only filter messages based on the the content, if I am correct?

Or there a way to determine the sender of a message? (if I am not the one creating the message, but a plugin)

RichestHumanAlive commented 1 year ago

@chrisgrieser , I was also expecting first to block notifications from a specific sender but I realized that, according to the API documentation, It wasn't explicitly intended to work like that.

The [vim.notify()](https://neovim.io/doc/user/lua.html#vim.notify()) function can be replaced by plugins to display notifications using a custom provider. That's what this nice plugin (nvim-notify) does.

The important fact for our issue is that, it seems like when any plugin or snippet of code sends a notification, calling the vim.notify() function, vim just forward the message to the UI, according to paramters passed to the vim.notify() function, regardless of the source of this notification.

The only explicit parameters of this functions are {msg} (string representing content of the notification to show to the user) and {level} (number|nil representing one of the values from vim.log.levels).

So, 'vim.notify()' function does not provide any way to explicitly set a source that sends the message as paramter nor any way to retrieve this source, so it is normal that nvim-notify by replacing the vim.notify() behaves similarly with regard to the source.

Considering this, the best we can do is what is described here #114

You can also take a look here

Hope this help !

chrisgrieser commented 1 year ago

I see. Thanks for the explanation; guess I'll have to resort writing a bunch of lua patterns to filter out the correct messages then 🙈

rcarriga commented 1 year ago

I'll add that though the third options table argument is completely optional and non-standard, many plugins do add a title field so if the source you wish to ignore does that then you can filter by title.

Alternatively if you want to have a bit of fun with it you could use debug.getinfo or debug.traceback to check the call stack for a specific module but that might be a bit overboard :sweat_smile:

RichestHumanAlive commented 1 year ago

yeah but it might be frustrating realizing that some plugins you are using do not provide a title and still be forced to filter messages