summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-02 11:24:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-02 11:24:54 +0800
commita08e06cf9e23e27e8f274710cbd45947579fa8c6 (patch)
tree8baf1c5de3acb9144c78700eef8ce3a1c5c900e0 /script
parent2a546145f61d9d0c461cd6f77340452e0ba4e982 (diff)
downloadlua-language-server-a08e06cf9e23e27e8f274710cbd45947579fa8c6.zip
file operations no longer reload workspace
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)