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

invert live_grep #2191

Closed
l-bowman opened this issue Oct 6, 2022 · 15 comments · Fixed by #2208
Closed

invert live_grep #2191

l-bowman opened this issue Oct 6, 2022 · 15 comments · Fixed by #2208
Assignees
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@l-bowman
Copy link

l-bowman commented Oct 6, 2022

Is your feature request related to a problem? Please describe.
I often want to generate a list of all files which do not contain String A. Grep has a -v option to accomplish this. I think this would be a great feature for Telescope.

Describe the solution you'd like
A simple way to perform a live invert grep.

Describe alternatives you've considered
I looked over the docs. I do not see an option for invert grep. I'm also unaware of extensions which offer this.

@l-bowman l-bowman added the enhancement Enhancement to performance, inner workings or existent features label Oct 6, 2022
@Conni2461
Copy link
Member

you can pass additional args to both live_grep and grep_string, but it seems like that -v changes the formatting of the rg output, so it no longer works with our parser. I'll fix that bug and then update how you can pass in that argument.

Will be done by this evening

@Conni2461 Conni2461 self-assigned this Oct 24, 2022
@l-bowman
Copy link
Author

you can pass additional args to both live_grep and grep_string, but it seems like that -v changes the formatting of the rg output, so it no longer works with our parser. I'll fix that bug and then update how you can pass in that argument.

Will be done by this evening

That's fantastic! Thank you!

@l-bowman
Copy link
Author

l-bowman commented Oct 24, 2022

you can pass additional args to both live_grep and grep_string, but it seems like that -v changes the formatting of the rg output, so it no longer works with our parser. I'll fix that bug and then update how you can pass in that argument.

Will be done by this evening

Here is the current behavior I am seeing with the following command:
:lua require('telescope.builtin').live_grep({additional_args = {'-lv'}})

image

I would like to see the names of the files here instead of "nil:nil:nil".

@Conni2461
Copy link
Member

Conni2461 commented Oct 24, 2022

thanks for confirming that its actually broken. i was 90% sure it wouldn't work out of the box.

#2208 should fix parsing for
:lua require('telescope.builtin').live_grep({additional_args = {'-lv'}}) and :lua require('telescope.builtin').live_grep({additional_args = {'-v'}})

Would be awesome if you could test it. after that i would merge the PR. (Probably tomorrow, its already 10:30pm for me)

@l-bowman
Copy link
Author

l-bowman commented Oct 24, 2022

thanks for confirming that its actually broken. i was 90% sure it wouldn't work out of the box.

#2208 should fix parsing for :lua require('telescope.builtin').live_grep({additional_args = {'-lv'}}) and :lua require('telescope.builtin').live_grep({additional_args = {'-v'}})

Would be awesome if you could test it. after that i would merge the PR. (Probably tomorrow, its already 10:30pm for me)

Cool! Happy to test. I tried to install your branch as a plugin, but Packer couldn't install it. What am I doing wrong? I tried:

-- Telescope
  use({
    "Conni2461/telescope.nvim/tree/fix/rg_invert_matches_arg_parsing",
    requires = { { "nvim-lua/popup.nvim" }, { "nvim-lua/plenary.nvim" } },
  })

Also tried using: nvim-telescope/telescope.nvim/pull/2208

@Conni2461
Copy link
Member

i think it should be

  use({
    "Conni2461/telescope.nvim", branch = "fix/rg_invert_matches_arg_parsing",
    requires = { { "nvim-lua/plenary.nvim" } },
  })

@l-bowman
Copy link
Author

    "Conni2461/telescope.nvim", branch = "fix/rg_invert_matches_arg_parsing",

I tried your branch. It is now showing files in the preview, but the filtering does not appear to be functioning properly. For example, my file whichkey-settings.lua contains the string 'Telescope'. This file continues to appear in the list after I type the string.

@Conni2461
Copy link
Member

okay we aren't applying the filter, rg gives us the results!? What happens if you do the exact same query in your terminal?

rg -lv Telescope (just my assumption)

@l-bowman
Copy link
Author

l-bowman commented Oct 25, 2022

okay we aren't applying the filter, rg gives us the results!? What happens if you do the exact same query in your terminal?

rg -lv Telescope (just my assumption)

Hmm, this doesn't seem to work in the terminal either. I am still seeing whichkey-settings.lua returned, but it should be excluded for containing the search string. Any idea what is going on?

@Conni2461
Copy link
Member

BurntSushi/ripgrep#138

this means i had to update the PR, just run PackerSync, after that lua require('telescope.builtin').live_grep({additional_args = {'--files-without-match'}}) should give you the expected behavior

@l-bowman
Copy link
Author

l-bowman commented Oct 25, 2022

BurntSushi/ripgrep#138

this means i had to update the PR, just run PackerSync, after that lua require('telescope.builtin').live_grep({additional_args = {'--files-without-match'}}) should give you the expected behavior

The file appears to be correctly excluded now, but the display is strange: 40 / 42 / 42.
image

@Conni2461
Copy link
Member

Conni2461 commented Oct 25, 2022

Thats a problem of live grep in general and not of that issue.

Items selected / Items filtered / Items in list

The last two filtered and in list, are the same because live_grep isn't filtering, because it always gets data directly from rg after each prompt change.

I'll fix this in a different PR and will merge #2208 Ill open a new issue for strange display.

Thanks for testing :)

@Conni2461
Copy link
Member

#2210 is the new issue for the displaying issue

@l-bowman
Copy link
Author

Thanks! @Conni2461

@brookhong
Copy link

I just implemented such feature in my telescope extension, please see the showcase on Youtube.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants