-
-
Notifications
You must be signed in to change notification settings - Fork 626
feat: Add ability to customize notification handler #2117
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: Add ability to customize notification handler #2117
Conversation
6d50020
to
0111af0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ok both commits:
- default handler
rcarriga/nvim-notify
notify.handler
:
local function h(msg, level, opts)
print(vim.inspect(msg))
print(vim.inspect(level))
print(vim.inspect(opts))
end
Please:
- Update help
- Remove camel case and rename
- Revert DEFAULT_OPTS pending @gegoune
`msg`: notification message | ||
`level`: notification level (see `vim.log.levels` for possible values) | ||
`opts`: table with additional parameters (e.g. `title`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
*nvim-tree.notify.handler*
Change the default notification handler, can be a string `"default"` or a function.
The default handler will check if the nvim-notify plugin is present on the
runtime path and use it, otherwise it will fallback to use |vim.notify()|
Type: `string` | `function`, Default: `"default"`
Parameters: ~
• {msg} (string) See |vim.notify()|
• {level} (number) See |vim.notify()|
• {opts} (table) Optional parameters
Options: ~
• {title} (string) Usually `"NvimTree"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking for nvim-notify at all? Wasn't idea behind vim.notify such that it handles notifications send to it per users' handler, if it happens to be nvim-notify so be it.
Not near my computer so can't check much easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see! We set handler directly to vim.notify.
Much cleaner. Just have to ensure that the arguments line up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking for nvim-notify at all? Wasn't idea behind vim.notify such that it handles notifications send to it per users' handler, if it happens to be nvim-notify so be it.
Yes, that's correct. I did it like that only to preserve the previous behavior, but I would happy to simplify it. Is there any issue/way of notifying users of such change?
Much cleaner. Just have to ensure that the arguments line up.
They do :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working:
handler = require("notify").notify,
and
handler = vim.notify,
the latter case does not prepend the title, however that's expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. I did it like that only to preserve the previous behavior, but I would happy to simplify it. Is there any issue/way of notifying users of such change?
If we were building this today, the user would need to specify handler = require("notify").notify
however the existing auto-detection behaviour exists and I don't like to break behaviour.
How about:
notify.handler
is nil or "default" ANDrequire("notify")
successful
"nvim-notify plugin detected: please set notify.handler = require("notify").notify. See :help nvim-tree.notify"
Options:
- Preserve existing behaviour, defaulting to nvim-notify
- Remove nvim-notify fallback, requiring the user to explicitly set
notify.handler
Your call @gegoune :)
88695df
to
a5aedaa
Compare
Waiting for the confirmation regarding auto detection of nvim-notify |
`msg`: notification message | ||
`level`: notification level (see `vim.log.levels` for possible values) | ||
`opts`: table with additional parameters (e.g. `title`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. I did it like that only to preserve the previous behavior, but I would happy to simplify it. Is there any issue/way of notifying users of such change?
If we were building this today, the user would need to specify handler = require("notify").notify
however the existing auto-detection behaviour exists and I don't like to break behaviour.
How about:
notify.handler
is nil or "default" ANDrequire("notify")
successful
"nvim-notify plugin detected: please set notify.handler = require("notify").notify. See :help nvim-tree.notify"
Options:
- Preserve existing behaviour, defaulting to nvim-notify
- Remove nvim-notify fallback, requiring the user to explicitly set
notify.handler
Your call @gegoune :)
I am all in for breaking changes if justified, they are not as disruptive as people might think if done properly. Why are we even checking for nvim-notify? So we can call it with some other parameters/if it't not present to prefix message ourselves? If messages sent change then it barely is a breaking change at all. Am I missing on how that is a breaking change? I am all in to setting default handler to (Is |
a5aedaa
to
c5c09eb
Compare
The breaking change I had in mind was regarding the auto-detection of nvim-notify. (Personally I think that the auto-detection feature should be removed) |
I agree with the removal. If someone is doing something like that we can very easily assume they know what they are doing and will be able to adapt. |
How about:
|
I am not sure about that bit. We should just send stuff to |
Very much indeed! Because of the small changes in the direction that we did during that PR it was not obvious to spot it, but I think that you are right. Now, once the auto-detection of nvim-notify was removed, we can just simply sent everything to |
Ok, good to know I wasn't imagining things. With that change we wouldn't need a custom handler any more. Would you like to amend that, or create new, PR with those changes? |
I will create a new PR to keep the things clear and refer to this one. |
add
notify.handler
to setup optsrefers to #1697