Closed pi314ever closed 6 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.
I am testing this branch in my configuration and it is exactly what I needed.
Thanks @pi314ever.
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!
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:
check_dupe
function in lua/oil/mutator/parser.lua
is probably the place to modify for the smallest footprint, but the only implementation I can think of may be a performance bottleneck for large projects and moving large amounts of files. a
and b
for a/b/c
), while raising errors for ending nodes if duplicates exist for the ending node. (Maybe some sort of trie-based data structure would be optimal) 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)
This solves feature request #117 without major changes to code.
Added functionality:
Known issues:
/home/user/oil/data/../test/test.lua
vs/home/user/oil/test/test.lua
)Example usage:
<--
= parent directory of oil buffer File directory structure:After changing
b.x
tod1/d2/b.x
:After changing
c.y
tod1/c.y
:After changing 'c.y' to
../c.y
:EDITS: Added examples and known issues