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

Ability to quickly include/exclude certain directories when doing live_grep #2215

Closed
dlvhdr opened this issue Oct 30, 2022 · 10 comments
Closed
Labels
enhancement Enhancement to performance, inner workings or existent features

Comments

@dlvhdr
Copy link

dlvhdr commented Oct 30, 2022

Is your feature request related to a problem? Please describe.
This is a feature I keep finding myself missing from VSCode.
Basically, when doing a live_grep, I would like to be presented with 2 additional input boxes for including or excluding directories.

image

Describe the solution you'd like
image

I guess this could be done by writing some custom lua code to ask the user for 2 inputs and then opening telescope but I think this has the disadvantage of being disconnected from the telescope UI.
This solution allows me to easily see and edit, in the context of my search, which dirs are being searched in.
This solution, should allow moving between the 3 input boxes with some kind of keybinding, like Tab.

The solution can pass the arguments to rg directly.

Note: this can also be done with one additional input box, where exclusions begin with !

Describe alternatives you've considered
Using something like #2201, which addresses some use cases, but not all, and also not as convenient as what I'm suggesting.

Additional context
I usually use this to exclude tests files on the fly, include only a certain package in a monorepo, exclude yarn.lock etc.

@dlvhdr dlvhdr added the enhancement Enhancement to performance, inner workings or existent features label Oct 30, 2022
@Conni2461
Copy link
Member

uff, i am not sure we want additional floating windows, this could make the ui extremely cluttered. Also tab is already mapped. Another thing that might make this really hard to implement is different telescope layouts/themes, or preview toggling ... anything that changes the frontend windows positions ...

We might wanna ping https://github.com/nvim-telescope/telescope-live-grep-args.nvim maintainer @weeman1337

My proposal would be to do this all in one prompt. Like introduce a new syntax to include and exclude directory, similar to what fzf has with ! to exclude. We could then reorder things and stuff, to make it work better, but this might also get in the way.

With live-grep-args you can also just write rg options at the beginning of the prompt, maybe that helps you more.

Idk its a though issue

@weeman1337
Copy link

Someone called my name? 😆

I can just talk for „live grep args“ and that it allows @dlvhdr to do exactly what he wants. You can easily pass the glob option there. I wouldn't hide it behind some crazy / magic prompt parsing and just pass the args: keep things simple.

The documentation already contains an example about how to set up a key mapping to quote + add the iglob to the prompt.

@dlvhdr
Copy link
Author

dlvhdr commented Nov 1, 2022

My proposal would be to do this all in one prompt. Like introduce a new syntax to include and exclude directory, similar to what fzf has with ! to exclude. We could then reorder things and stuff, to make it work better, but this might also get in the way.

This works for me :)
I can see myself using it easily.
A search prompt like require +lua !test would search for the word require in all paths containing lua and exclude results in paths that contain test?
What's the syntax you're thinking of? I don't really work with rg a lot so not sure what's the standard.


@weeman1337 thanks for stopping by!
I love your extension and do use it.
I've set up everything to work, but I'm not getting the behavior I'm after.
Maybe I've set something wrong? Here are my dotfiles: https://github.com/dlvhdr/dotfiles/blob/9448bd07b4e3f0d9095ca3e9ee43c65b447b1d81/.config/nvim/lua/dlvhdr/telescope.lua#L32

When I search for dlvhdr I don't get results under any path containing dlvhdr, I have to type the full prefix for it to work: e.g. lua/dlvhdr. That is very cumbersome when you're working in a monorepo with packages named src/packages/some-long-package-name.
See the video:

Screen.Recording.2022-11-01.at.21.28.12.mov

@weeman1337
Copy link

Here are some examples (using matrix-react-sdk:

  • Grep client in all files under src, ignore tsx files: "client" --iglob src/** --iglob !*.tsx
  • Grep client in all files under src, ignore components: "client" --iglob src/** --iglob !**/components/**
  • Grep client in all files under any components directory: "client" --iglob **/components/**

All that can be supported by shortcut commands, like mentioned in the doc.

@dlvhdr
Copy link
Author

dlvhdr commented Nov 18, 2022

Thanks, this appears to work great. 💖
I will use it for some time and if I find it cumbersome, I might reopen the issue.

@dlvhdr dlvhdr closed this as completed Nov 18, 2022
@zyriab
Copy link

zyriab commented Sep 13, 2023

Sorry to post almost one year later but I was super confused as to how I could make this work so here it is for the next lost soul, a minimal config to get you started on the right path:
(using Lazy-nvim)

-- lazy-nvim.lua
 {
        "nvim-telescope/telescope.nvim",
        tag = "0.1.2",
        dependencies = {
            "nvim-telescope/telescope-live-grep-args.nvim",
            -- your other deps     
        },
        config = function()
    	require("telescope").load_extension("live_grep_args")
  	end
    },
-- telescope.lua
local telescope = require("telescope")
local lga_actions = require("telescope-live-grep-args.actions")

-- ... rest of your config

-- Whatever keymap you want
vim.keymap.set("n", "<leader>lg", function()
    telescope.extensions.live_grep_args.live_grep_args()
end)

@jamestrew
Copy link
Contributor

@ZyriabDsgn technically it should be closer to this

{
  "nvim-telescope/telescope.nvim",
    tag = "0.1.3", -- latest tag
    dependencies = {
      "nvim-lua/plenary.nvim", -- telescope dependency
      "nvim-telescope/telescope-live-grep-args.nvim",
      -- your other deps     
    },
    config = function()
      require("telescope").setup() -- setup
      require("telescope").load_extension("live_grep_args")
    end
},

@dlvhdr
Copy link
Author

dlvhdr commented Sep 13, 2023

I actually discovered you can do refine_search which is better. Check out my dotfiles

@zyriab
Copy link

zyriab commented Sep 14, 2023

Thanks guys.
@dlvhdr I took a look, some nice configs down there :)
As for the refine_search I didn't find it but I'll look around some more, thanks!

@dlvhdr
Copy link
Author

dlvhdr commented Sep 14, 2023

dlvhdr/dotfiles@f8bcfea

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

No branches or pull requests

5 participants