zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
530 stars 42 forks source link

Zk Grep #171

Open shfattig opened 4 months ago

shfattig commented 4 months ago

Use Telescope's "jobs" to perform live asynchronous calls to zk list -m to provide grep-like searching of note bodies

shfattig commented 4 months ago

To test, run :ZkGrep

shfattig commented 4 months ago

closes #127

shfattig commented 4 months ago

A few things to clean up, but should be functional right now. Additionally, as mentioned in #127 , zk list -m does not provide line numbers of matches, but doing so would greatly enhance the match preview as well as the opening of the file. Also, zk list -m seems to behave differently from zk list -i, matching less frequently and omitting expected matches for some reason

edit: compare to zk list -i (although zk edit -i seems to give model behavior as well)

tjex commented 4 months ago

Tested by replacing the hard coded notebook root with my own directory. I can execute the command and grep :) Great!

I'm going to have a look at how telescope grepper does the highlighting for the returned grep result in the previewer and see how trivial it is to implement. Thanks for this pr! 🙌

tjex commented 4 months ago

A few things to clean up, but should be functional right now. Additionally, as mentioned in #127 , zk list -m does not provide line numbers of matches, but doing so would greatly enhance the match preview as well as the opening of the file. Also, zk list -m seems to behave differently from zk list -i, matching less frequently and omitting expected matches for some reason

edit: compare to zk list -i (although zk edit -i seems to give model behavior as well)

It would seem that zk list -i only searches through note titles? This is why it's returning less results than zk list -m <term>.

Jumping to the line number would be great. I guess we can also look to the Telescope grep implementation (as well as highlighting) here as well.

shfattig commented 4 months ago

Tested by replacing the hard coded notebook root with my own directory. I can execute the command and grep :) Great!

I'm going to have a look at how telescope grepper does the highlighting for the returned grep result in the previewer and see how trivial it is to implement. Thanks for this pr! 🙌

You're welcome! Yeah it should be fairly trivial as long as we can get match line numbers. I'll work on some of the cleanup (like removing that hard coded path) and attempt a call to the lua api instead

github-actions[bot] commented 3 months ago

This pull request has been automatically marked as stale because it has not had recent activity.

lingling9000 commented 3 months ago

Any updates on this feature? I would love to have this!

shfattig commented 2 months ago

Any updates on this feature? I would love to have this!

Haha thanks for the poke. I'm looking at using the zk lua api instead of an external shell command for the grepping. It doesn't look like Telescope has an existing finder for this, so I'll have to figure out how to get there.

I did find that changing the matching strategy to "re" (regex) does give better results (rather than waiting until the end of a word). It also gives more intuitive usage haha, given that this is a grep feature after all...) - what do you think?

shfattig commented 2 months ago

Other than that, maybe we should outline what the minimum requirements are to get this merged in. I might argue that it's functional as is and ready for public release, as long as code style is fine and docs are updated appropriately (I can go do that, but you might have to help me find the right places)

shfattig commented 2 months ago

@tjex can you get us line numbers on zk list -m?

tjex commented 2 months ago

I have a bit too much to tackle at the moment both here with zk (mainly new docs site, another active PR and some aging bugs) and my study / job hunting commitments to be able to deliver something like that in any respectable amount of time :(

I would personally be fine with merging without the jump-to-line feature. You could also leave a comment where that step should be implemented, so that it can be addressed later. Better to have the cake, even if the cherry on top is missing for the moment imo.

Another approach could be to grab the user input search query, and after entering the file, executing a regular buffer neovim search, using the user input as the search term?

tjex commented 2 months ago

@shfattig Maybe there is something to take from this discussion on zk-org/zk.

https://github.com/zk-org/zk/discussions/330

This person was also looking to integrate jump to line from grep / fzf. Perhaps it works for your contribution as well.

shfattig commented 1 month ago

@shfattig Maybe there is something to take from this discussion on zk-org/zk.

https://github.com/zk-org/zk/discussions/330

This person was also looking to integrate jump to line from grep / fzf. Perhaps it works for your contribution as well.

Yeah, interesting. I can explore that more. I still think this feature is worth merging as is, and getting it in front of people might help to refine the behavior we're looking for. I'll be able to take some time for this in a couple weeks

tjex commented 1 month ago

I'm having a little look at it too, cleaned up a few things just now. Non-telescope users will get a nasty error when running this too. Should be addressed, as the command for the other pickers is not going to come around too quickly..