m4xshen / hardtime.nvim

Establish good command workflow and quit bad habit
MIT License
1.35k stars 27 forks source link

feat: Add callback function to notifications #101

Closed tris203 closed 2 weeks ago

tris203 commented 2 months ago

This commit introduces a new callback function to the notification system. This function can be used to trigger custom events on a notification. It receives a config object and the notification text as parameters. The callback function is optional and is added to the config object in config.lua. The notify function in util.lua has been updated to call the callback function if it is provided.

This would be one way to handle a request we had in https://github.com/tris203/precognition.nvim/issues/62

But open to your ideas about implementation.

Draft as this is just a talking point for now

tris203 commented 2 months ago

I am completely open to the implementation, perhaps it should overwrite the notify function completely rather than just be additional.

It depends what you would like to consider

tris203 commented 3 weeks ago

@m4xshen did you have any thoughts on this?

m4xshen commented 2 weeks ago

Hi @tris203, sorry for the late reply.

I am completely open to the implementation, perhaps it should overwrite the notify function completely rather than just be additional.

Could you please provide an example of how precognition.nvim will use this option to achieve integration under both implementation?

It's hard to say which one is better. It would be nice to have some example code.

tris203 commented 2 weeks ago

Thanks for the reply @m4xshen. Dont worry about the speed, we are all busy!

It's hard to say which one is better. It would be nice to have some example code.

In the current implementation you can pass something like this in setup:

  {
    'm4xshen/hardtime.nvim',
    dependencies = { 'tris203/precognition.nvim' },
    opts = {
      callback = function(config, text)
        require('precognition').peek()
      end,
    },
  },

This will toggle the precognition hints every time that you get a notification from hardtime.

If we were to overwrite the function entirely, then it would be very similar, except that you would also be required to recreate the notification as well as the additional actions

m4xshen commented 2 weeks ago

Got it. I prefer to overwrite the function entirely and the default value of callback should be util.notify.

tris203 commented 2 weeks ago

Have made changes and rebased @m4xshen

m4xshen commented 2 weeks ago

@tris203 Thanks for the PR! You can now use this option to integrate with precognition.nvim!

btw I'm looking forward to the inlay hint feature, is this available now?

tris203 commented 2 weeks ago

@tris203 Thanks for the PR! You can now use this option to integrate with precognition.nvim!

btw I'm looking forward to the inlay hint feature, is this available now?

Thanks @m4xshen Yeah inlay hints are merged as of a few weeks ago!