Skip to content
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

Use rg --json for highlighting the matches #4

Open
weeman1337 opened this issue Nov 16, 2021 · 6 comments
Open

Use rg --json for highlighting the matches #4

weeman1337 opened this issue Nov 16, 2021 · 6 comments

Comments

@weeman1337
Copy link
Collaborator

weeman1337 commented Nov 16, 2021

rg provides a --json option that returns offsets of the matches. This can be used to highlight the matches.

It should use json_decode or vim.json.decode depending on availablility where vim.json has priority. vim.json is going to be shipped with nvim 0.6.

relates to nvim-telescope/telescope.nvim#1448

@jesseleite
Copy link
Contributor

jesseleite commented Nov 22, 2021

Love it! Too add to that, I feel like it should have no problem highlighting more complex regex searches as well, which --json would absolutely help with.

CleanShot 2021-11-20 at 14 40 08

I'm curious how --json would affect performance though.

Also, @TC72 had done some experimenting with highlighting on my old live_grep_raw PR as well; Posting his thoughts here in case it helps... nvim-telescope/telescope.nvim#670 (comment)

@TC72
Copy link

TC72 commented Nov 22, 2021

I have code which works thanks to @Conni2461 giving me some code to convert ansi codes to highlighting.
But overall the way I implemented it was a mess.

I think we could give --json a try, my only concern is the sheer amount of data we'll get back from it.
As @weeman1337 has already spotted, this patch should improve json parsing:
neovim/neovim#14871

@Conni2461
Copy link
Member

I already said it once but again vim.fn.json_decode was never an option because we are in an fast event. You cant call viml inside a fast event. :help api-fast

Thats why vim.json is such a big deal not because its 2.5 times faster.

@TC72
Copy link

TC72 commented Nov 22, 2021

@Conni2461 thanks for explaining.

@jugarpeupv
Copy link

Hi, sorry but i dont understand how to use --json to highlight the matches (tried passing that in rg args but got nil:nil:nil). Is it possible to highlight matches when additional arguments are passed? Like this
image

@weeman1337
Copy link
Collaborator Author

Hi, sorry but i dont understand how to use --json to highlight the matches

Hi @jugarpeupv . It has not yet been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants