telescope-live-grep-args.nvim icon indicating copy to clipboard operation
telescope-live-grep-args.nvim copied to clipboard

Use `rg --json` for highlighting the matches

Open weeman1337 opened this issue 2 years ago • 6 comments

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 https://github.com/nvim-telescope/telescope.nvim/pull/1448

weeman1337 avatar Nov 16 '21 18:11 weeman1337

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... https://github.com/nvim-telescope/telescope.nvim/pull/670#issuecomment-975341210

jesseleite avatar Nov 22 '21 14:11 jesseleite

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: https://github.com/neovim/neovim/pull/14871

TC72 avatar Nov 22 '21 14:11 TC72

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.

Conni2461 avatar Nov 22 '21 17:11 Conni2461

@Conni2461 thanks for explaining.

TC72 avatar Nov 22 '21 17:11 TC72

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

jugarpeupv avatar May 01 '22 08:05 jugarpeupv

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

Hi @jugarpeupv . It has not yet been implemented.

weeman1337 avatar May 01 '22 10:05 weeman1337