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

Incorrect Parent Folder Name When Moving Folders #357

Closed
fadedreams opened this issue Jan 28, 2024 · 13 comments · Fixed by #358
Closed

Incorrect Parent Folder Name When Moving Folders #357

fadedreams opened this issue Jan 28, 2024 · 13 comments · Fixed by #358
Labels
bug Something isn't working

Comments

@fadedreams
Copy link

fadedreams commented Jan 28, 2024

Description

I have encountered a potential issue when using the telescope-file-browser.nvim plugin. When I mark a folder for moving, navigate to another folder, and then press Alt + m to move the marked folder, the moved folder's name becomes the parent of the desired folder instead of retaining its original name.

Neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

Operating system and version

Debian12

Steps to reproduce

Open the telescope-file-browser.nvim file browser.
Mark a folder for moving (e.g., using Tab).
Navigate to another folder.
Press Alt + m(insert mode) or m (normal mode) to move the marked folder.

Expected behavior

I expect the marked folder to be moved to the current location, the moved folder should be keep its original name.

Actual behavior

The moved folder's name becomes the parent of the desired folder.

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope-file-browser.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
    },
    config = function()
      require("telescope").setup({})
      require("telescope").load_extension("file_browser")
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
@fadedreams fadedreams added the bug Something isn't working label Jan 28, 2024
@jamestrew
Copy link
Collaborator

I believe this was fixed not too long ago.
#344

Can you update telescope-file-browser and see if the issue still persists?

@fadedreams
Copy link
Author

fadedreams commented Jan 29, 2024

Hi @jamestrew,

Thanks for investigating the issue. I wanted to let you know that I've updated the telescope-file-browser plugin, and you can verify the changes in the Git log below:

