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

Unable to preview and open files with parentheses in the path #2446

Open
davisthedev opened this issue Mar 28, 2023 · 19 comments
Open

Unable to preview and open files with parentheses in the path #2446

davisthedev opened this issue Mar 28, 2023 · 19 comments
Labels
bug Something isn't working Windows Relates to window operating system

Comments

@davisthedev
Copy link

davisthedev commented Mar 28, 2023

Description

When using telescope search files or live grep within a sveltekit project telescope is unable to preview or open files contained within a sveltekit advanced layout group: sveltekit docs.

Neovim version

NVIM v0.8.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compiled by runneradmin@fv-az28-353

Operating system and version

Windows 11

Telescope version / branch / rev

telescope 0.1.1

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0 (rev af6b6c543b)
  - OK: fd: found fd 8.7.0

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

Steps to reproduce

Within a sveltekit project using the advanced routeing -> advanced layout -> (groups).
Open a search files or live grep telescope window and search for content that will be nested below the route like /routes/(group)/.
The preview window will not display any content.
Then use your bound key or to open the selected file.
The route will show as /routes(group)/ with the / preceding the group not displaying.
This will open a new buffer with no content.

Expected behavior

That telescope is able to parse, display preview, and open files contained within these routes.

Actual behavior

Telescope is unable to preview content and open files contained within these routes

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' },
        },
      },
    },
    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')
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()]]



Notes from @jamestrew (2024-03-23):
There's a workaround for rg using pickers (find_files, live_grep, grep_string) here
Still affects many other file related pickers (current_buffer_fuzzy_find confirmed).

@davisthedev davisthedev added the bug Something isn't working label Mar 28, 2023
@jamestrew
Copy link
Contributor

This sounds somewhat related to #2412 and by that I mean some of these javascript meta frameworks tend to have file/folder naming conventions that don't play nicely with telescope.

I'll try to incorporate a fix for this into my PR and its subsequent PRs but can you dumb down your steps to reproduce? I've never used sveltekit so I tried replicating the bug by simply creating this file structure without using sveltekit and playing around in telescope and things appear to be working fine for me.

src/routes/
│ (app)/
│ ├ dashboard/
│ ├ item/
│ └ +layout.svelte

@davisthedev
Copy link
Author

Thank you for the link to that other issue. I am experiencing it with a private work project. I will try to make a reproducible repo on windows when I get home. I can say that the issue does not happen with my exact same config when using ubuntu on wsl2. So it may be a windows specific issue. I will follow up tonight and link a reproducible repo on windows.

@davisthedev
Copy link
Author

davisthedev commented Mar 29, 2023

I was able to reproduce the issue without using sveltekit or any javascript framework.

On windows 11 I just made a directory that matched the (dir)/ of the sveltekit project. Windows showed the file as '(dir)'/ with single quotes.

Using netrw I navigated to the parent directory of the (dir)/ and did a live grep. This was actually successful and found my html file with some text in it.

However if you navigate to the parent folder again i.e. here/parent/(dir)/ You were not able to use the live grep to locate the contents of the (dir)/ file.

At no point did the preview show the content, even when live grep and telescope navigated and opened the correct file.

Please let me know if you were able to follow these instructions and reproduce. Again this is only on windows 11, and only when you are more than one directory above the (dir)/ directory.

@jamestrew
Copy link
Contributor

Hmm.. navigating with netrw shouldn't change live_grep's behavior.
Regardless, I can't replicate the issue following your steps. I'm on arch linux. It's possible it's a Windows 11 issue. Unfortunately, I wouldn't know where to start with fixing this without playing around in Windows myself.

@davisthedev
Copy link
Author

davisthedev commented Apr 4, 2023

After some more digging it looks to be a behavior similar to or exactly matching #1171

If anyone who is able to test on windows finds this, here is what happens:

  1. search in find_files or live_grep for src\routes\(app)\loading\+page.svelte

  2. the previewer will show an empty file.

  3. when hitting return to open the file it will open to: src\routes(app)\loading\+page.svelte which does not exist because routes(app) is treated as a directory I believe.

So it must be something with how plenary or telescope handle that '(app)'/

I also might be missing a config or setting on my end that could alleviate this. Any information would be appreciated.

@Conni2461
Copy link
Member

so i've tested this with a sveltekit repo from work an i only had issues previewing $types.d.ts files which was resolved by #2412 so i've just merged that PR and i no longer have any issues previewing files. I'm not sure if there is still an issue on windows can you retest with the current master version (or 0.1.x).

thanks :)

@Conni2461
Copy link
Member

image
image
image

so yeah it works on linux but there is still the posibility we have to escape on windows because windows \ path separator is also kinda an escape string. I've pushed another branch fix/windows_parentheses_escape and can be found on this repo. Would be nice if you can also test this branch. it should ONLY fix the preview if that part is fixed we can look into fixing opening the file

@davisthedev
Copy link
Author

