stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.84k stars 110 forks source link

Added ability to move files into folders (and create if they don't exist) #305

Closed pi314ever closed 6 months ago

pi314ever commented 8 months ago

This solves feature request #117 without major changes to code.

Added functionality:

Known issues:

Example usage: <-- = parent directory of oil buffer File directory structure:

- a/ <--
  - b.x
  - c.y

After changing b.x to d1/d2/b.x:

- a/ <--
  - d1/
  | - d2/
  | | - b.x
  - c.y

After changing c.y to d1/c.y:

- a/ <--
  - d1/
  | - d2/
  | | - b.x
  | - c.y

After changing 'c.y' to ../c.y:

- a/ 
  - d1/ <--
  | - d2/
  | | - b.x
  - c.y

EDITS: Added examples and known issues

pi314ever commented 7 months ago

I realize I did not address the edge case for when files already exist that was mentioned in the issue. However, there is an argument that this decision should not live in this PR as it applies to renaming things in general and should be accounted for explicitly in the move operation. I haven't taken the time to dig into that yet, so I am not sure what the default behavior is.

thiagokokada commented 7 months ago

I am testing this branch in my configuration and it is exactly what I needed.

Thanks @pi314ever.

pi314ever commented 7 months ago

Hey @stevearc , any idea when you could take a look at this? I would love to have this PR merged to improve the capabilities of oil. Thank you for your time!

pi314ever commented 6 months ago

Thanks for your response! I truly appreciate the time you took to detail your concerns with this PR. The current method for checking duplicates only works on currently open buffers, and the extension to search in unopened buffers does seem quite difficult with the current implementation of oil. I don't think I will have time to figure out how to work this out myself either, but I hope someone can pick up where I left off.

Some notes to anyone who wants to tackle this problem:

  it("errors on duplicate names for nested files", function()
    local file = test_adapter.test_set("/foo/a.txt", "file")
    local dir = test_adapter.test_set("/foo/bar", "directory")
    local _ = test_adapter.test_set("/foo/bar/a.txt", "file")
    vim.cmd.edit({ args = { "oil-test:///foo/" } })
    local bufnr = vim.api.nvim_get_current_buf()
    set_lines(bufnr, {
      string.format("/%d bar", dir[FIELD_ID]),
      string.format("/%d bar/a.txt", file[FIELD_ID]),
    })
    local _, errors = parser.parse(bufnr)
    assert.are.same({
      {
        message = "Duplicate filename",
        lnum = 2,
        end_lnum = 3,
        col = 0,
      },
    }, errors)
  end)