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

Passing additional arguments on Windows #3350

Open
efeklisov opened this issue Oct 31, 2024 · 0 comments
Open

Passing additional arguments on Windows #3350

efeklisov opened this issue Oct 31, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@efeklisov
Copy link

Description

Hello! today I've tried to add some additional arguments to live_grep on Windows. However, I ran into the problem that this some arguments ripgrep just refused to work and provided empty output.

So, what I originally tried to do is this:

exts_shader_code = "--type-add shader:*.{hlsl,azsl,glsl,comp,rchit,rcmiss,rgen,hlsli,azsli,h,shader,pass} -tshader"
exts_cpu = "-tc -tcpp"

require('telescope.builtin').live_grep({
    additional_args = {
      "--no-ignore",
      exts_shader_code,
      exts_cpu,
    },
})

However, this leads to unexpected behavior above. The trick is to do it like this:

exts_shader_code = {"--type-add", "shader:*.{hlsl,azsl,glsl,comp,rchit,rcmiss,rgen,hlsli,azsli,h,shader,pass}", "-tshader"}
exts_cpu = {"-tc", "-tcpp"}

require('telescope.builtin').live_grep({
    additional_args = {
      "--no-ignore",
      exts_shader_code,
      exts_cpu,
    },
})

Now it works, because nvim.uv (nvim.loop) automatically puts the arguments to ripgrep in double quotes on Windows ONLY and if you have several arguments in one string it quotes the entire string and the args become invalid.

To be honest, this is extremely counterintuitive behavior that's OS specific. You can remedy this by setting options.verbatim of uv.spawn to true (in lua/telescope/_.lua. The file is probably generated, I didn't check the repo ). Alternatively, you can specifically explain this behavior in the docs to Telescope and make it more apparent (if it already is explained, I've missed it and it drives my point home IMHO).

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

Windows 11

Telescope version / branch / rev

df534c3 fix(git_status): correctly count result on_complete (#3321) (3 weeks ago)

checkhealth telescope

==============================================================================
telescope: health#telescope#check

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

Checking external dependencies ~
- OK rg: found ripgrep 14.1.1 (rev 4649aa9700)
- WARNING fd: not found. Install [sharkdp/fd](https://github.com/sharkdp/fd) for extended capabilities

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

Telescope Extension: `ag` ~
- No healthcheck provided

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Steps to reproduce

  1. Be on windows
  2. Install NeoVim and ripgrep (from scoop)
  3. Install telescope
  4. Configure live_grep as shown above
  5. Run live_grep

Expected behavior

ripgrep returns expected results or tells you which arguments are incorrect.

Actual behavior

ripgrep shows empty output.

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()
      -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      require("telescope").setup {}
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

exts_shader_code = "--type-add shader:*.{hlsl,azsl,glsl,comp,rchit,rcmiss,rgen,hlsli,azsli,h,shader,pass} -tshader"
exts_cpu = "-tc -tcpp"

vim.keymap.set('n', '<F5>', 

(function()
require('telescope.builtin').live_grep({
    additional_args = {
      "--no-ignore",
      exts_shader_code,
      exts_cpu,
    },
})
end)

)
@efeklisov efeklisov added the bug Something isn't working label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant