stevearc / oil.nvim

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

fix: willRename source path #248

Closed luckasRanarison closed 9 months ago

luckasRanarison commented 10 months ago

Closes #247. I think getting the relative path is unnecessary because the glob pattern will always match the full path, and it can mess up with some server filters, for example: tsserver uses **/*.js but the relative path omit the parent dir.

luckasRanarison commented 10 months ago

Any pattern that doesn't start with ** will fail to match because we're passing in the absolute path to the file.

This is actually not true, try the following:

local pat = vim.fn.glob2regpat("*.js")
local match = vim.fn.match("/dir/file.js", pat)
print(match) -- 9
stevearc commented 10 months ago

Ah, I was overly broad. Yes it's true that a pattern of *.js also works, but if the pattern doesn't start with a * or **, then it will fail. Example:

local pat = vim.fn.glob2regpat("src/*.js")
local match = vim.fn.match("/home/user/project/src/file.js", pat)
print(match) -- -1
luckasRanarison commented 10 months ago

Oh, I see. But I think it's unlikely going to happen, I think FileOperartionPattern is meant to be matched against the absolute path. tsserver, rust_analyzer and php actor which support willRenameFiles all use **/*.filetype.

I'll update this later and use vim.lsp._watchfiles and fallback to both absolute path and relative path as a workaround if you're concerned about it.

stevearc commented 9 months ago

Thanks for the PR!