I tested with the fix/windows_parentheses_escape and master branch and the issue did persist. I was unable to preview any files in any directory with the name including parentheses, and unable to open them directly from the telescope find_files.

I use the same configs for my windows(work) computer and my personal(fedora) computer. The issue definitely does not persist on linux, so I agree that it is windows doing some sort of escaping. Would telescope need to escape the ' character as well?

I don't know much about lua dev, but I am happy to test any theories. Or if there is any additional info that would help.

Thanks,

@Conni2461
Copy link
Member

okay if thats an isolated windows issue i gonna setup a windows vm and test it there. that's probably easier. i am come back to you once i have a solution for that issues (in the next couple of days).

thanks for reporting :)

@Zeztron
Copy link

Zeztron commented Apr 20, 2023

Same thing happens in Next.js with their route grouping system. In this case, i'm not able to write to the file either:

Folder structure:
image

image

@davisthedev
Copy link
Author

Small update. I did try using nvChad and Lunarvim to see if their pre-configuration worked. It did not. And the issue was happening with Nvim-tree, so I believe this is not something isolated to telescope but vim and neovim issues.

@jamestrew
Copy link
Contributor

I managed to get a neovim setup working on windows and there is definitely some strange behavior with the (app)\ (folders with ()) in neovim that goes beyond telescope. I have to do some more testing but something is definitely weird and I'll continue to investigate this.

@davisthedev
Copy link
Author

Thank you for following up. I have a feeling it is related to windows wrapping directory names with special characters in single quotes, and then the quote getting escaped when neovim is opening the directory/folder location. I can reliably reproduce and I am happy to do any testing that would be helpful. I just do not know enough about neovim's workings to try and diagnose.

@davisthedev
Copy link
Author

I have a fix for this. I have it working for opening files, but I am not sure exactly where the code is that provides a path for the previewer to view a file. Could you help me figure out where that is. Basically I have a piece of code that correctly escapes these characters for windows. I just need to modify the path it is passing into the previewer.

@jamestrew
Copy link
Contributor

That's good to hear.
This might be a helpful:

previewers.cat = defaulter(function(opts)
opts = opts or {}
local cwd = opts.cwd or vim.loop.cwd()
return previewers.new_buffer_previewer {
title = "File Preview",
dyn_title = function(_, entry)
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
end,
get_buffer_by_name = function(_, entry)
return from_entry.path(entry, false)
end,
define_preview = function(self, entry)
local p = from_entry.path(entry, true)
if p == nil or p == "" then
return
end
conf.buffer_previewer_maker(p, self.state.bufnr, {
bufname = self.state.bufname,
winid = self.state.winid,
preview = opts.preview,
file_encoding = opts.file_encoding,
})
end,
}
end, {})

I think the from_entry.path from above might be the place to tweak.

@davisthedev
Copy link
Author

Thank you. You are correct, the from entry looks like what I want.
When I make a modification in that file, even a print() command, nothing changes.
I tried logging the path variable in that from_entry.lua and nothing returns.

My changes so far fix file opening, and the preview works when moving down, but not up.
#2652 is my draft if you have time to take a look and make recommendations. My fix is working, I just need to make sure I add it in all relevant areas.

@Pkcarreno
Copy link

I am experiencing something similar but with the nextjs dynamic routes convention of using square brackets in the folder names and also as #2446 (comment) says, similar to case #1171 but in windows and powershell

I don't know if it helps but I found this post that explains the reason for this in powershell and an workaround for it, in commands it works for me like this:

cd "./```[locale``]"

This only happens with folders, in files with square brackets in the name ([file].tsx) telescope works as expected

@hinell
Copy link

hinell commented Oct 16, 2023

Please, specify your operating system. There might be issues with path slash delimiters...

@schubsijan
Copy link

I had the same problem as @davisthedev. I also use Windows 11 and when I tried to open files in a folder of a SvelteKit-Advanced-layout, Telescope failed. As described above, only the path routes(group)\file_name opened.
I was able to work around this problem by adding the following to my setup-call:

require("telescope").setup({
      pickers = {
        find_files = {
          hidden = true,
          find_command = {
            "rg",
            "--files",
            "--glob",
            "!{.git/*,.svelte-kit/*,target/*,node_modules/*}",
            "--path-separator",
            "/",
          },
        },
      },
    })

@KevinSilvester has already suggested something similar here. Telescope now uses / and not \ and opens and previews the file correctly. It is only a workaround.

@jamestrew jamestrew added the Windows Relates to window operating system label Mar 22, 2024
@jamestrew jamestrew changed the title Telescope unable to preview and open files with sveltekit advanced layouts Unable to preview and open files parentheses Mar 22, 2024
@jamestrew jamestrew changed the title Unable to preview and open files parentheses Unable to preview and open files with parentheses in the path Mar 24, 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 Windows Relates to window operating system
Projects
None yet
7 participants