nvim-telescope / telescope.nvim

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

Does live_grep work with number instead of string? #3310

Closed zigotica closed 1 month ago

zigotica commented 1 month ago

Description

I am getting an error when trying to grep for number, nit sure if this is expected or not.

Neovim version

NVIM v0.10.0-dev-2593+ga6b6d036b-Homebrew
Build type: Release
LuaJIT 2.1.1725453128

Operating system and version

macOS 15.0

Telescope version / branch / rev

latest master

checkhealth telescope

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

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0
- OK fd: found fd 9.0.0

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

Telescope Extension: `glyph` ~
- No healthcheck provided

Telescope Extension: `ui-select` ~
- No healthcheck provided

Telescope Extension: `undo` ~
- No healthcheck provided

Steps to reproduce

  1. open a project
  2. :Telescope grep_string search=map
  3. This opens a modal with fzf-able files including that string (map)
  4. :Telescope grep_string search=3
  5. Should open a similar modal but throws error seen below

Expected behavior

Opens a modal with fzf-able files including that number (3)

Actual behavior

Error executing Lua callback: ...im/lazy/telescope.nvim/lua/telescope/builtin/files.lua:21: attempt to index local 'string' (a number value) stack traceback: ...im/lazy/telescope.nvim/lua/telescope/builtin/files.lua:21: in function 'escape_chars' ...im/lazy/telescope.nvim/lua/telescope/builtin/files.lua:205: in function 'v' ...im/lazy/telescope.nvim/lua/telescope/builtin/files.lua:644: in function 'v' .../nvim/lazy/telescope.nvim/lua/telescope/builtin/init.lua:587: in function <.../nvim/lazy/telescope.nvim/lua/telescope/builtin/init.lua:546> ...share/nvim/lazy/telescope.nvim/lua/telescope/command.lua:188: in function 'run_command' ...share/nvim/lazy/telescope.nvim/lua/telescope/command.lua:259: in function 'load_command' ...ocal/share/nvim/lazy/telescope.nvim/plugin/telescope.lua:108: in function <...ocal/share/nvim/lazy/telescope.nvim/plugin/telescope.lua:107>

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    config = function()
      require("telescope").setup {}
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
Conni2461 commented 1 month ago

we are parsing the viml command into a lua call, so yeah we are interpreting numbers as strings iirc. If you have that youcase its best you use the lua interface directly

zigotica commented 1 month ago

Hello, thank you for the answer. If I understand correctly, you're suggesting I use the lua method directly, so instead of :Telescope grep_string search=3 I would be using lua require('telescope.builtin').live_grep()? Problem with that, is it is not a direct equivalent, since this opens a modal where I can write the number and returns files containing that number, but I cannot fzf the files (the filter is the actual number being searched). Sorry, maybe there is a documentation page for this specific "issue" but cannot find it.

jamestrew commented 1 month ago

It would be like :lua require('telescope.builtin').grep_string({ search = '3' })

I see mappings like this frequently to prompt for the search term. nnoremap <leader>ps :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ") })<CR>

jamestrew commented 1 month ago

Actually I don't think it hurts to cast the search value into a string.

zigotica commented 1 month ago

Thanx, works perfectly!