nvim-telescope / telescope.nvim

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

Files with brackets in the name fail to open #1303

Closed itmecho closed 3 years ago

itmecho commented 3 years ago

Description

If you have a file with brackets in the name, for example pages/api/user/[id].ts, it fails to open via telescope's find_files or file_browser.

Opened with telescope, I see this

:echo expand('%')
/pages/api/user/[id].ts

opened via :e using tab completion where it auto escapes the first bracket, I see this:

:e pages/api/auth/\[...nextauth].ts
:echo expand('%')
pages/api/auth/[...nextauth].ts

Neovim version

NVIM v0.6.0-dev+324-ge8fb0728e Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilation: /usr/bin/cc -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/iain/src/neovim/build/config -I/home/iain/src/neovim/src -I/home/iain/src/neovim/.deps/usr/include -I/usr/include -I/home/iain/src/neovim/build/src/nvim/auto -I/home/iain/src/neovim/build/include Compiled by iain@orion

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/home/iain/.local/share/nvim"

Operating system and version

Arch linux Linux orion 5.14.7-arch1-1 #1 SMP PREEMPT Wed, 22 Sep 2021 21:35:11 +0000 x86_64 GNU/Linux

checkhealth 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.2.1

## ===== Installed extensions =====

## Telescope Extension: `fzy_native`
  - INFO: No healthcheck provided

Steps to reproduce

  1. cd /tmp && echo 'test' > '[test].txt'
  2. Open neovim with telescope installed
  3. :Telescope find_files or :Telescope file_browser
  4. Search for test and select the file from step 1
  5. See an empty buffer

Expected behavior

Should open the correct file

Actual behavior

Opens a blank buffer (I'm guessing a new file?)

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-fzf-native.nvim', run = 'make' },
        },
      },
      -- 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('fzf')
  -- 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()]]
fdschmidt93 commented 3 years ago

Closing this as a duplicate of #1223 and #1291 being tracked over at #1171

Just to check, :e pages/api/auth/\[...nextauth].ts already solves the problem? If that already solves it, my first hunch is the below would have to be extended to properly escape these filenames adequately. I'm quite busy atm, happy to guide a PR.

https://github.com/nvim-telescope/telescope.nvim/blob/440c598de419858a056e7d9d42a0a6829cd5bb05/lua/telescope/actions/set.lua#L132-L134

cc also @MatthiasGrandl @efierros @lgmys -- if one of the four of you in total wants to take a crack at this :)

MatthiasGrandl commented 3 years ago

@fdschmidt93 yes opening the file like that works as expected. Sadly I have very little lua knowledge and am quite busy myself.