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

Files with this kind of title [...title] not opening correctly on find_files #1171

Closed
efierros opened this issue Aug 26, 2021 · 10 comments
Closed
Labels
bug Something isn't working

Comments

@efierros
Copy link

Description

Each time I trigger the command to find files with Telescope, I search for a file with this kind of title

[...title].js

And it doesn't open, it shows me a blank file, but the file es full of code

I believe is because it asumes the extension is: ..title].js, Formatter also has trouble with this files

Neovim version

0.5.0

Operating system and version

macOS 11.5.2

Steps to reproduce

1.- Create a file with the title [...title].js
2.- Try to open it with find_files command, I use this: <Cmd>Telescope find_files find_command=rg,--ignore,--hidden,--files<CR>

Expected behavior

No response

Actual behavior

If I open the file from nvimTree, it opens fine
Captura de Pantalla 2021-08-26 a la(s) 15 02 58

If I search the file it shows me correctly the preview
Captura de Pantalla 2021-08-26 a la(s) 15 04 04

But once I opened the file is blank, it doesn't overwrite the file, just show it blank
Captura de Pantalla 2021-08-26 a la(s) 15 04 16

Minimal config

This is my telescope config

require('telescope').setup {
    defaults = {
        vimgrep_arguments = {
            'rg',
            '--no-heading',
            '--with-filename',
            '--line-number',
            '--column',
            '--smart-case',
            '-u'
        },
        prompt_prefix = "",
        selection_caret = "",
        entry_prefix = "  ",
        initial_mode = "insert",
        selection_strategy = "reset",
        sorting_strategy = "ascending",
        layout_strategy = "vertical",
        layout_config = {
			prompt_position = "top",
			horizontal = {mirror = false}, vertical = {mirror = false},
			--width = 0.75,
			--preview_cutoff = 120,
		},
        file_sorter = require'telescope.sorters'.get_fzy_sorter,
        file_ignore_patterns = {},
        path_display = {
			--'shorten'
		},
        winblend = 0,
        border = {},
        borderchars = {'', '', '', '', '', '', '', ''},
        color_devicons = true,
        use_less = true,
        set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
        file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
        grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
        qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,

        -- Developer configurations: Not meant for general override
        buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker,
        mappings = {
            i = {
                ["<C-j>"] = actions.move_selection_next,
                ["<C-k>"] = actions.move_selection_previous,
                -- To disable a keymap, put [map] = false
                -- So, to not map "<C-n>", just put
                -- ["<c-x>"] = false,
                ["<esc>"] = actions.close,

                -- Otherwise, just set the mapping to the function that you want it to be.
                -- ["<C-i>"] = actions.select_horizontal,

                -- Add up multiple actions
                ["<CR>"] = actions.select_default + actions.center

                -- You can perform as many actions in a row as you like
                -- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
            },
            n = {
                ["<C-j>"] = actions.move_selection_next,
                ["<C-k>"] = actions.move_selection_previous
                -- ["<C-i>"] = my_cool_custom_action,
            }
        },
        extensions = {
            media_files = {
                filetypes = {"png", "webp", "jpg", "jpeg", "mp4", "pdf"},
                find_cmd = "rg"
            },
            fzy_native = {
                override_generic_sorter = false,
                override_file_sorter = true,
            },
			project = {
				display_type = 'full'
			}
		}
    }
}
@efierros efierros added the bug Something isn't working label Aug 26, 2021
@kkharji
Copy link
Member

kkharji commented Aug 28, 2021

tbh, it's weird use case 😄. I can confirm the bug, and it's because [ needs to be escaped with \ for it to be opened via edit command.

if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd())
vim.cmd(string.format("%s %s", command, filename))
end

Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) should have taken care of that.

executing :exe "edit " . fnameescape("[...algo].js") works without issues. However,

  • original: "/full/path/to/file/[...algo].js"
  • after fnameescape: "/full/path/to/file/\[...algo].js" (double escape is wrong)
  • after normalize: "/\\[...algo].js" (path is gone, left with just name)

So it must be something todo with either normalize path or make_relative

For the life of me, I couldn't spot out what maybe causing this.

@itmecho
Copy link

itmecho commented Oct 5, 2021

So from what I can tell, the problem is coming plenary.path where the path is getting normalized to the root directory.

:lua print(string.format('edit %s', require('plenary.path'):new(vim.fn.fnameescape('pages/api/auth/[...nextAuth].ts'))))
edit pages/api/auth/\[...nextAuth].ts

-- same thing with the normalize call
:lua print(string.format('edit %s', require('plenary.path'):new(vim.fn.fnameescape('pages/api/auth/[...nextAuth].ts')):normalize(vim.loop.cwd())))
edit /pages/api/auth/\[...nextAuth].ts

@itmecho
Copy link

itmecho commented Oct 5, 2021

OK I've found the problem and a possible fix. I'll open a ticket on plenary

@kkharji
Copy link
Member

kkharji commented Oct 5, 2021

@itmecho open a pr better

@itmecho
Copy link

itmecho commented Oct 5, 2021

Meant to open it as a draft as I didn't have time to get everything working at work =[ Tidying it up now

@itmecho
Copy link

itmecho commented Oct 5, 2021

@tami5 Hopefully it's better now. The tests pass locally and I tested it with telescope and it now opens the files correctly

@Conni2461
Copy link
Member

I just merged the plenary PR so this should be fixed. Big thanks to @itmecho

Closed by nvim-lua/plenary.nvim@de5acdc

@4ry1337
Copy link

4ry1337 commented Jan 26, 2024

I am still facing the same problem

I am using Windows 11 and powershell

trying to save

image

image

@stf9
Copy link

stf9 commented Feb 4, 2024

I am also having this issue, did you figure it out?

@jluquer
Copy link

jluquer commented Apr 1, 2024

It happens to me too.

My workaround is to use a custom find_command:

find_command = { "rg", "--files", "--glob", "!{.git/*,.svelte-kit/*,target/*,node_modules/*,.vscode/*}", "--path-separator", "/", },

live_grep also fails. It shows an empty buffer when navigating to a file inside a (folder) but I did not found a workaround yet.

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

7 participants