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

Crash when opening folder containing () characters #244

Closed
juanpprieto opened this issue Feb 27, 2023 · 10 comments
Closed

Crash when opening folder containing () characters #244

juanpprieto opened this issue Feb 27, 2023 · 10 comments
Labels
bug Something isn't working

Comments

@juanpprieto
Copy link

Description

When I try to open a folder containing ( or ) I get the following error:

[telescope] ^I...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:484: in function <...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:450>

Neovim version

NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

macOS 13.2.1

Steps to reproduce

  1. Try to open a folder which contains () e.g ($lang). This is a new pattern supported by Remix optional segments file based routing

Expected behavior

Expect to be able to navigate to the folder

Actual behavior

Error

[telescope] ^I...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:484: in function <...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:450>

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          'nvim-telescope/telescope-file-browser.nvim',
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('file_browser')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@juanpprieto juanpprieto added the bug Something isn't working label Feb 27, 2023
@jamestrew
Copy link
Collaborator

jamestrew commented Feb 28, 2023

Hey thanks for reporting this issue.

I am able to reproduce this bug.
I've also noticed that the File Previewer for files with names like ($lang)._index.tsx are broken as well, as in it fails to display the contents of the file. You can experience this with :Telescope find_files as well.

I'll look into both of these issues further but my initial instincts are that they're more suited to be fixed upstream by telescope and plenary.

@fdschmidt93 Can I get your thoughts on this? It looks like this is a case of improperly handled escape sequences but I'm not quite sure why it's tripping up the way it's tripping up. Experimenting around, it doesn't seem like it's an issue with just any file/folder with () in them. $ seems to play apart but just having $ isn't an issue either.

Eg.
(foo)/ -> ok
$foo/ -> also ok
($foo)/ -> not ok

cwd for the plenary job is being interpreted as "/tmp/testing/()"

edit: the paths are being passed to vim.fn.expand and that seems to mess things up.

full warning stack
[telescope] [WARN  18:57:32] .../.repro/plugins/telescope.nvim/lua/telescope/pickers.lua:493: Finder failed with msg:  ...esting/.repro/plugins/telescope.nvim/lua/telescope/_.lua
:76: Failed to spawn process: {
[telescope]   command = "fd",
[telescope]   pid = "ENOENT: no such file or directory",
[telescope]   stderr = {
[telescope]     close = <function 1>,
[telescope]     eof_rx = <function 2>,
[telescope]     eof_tx = <function 3>,
[telescope]     read_start = <function 4>,
[telescope]     start = <function 5>,
[telescope]     <metatable> = <1>{
[telescope]       __call = <function 6>,
[telescope]       __tostring = <function 7>,
[telescope]       new = <function 8>,
[telescope]       super = <2>{
[telescope]         __call = <function 6>,
[telescope]         __index = <table 2>,
[telescope]         __tostring = <function 7>,
[telescope]         close = <function 9>,
[telescope]         new = <function 10>,
[telescope]         super = <3>{
[telescope]           __call = <function 6>,
[telescope]           __index = <table 3>,
[telescope]           __tostring = <function 7>,
[telescope]           extend = <function 11>,
[telescope]           implement = <function 12>,
[telescope]           is = <function 13>,
[telescope]           new = <function 14>
[telescope]         },
[telescope]         <metatable> = <table 3>
[telescope]       },
[telescope]       <metatable> = <table 2>
[telescope]     }
[telescope]   },
[telescope]   stdin = {
[telescope]     close = <function 15>,
[telescope]     eof_rx = <function 16>,
[telescope]     eof_tx = <function 17>,
[telescope]     read_start = <function 18>,
[telescope]     start = <function 19>,
[telescope]     <metatable> = <table 1>
[telescope]   },
[telescope]   stdout = {
[telescope]     eof_rx = <function 20>,
[telescope]     eof_tx = <function 21>,
[telescope]     handle = <userdata 1>,
[telescope]     <metatable> = <4>{
[telescope]       __call = <function 6>,
[telescope]       __index = <table 4>,
[telescope]       __tostring = <function 7>,
[telescope]       iter = <function 22>,
[telescope]       new = <function 23>,
[telescope]       read = <function 24>,
[telescope]       super = <table 2>,
[telescope]       <metatable> = <table 2>
[telescope]     }
[telescope]   },
[telescope]   uv_opts = {
[telescope]     args = { "--base-directory=/tmp/testing/($lang)", "--absolute-path", "--path-separator=/", "--maxdepth", 1 },
[telescope]     cwd = "/tmp/testing/()",
[telescope]     stdio = {
[telescope]       [2] = <userdata 1>
[telescope]     }
[telescope]   },
[telescope]   <metatable> = <5>{
[telescope]     __index = <table 5>,
[telescope]     _for_each_pipe = <function 25>,
[telescope]     close = <function 26>,
[telescope]     new = <function 27>
[telescope]   }
[telescope] }
[telescope] stack traceback:
[telescope] ^I...esting/.repro/plugins/telescope.nvim/lua/telescope/_.lua:76: in function 'spawn'
[telescope] ^I...cope.nvim/lua/telescope/finders/async_oneshot_finder.lua:48: in function '_finder'
[telescope] ^I....nvim/lua/telescope/_extensions/file_browser/finders.lua:224: in function 'finder'
[telescope] ^I.../.repro/plugins/telescope.nvim/lua/telescope/pickers.lua:489: in function <.../.repro/plugins/telescope.nvim/lua/telescope/pickers.lua:488>
[telescope] ^I[C]: in function 'pcall'
[telescope] ^I.../.repro/plugins/telescope.nvim/lua/telescope/pickers.lua:488: in function <.../.repro/plugins/telescope.nvim/lua/telescope/pickers.lua:450>

