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

Unsure how to search with wildcard paths

Open comatory opened this issue 1 year ago • 4 comments

Description

I'm used to using ag with searching like this `ag "some.*regex" path/**/some-subfolder. When I trigger the search window and type:

"some.*regex" path/**/some-subfolder

I don't get any results. I checked the query with ag on command line and I get results. This is how my telescope is set up:

{
  "nvim-telescope/telescope.nvim",
   dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-telescope/telescope-live-grep-args.nvim",
   },
   config = function()
     local builtin = require("telescope.builtin")
     vim.keymap.set("n", "<C-p>", builtin.find_files, {})
     vim.keymap.set("n", "<C-l>", builtin.live_grep, {})

    local telescope = require("telescope")

    local opts = {}

    -- replace ripgrep with ag
    -- https://github.com/nvim-telescope/telescope.nvim/issues/2083
    local ag = os.execute("command -v " .. "ag")
    if ag == 0 then
      opts.defaults = {
        vimgrep_arguments = {
          "ag",
          "--nocolor",
          "--noheading",
          "--numbers",
          "--column",
          "--smart-case",
          "--silent",
          "--vimgrep",
        }
      }
    end

    -- extension for grepping with arguments
    vim.keymap.set("n", "<C-k>", ":lua require('telescope').extensions.live_grep_args.live_grep_args()<CR>")
    telescope.load_extension("live_grep_args")

    telescope.setup(opts)
   end
}

In order to get results I have to specifically narrow down the path with specific subdirectories. Perhaps I'm not really searching with ag? I'm not sure how I could find out.

I use lazy.nvim as my package manager.

Thanks for any suggestions.

Neovim version

NVIM v0.10.0-dev-785+gbad71a4ca-Homebrew
Build type: Release
LuaJIT 2.1.1696795921
Run "nvim -V1 -v" for more info

Operating system and version

macOS 14.3.1

Telescope version / branch / rev

e9e01d699843af530ef4ad2c8679a7e273bb3dd1

Telescope live grep args version / branch / rev

731a046da7dd3adff9de871a42f9b7fb85f60f47

checkhealth telescope

telescope: health#telescope#check

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.6.0

===== Installed extensions ===== ~

Steps to reproduce

  1. Use options mentioned above
  2. Open nvim, press <C-k>
  3. Type "<your regex here>" <path>/**/<subdirectory>

Expected behavior

Get the same list of files as if launching it with command-line: ag "<your regex here>" <path>/**/<subdirectory>

Actual behavior

No files present

Minimal config

-- init.lua

-- PACKAGE MANAGER
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup("plugins")

-- lua/plugins/telescope.lua

-- fuzzy file search / content search with UI
return {
  "nvim-telescope/telescope.nvim",
   dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-telescope/telescope-live-grep-args.nvim",
   },
   config = function()
     local builtin = require("telescope.builtin")
     vim.keymap.set("n", "<C-p>", builtin.find_files, {})
     vim.keymap.set("n", "<C-l>", builtin.live_grep, {})

    local telescope = require("telescope")

    local opts = {}

    -- replace ripgrep with ag
    -- https://github.com/nvim-telescope/telescope.nvim/issues/2083
    local ag = os.execute("command -v " .. "ag")
    if ag == 0 then
      opts.defaults = {
        vimgrep_arguments = {
          "ag",
          "--nocolor",
          "--noheading",
          "--numbers",
          "--column",
          "--smart-case",
          "--silent",
          "--vimgrep",
        }
      }
    end

    -- extension for grepping with arguments
    vim.keymap.set("n", "<C-k>", ":lua require('telescope').extensions.live_grep_args.live_grep_args()<CR>")
    telescope.load_extension("live_grep_args")

    telescope.setup(opts)
   end
}

comatory avatar Mar 17 '24 12:03 comatory

The difference between CLI ag something **/somewhere/** and Telescope Live Grep "something" **/somewhere/** is that in the first case your shell expands the path (see „globbing“). When Telescope invokes the command the args are passed directly to the command. Means there is no globbing.

Long story short, you should use "something" -G .*/somewhere/.* (or see other options from man ag).

Does that work for you @comatory ?

weeman1337 avatar Jun 09 '24 08:06 weeman1337

Long story short, you should use "something" -G ./somewhere/.

Did you mean type it like this into telescope? Because that did not work for me. Can I check somehow that telescope is indeed using ag in runtime?

comatory avatar Jun 12 '24 20:06 comatory

Did you mean type it like this into telescope?

Into the prompt field, when the live grepper is open. E.g. with ripgrep --iglob as a similar option

image

Can I check somehow that telescope is indeed using ag in runtime?

Yes, you can check your vimgrep command with :lua print(vim.o.grepprg)

weeman1337 avatar Jul 28 '24 08:07 weeman1337

@weeman1337

As soon as I add --iglob flag, I get :nil in the result list:

Screenshot 2024-07-29 at 13 54 35

Yes, you can check your vimgrep command with :lua print(vim.o.grepprg)

Ok running it gave me this:

rg --vimgrep -uu

Does not look like ag binary :(

I have this set up inside of config function for telescipe:

      -- replace ripgrep with ag
      -- https://github.com/nvim-telescope/telescope.nvim/issues/2083
      local ag = os.execute("command -v " .. "ag")
      if ag == 0 then
        opts.defaults.vimgrep_arguments = {
          "ag",
          "--nocolor",
          "--noheading",
          "--numbers",
          "--column",
          "--smart-case",
          "--silent",
          "--vimgrep",
        }
      end

I definitely have ag on my system. Am I doing something wrong?

comatory avatar Jul 29 '24 11:07 comatory