summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/files.lua14
-rw-r--r--script/provider/provider.lua21
2 files changed, 33 insertions, 2 deletions
diff --git a/script/files.lua b/script/files.lua
index 60119b8d..2e0c2666 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -206,6 +206,20 @@ function m.getOriginText(uri)
return file.originText
end
+function m.getChildFiles(uri)
+ uri = getUriKey(uri)
+ local results = {}
+ local uris = m.getAllUris()
+ for _, curi in ipairs(uris) do
+ if #curi > #uri
+ and curi:sub(1, #uri) == uri
+ and curi:sub(#uri+1, #uri+1):match '[/\\]' then
+ results[#results+1] = curi
+ end
+ end
+ return results
+end
+
--- 移除文件
---@param uri uri
function m.remove(uri)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 2fcc4f70..550b7945 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -197,6 +197,10 @@ proto.on('workspace/didDeleteFiles', function (params)
log.debug('workspace/didDeleteFiles', util.dump(params))
for _, file in ipairs(params.files) do
files.remove(file.uri)
+ local childs = files.getChildFiles(file.uri)
+ for _, uri in ipairs(childs) do
+ files.remove(uri)
+ end
end
end)
@@ -205,8 +209,21 @@ proto.on('workspace/didRenameFiles', function (params)
plugin.awaitReady()
for _, file in ipairs(params.files) do
local text = files.getOriginText(file.oldUri)
- files.remove(file.oldUri)
- files.setText(file.newUri, text, false)
+ if text then
+ files.remove(file.oldUri)
+ files.setText(file.newUri, text, false)
+ end
+ local childs = files.getChildFiles(file.oldUri)
+ for _, uri in ipairs(childs) do
+ local ctext = files.getOriginText(uri)
+ if ctext then
+ local ouri = files.getOriginUri(uri)
+ local tail = ouri:sub(#file.oldUri)
+ local nuri = file.newUri .. tail
+ files.remove(uri)
+ files.setText(nuri, text, false)
+ end
+ end
end
end)