nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.84k stars 835 forks source link

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

Closed dlvhdr closed 1 year ago

dlvhdr commented 1 year ago

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.

Conni2461 commented 1 year ago

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 commented 1 year ago

Someone called my name? :laughing:

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 commented 1 year ago

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:

https://user-images.githubusercontent.com/6196971/199321569-f1224e9b-fad4-4863-8d6a-fd0f1c9d9d17.mov

weeman1337 commented 1 year ago

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

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

dlvhdr commented 1 year ago

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

zyriab commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

zyriab commented 1 year ago

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 commented 1 year ago

https://github.com/dlvhdr/dotfiles/commit/f8bcfeaf5361d123ea61cb305c8086deac43f552