~/.local/share/nvim/lazy/telescope-file-browser.nvim$ git log --oneline --graph
* 6dd6522 (HEAD -> master, origin/master, origin/HEAD) fix(git): show status for git submodules (#356)
* 6f735a6 chore: format minimal config (#355)
* ee7e5aa chore: update bug report minimal config to use lazy (#354)
* 4bd5657 fix(action): prevent collapse_dirs from trying to open file (#351)
* 8e05433 fix(action.move): moving folders (#344) <------------------ This line 344

However, I regret to inform you that the issue is not yet resolved on my end. If you have any insights or suggestions, I would greatly appreciate your assistance.

@jamestrew
Copy link
Collaborator

Can you provide more details on how to reproduce this.
I've tried precisely this

Open the telescope-file-browser.nvim file browser.
Mark a folder for moving (e.g., using Tab).
Navigate to another folder.
Press Alt + m(insert mode) or m (normal mode) to move the marked folder.

with the minimal config and I'm not getting any strange behaviors.

file-browser-move-folder-repro.mp4

@fadedreams
Copy link
Author

I hope this message finds you well. I wanted to update you on the situation regarding the issue we discussed. I attempted to resolve it by cleaning up my Neovim configurations using the following steps:

rm -rf ~/.config/nvim ~/.local/share/nvim ~/.local/state/nvim ~/.cache/nvim

Afterwards, I created a new ~/.config/nvim/init.lua from here file with the following content:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

and another ~/.config/nvim/min.lua

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope-file-browser.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
    },
    config = function()
      require("telescope").setup({})
      require("telescope").load_extension("file_browser")
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

I then tested the setup using:

~/.config/nvim$ nvim -u min.lua
s.mp4

However, it did not work as expected. If you have any insights or suggestions on how to resolve this, I would greatly appreciate your assistance.

Thank you for your time and help.

@jamestrew
Copy link
Collaborator

I'm sorry. I tried to follow exactly your steps, even downgraded to neovim v0.9.4 but I'm still not able to replicate this issue.
Without the ability to replicate this, I'm not able to debug what is causing this issue for you.

@fadedreams
Copy link
Author

fadedreams commented Jan 31, 2024

Thank you for your continued efforts in trying to help me resolve this issue. I've done some tracking down on my end, and it seems that the problem might be related to the line:
local new_path_absolute = new_path:absolute()
which is part of the fb_actions.move function in the file "lua/telescope/_extensions/file_browser/actions.lua" . The new_path_absolute variable is giving unexpected results for me. For example, when I attempt to move "folder1" into "folder2," the result is something like "parent_of_folder1/folder2/parent_of_folder1," which is not the expected behavior. I hope this information helps in identifying the root cause of the issue.

@jamestrew
Copy link
Collaborator

Interesting.
If you can, can you put

      vim.print {
        selection = old_path_absolute,
        basename = basename,
        target_dir = target_dir,
        new_path = new_path_absolute,
      }

below that line

local new_path_absolute = new_path:absolute()

then repeat the reproduction steps and share the results?

I don't think it's the new_path:absolute() that's the issue but something before that.

@fadedreams
Copy link
Author

Thanks for your suggestion. I've added the debug print statements below the line:

{
  basename = "parent_of_folder1",
 new_path = "/home/m/parent_of_folder1/folder2/parent_of_folder1",
 selection = "/home/m/parent_of_folder1",
 target_dir = "/home/m/parent_of_folder1/folder2"
}

before :‌
 m@debian:  ~/parent_of_folder1$ tree

├──   folder1
└──   folder2
moving folder1 into folder2
after:
m@debian:~/parent_of_folder1$ tree
.
└── folder2
      └── parent_of_folder1


...
if new_path:exists() then
  table.insert(skipped, basename)
else
  local new_path_absolute = new_path:absolute()

  vim.print {
    selection = old_path_absolute,
    basename = basename,
    target_dir = target_dir,
    new_path = new_path_absolute,
  }
  selection:rename {
    new_name = new_path_absolute,
  }
...

@jamestrew
Copy link
Collaborator

Wow. I'm thoroughly confused.
Does using <tab> to select and delete directories work as expected?
If it does and you're willing, can you try adding a couple of print statements a few lines higher?

  local target_dir = get_target_dir(finder)
  local moved = {}
  local skipped = {}

  for idx, selection in ipairs(selections) do
    local old_path_absolute = selection:absolute()
    print(old_path_absolute)
    if vim.fn.isdirectory(old_path_absolute) == 1 then
      old_path_absolute = vim.fs.dirname(old_path_absolute)
    end
    local basename = vim.fs.basename(old_path_absolute)
    print(basename, old_path_absolute)

And just to double check, nothing but the print statements should be different here.

@fadedreams
Copy link
Author

fadedreams commented Feb 3, 2024

I've confirmed that using Tab key to select, delete, and copy directories works as expected. However, I've also tested this in WSL Ubuntu on Windows 10, and I'm encountering the same unexpected results when moving directories.

/home/m/parent_of_folder1/folder1
parent_of_folder1 /home/m/parent_of_folder1
[file_browser.actions.move] Moved: parent_of_folder1
before :‌
 m@debian:  ~/parent_of_folder1$ tree

├──   folder1
└──   folder2
moving folder1 into folder2
after:
m@debian:~/parent_of_folder1$ tree
.
└── folder2
      └── parent_of_folder1
for idx, selection in ipairs(selections) do
    local old_path_absolute = selection:absolute()
    print(old_path_absolute)
    if vim.fn.isdirectory(old_path_absolute) == 1 then
      old_path_absolute = vim.fs.dirname(old_path_absolute)
    end
    local basename = vim.fs.basename(old_path_absolute)
    print(basename, old_path_absolute)

@jamestrew
Copy link
Collaborator

Ohhh I see what the issue is and why I couldn't reproduce it.
You're not using fd, am I correct? I'm able to reproduce this when I disable the use of fd.

I'll work on a fix for this. Thanks for helping me debug this.

@jamestrew
Copy link
Collaborator

@fadedreams If you can try out the linked PR, that would be great.

@fadedreams
Copy link
Author

You're correct; I haven't installed fd. However, I tested the linked PR 358, and it worked for me in the situation even without installing fd. Thanks for your quick response and efforts to fix the issue!

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

Successfully merging a pull request may close this issue.

2 participants