feat: add support for LSP willRenameFiles (#184)
This commit is contained in:
parent
956d7fc89b
commit
8f3c1d2d2e
3 changed files with 195 additions and 0 deletions
|
|
@ -26,6 +26,13 @@ M.is_absolute = function(dir)
|
|||
end
|
||||
end
|
||||
|
||||
M.abspath = function(path)
|
||||
if not M.is_absolute(path) then
|
||||
path = vim.fn.fnamemodify(path, ":p")
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param cb fun(err: nil|string)
|
||||
M.touch = function(path, cb)
|
||||
|
|
@ -39,6 +46,38 @@ M.touch = function(path, cb)
|
|||
end)
|
||||
end
|
||||
|
||||
--- Returns true if candidate is a subpath of root, or if they are the same path.
|
||||
---@param root string
|
||||
---@param candidate string
|
||||
---@return boolean
|
||||
M.is_subpath = function(root, candidate)
|
||||
if candidate == "" then
|
||||
return false
|
||||
end
|
||||
root = vim.fs.normalize(M.abspath(root))
|
||||
-- Trim trailing "/" from the root
|
||||
if root:find("/", -1) then
|
||||
root = root:sub(1, -2)
|
||||
end
|
||||
candidate = vim.fs.normalize(M.abspath(candidate))
|
||||
if M.is_windows then
|
||||
root = root:lower()
|
||||
candidate = candidate:lower()
|
||||
end
|
||||
if root == candidate then
|
||||
return true
|
||||
end
|
||||
local prefix = candidate:sub(1, root:len())
|
||||
if prefix ~= root then
|
||||
return false
|
||||
end
|
||||
|
||||
local candidate_starts_with_sep = candidate:find("/", root:len() + 1, true) == root:len() + 1
|
||||
local root_ends_with_sep = root:find("/", root:len(), true) == root:len()
|
||||
|
||||
return candidate_starts_with_sep or root_ends_with_sep
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@return string
|
||||
M.posix_to_os_path = function(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue