Open davisthedev opened 1 year ago
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
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.
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.
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.
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:
search in find_files or live_grep for src\routes\(app)\loading\+page.svelte
the previewer will show an empty file.
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.
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 :)
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
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,
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 :)
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:
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.
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.
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.
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.
That's good to hear. This might be a helpful: https://github.com/nvim-telescope/telescope.nvim/blob/2d92125620417fbea82ec30303823e3cd69e90e8/lua/telescope/previewers/buffer_previewer.lua#L482-L508
I think the from_entry.path
from above might be the place to tweak.
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. https://github.com/nvim-telescope/telescope.nvim/pull/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.
I am experiencing something similar but with the nextjs dynamic routes convention of using square brackets in the folder names and also as https://github.com/nvim-telescope/telescope.nvim/issues/2446#issuecomment-1516188859 says, similar to case https://github.com/nvim-telescope/telescope.nvim/issues/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
Please, specify your operating system. There might be issues with path slash delimiters...
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.
Hello. Maybe i have something similar, when i use the find_browser extensions. For some reason is stays stuck.
New solution based on: https://github.com/MagicDuck/grug-far.nvim/pull/305
return {
'nvim-telescope/telescope.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
},
config = function()
local telescope = require 'telescope'
local actions = require 'telescope.actions'
-- https://github.com/MagicDuck/grug-far.nvim/pull/305
local is_windows = vim.fn.has('win64') == 1 or vim.fn.has('win32') == 1
local vimfnameescape = vim.fn.fnameescape
local winfnameescape = function(path)
local escaped_path = vimfnameescape(path)
if is_windows then
local need_extra_esc = path:find('[%[%]`%$~]')
local esc = need_extra_esc and '\\\\' or '\\'
escaped_path = escaped_path:gsub('\\[%(%)%^&;]', esc .. '%1')
if need_extra_esc then
escaped_path = escaped_path:gsub("\\\\['` ]", '\\%1')
end
end
return escaped_path
end
local select_default = function(prompt_bufnr)
vim.fn.fnameescape = winfnameescape
local result = actions.select_default(prompt_bufnr, "default")
vim.fn.fnameescape = vimfnameescape
return result
end
telescope.setup {
defaults = {
mappings = {
i = {
['<cr>'] = select_default,
},
n = {
['<cr>'] = select_default,
}
},
},
}
end
}
New solution based on: MagicDuck/grug-far.nvim#305
return { 'nvim-telescope/telescope.nvim', dependencies = { 'nvim-lua/plenary.nvim', }, config = function() local telescope = require 'telescope' local actions = require 'telescope.actions' -- https://github.com/MagicDuck/grug-far.nvim/pull/305 local is_windows = vim.fn.has('win64') == 1 or vim.fn.has('win32') == 1 local vimfnameescape = vim.fn.fnameescape local winfnameescape = function(path) local escaped_path = vimfnameescape(path) if is_windows then local need_extra_esc = path:find('[%[%]`%$~]') local esc = need_extra_esc and '\\\\' or '\\' escaped_path = escaped_path:gsub('\\[%(%)%^&;]', esc .. '%1') if need_extra_esc then escaped_path = escaped_path:gsub("\\\\['` ]", '\\%1') end end return escaped_path end local select_default = function(prompt_bufnr) vim.fn.fnameescape = winfnameescape local result = actions.select_default(prompt_bufnr, "default") vim.fn.fnameescape = vimfnameescape return result end telescope.setup { defaults = { mappings = { i = { ['<cr>'] = select_default, }, n = { ['<cr>'] = select_default, } }, }, } end }
Thanks! Worked perfectly.
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
Operating system and version
Windows 11
Telescope version / branch / rev
telescope 0.1.1
checkhealth telescope
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
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).