sassanh / qnvim

Neovim backend for Qt Creator
MIT License
134 stars 8 forks source link

Search highlighting #26

Open Shatur opened 4 years ago

Shatur commented 4 years ago

I noticed that plugin does not highlight searched items. Highlighting is also not works with such plugins as sandwich (It should show the word to which the modification will be applied.)

Is it possible to somehow access to neovim highlighting?

sassanh commented 4 years ago

Take a look at these:

:help ui-hlstate

https://github.com/neovim/neovim/pull/10504/files#diff-daa9e2681b8e40ea216038de23283f09R319

https://github.com/neovim/neovim/issues/9421#issuecomment-477773593

Then you need some trial and error.

In case you end up using searchpos I suggest injecting a piece of vimscript into neovim on initialization which defines a function that does this repetitive call of searchpos internally and returns the result, you may also want to limit it to 1000 results (so that in case there are 1,000,000 search results for example, the return value of the function isn't huge and also it doesn't take forever to respond) then you should be able to get all search highlight positions in a single msgpack function call.

There's also searchpairpos for highlighting pairs like if and fi or { and }.

But both of these just return the position the highlight starts and don't tell anything about where it ends which makes it hard for when user has search a regular expression. Also both of these change cursor position so you need to store it first. I think ui-hlstate is better because it doesn't have these restrictions and it works with all highlights and not just search and pair results, but it's a bit harder to implement.

Shatur commented 4 years ago

Will take a look, thank you!