@juanpprieto
Copy link
Author

juanpprieto commented Feb 28, 2023

Thanks for the quick response and all the work with this amazing plugin @jamestrew

Eg.
(foo)/ -> ok
$foo/ -> also ok
($foo)/ -> not ok

Confirm this is the case for me too 🙏🏼

@jamestrew
Copy link
Collaborator

jamestrew commented Mar 1, 2023

Several things I should look into:

  • async_oneshot_finder -> cwd is being expanded prior to passing cwd to uv and the expansion is butchering the path
  • regular "grouped" Job is fine since not passing cwd
  • git status Job also fails passing in cwd -> also being vim.fn.expanded
  • plenary.scandir is ok
  • "File Previewer" also fails for both directory and file preview

@jamestrew
Copy link
Collaborator

@juanpprieto I've determined the cause of this bug (besides the File Previewer). I'll work with the maintainers upstream to figure out a fix but in the meantime, you should be able to do :Telescope file_browser use_fd=false git_status=false (or put those in your settings) to get most of the functionality back.

@juanpprieto
Copy link
Author

Amazing! Thanks @jamestrew use_fd=false git_status=false did the trick for the folder access (which was the most pressing issue). File preview is empty, but that less important 🥇

@fdschmidt93
Copy link
Member

fdschmidt93 commented Mar 1, 2023

The problem most likely is that the path would have to be escaped for fd

[telescope] args = { "--base-directory=/tmp/testing/($lang)", "--absolute-path", "--path-separator=/", "--maxdepth", 1 },

like so

fd --base-directory="/tmp/testing/(\$lang)" which seems to work in my case appropriately. This seems sensible, because fd by default uses a regex syntax.

We should be able to fix this I believe (i.e. fd -F --base-directory="/tmp/testing/$lang" works) by passing -F or --fixed-strings which is also more appropriate since we don't want regex.

@jamestrew
Copy link
Collaborator

jamestrew commented Mar 2, 2023

I tried the above mentioned fix of adding --fixed-strings but in my testing, it doesn't resolve the issue.

I believe for both the git_status plenary job and async_oneshot_finder use cases, the issue comes down to the passed cwd being expanded via vim.fn.expand. Altering both of these to just use the provide cwd resolves the issue (besides the File Previewer).

https://github.com/nvim-lua/plenary.nvim/blob/253d34830709d690f013daf2853a9d21ad7accab/lua/plenary/job.lua#L68

https://github.com/nvim-telescope/telescope.nvim/blob/a3f17d3baf70df58b9d3544ea30abe52a7a832c2/lua/telescope/_.lua#L24

According to :h expand():

When {string} does not start with '%', '#' or '<', it is
expanded like a file name is expanded on the command line.

which is an issue for files/folders with pattern like ($lang).

Edit: I found an example of a way to mitigate this in telescope.from_entry using vim.fn.escape so I'll just extend that to include $.

@juanpprieto
Copy link
Author

juanpprieto commented Mar 14, 2023

Hi @jamestrew, just ran a PackerSync and it seems this issue has regressed. My guess is that it's telescope related but just wanted to let you know.

Now instead of showing an error message, file browser just freezes and I see a telescope message saying something along the lines of "Nothing selected" when I try to open the ($lang) folder.

One more thing I noticed last week (before this latest changes) is that the following pattern was also breaking:

/app/routes/($lang)/__public/xyz

Thanks!

@jamestrew
Copy link
Collaborator

@juanpprieto This should be fixed now. You'll need to be on the latest commit for upstream telescope and plenary.

@juanpprieto
Copy link
Author

Amazing thanks @jamestrew - It's been great following this going upstream 🙏🏼

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

3 participants