summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/provider/provider.lua28
2 files changed, 23 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index bd39ed9b..ce3d5608 100644
--- a/changelog.md
+++ b/changelog.md
@@ -8,6 +8,7 @@
* `FIX` infer of `---@type class[][]`
* `FIX` infer of `---@type {}[]`
* `FIX` completion: displaying `@fenv` in `Lua 5.1`
+* `FIX` when a file is renamed, the file will still be loaded even if the new file name has been set to ignore
* `FIX` [#596](https://github.com/sumneko/lua-language-server/issues/596)
* `FIX` [#597](https://github.com/sumneko/lua-language-server/issues/597)
* `FIX` [#598](https://github.com/sumneko/lua-language-server/issues/598)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index dd8bcc15..b68300a9 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -35,6 +35,20 @@ local function updateConfig()
log.debug('loaded config dump:', util.dump(new))
end
+local function isValidLuaUri(uri)
+ if not files.isLua(uri) then
+ return false
+ end
+ if not files.isOpen(uri) then
+ return false
+ end
+ if workspace.isIgnored(uri)
+ and not files.isLibrary(uri) then
+ return false
+ end
+ return true
+end
+
proto.on('initialize', function (params)
client.init(params)
config.init()
@@ -127,9 +141,7 @@ proto.on('workspace/didChangeWatchedFiles', function (params)
end
elseif change.type == define.FileChangeType.Changed then
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
- if files.isLua(uri)
- and not files.isOpen(uri)
- and (not workspace.isIgnored(uri) or files.isLibrary(uri)) then
+ if isValidLuaUri(uri) then
files.setText(uri, pub.awaitTask('loadFile', uri), false)
else
local path = furi.decode(uri)
@@ -149,7 +161,7 @@ end)
proto.on('workspace/didCreateFiles', function (params)
log.debug('workspace/didCreateFiles', util.dump(params))
for _, file in ipairs(params.files) do
- if files.isLua(file.uri) then
+ if isValidLuaUri(file.uri) then
files.setText(file.uri, pub.awaitTask('loadFile', file.uri), false)
end
end
@@ -173,7 +185,9 @@ proto.on('workspace/didRenameFiles', function (params)
local text = files.getOriginText(file.oldUri)
if text then
files.remove(file.oldUri)
- files.setText(file.newUri, text, false)
+ if isValidLuaUri(file.newUri) then
+ files.setText(file.newUri, text, false)
+ end
end
local childs = files.getChildFiles(file.oldUri)
for _, uri in ipairs(childs) do
@@ -184,7 +198,9 @@ proto.on('workspace/didRenameFiles', function (params)
local nuri = file.newUri .. tail
log.debug('workspace/didRenameFiles#child', ouri, nuri)
files.remove(uri)
- files.setText(nuri, text, false)
+ if isValidLuaUri(nuri) then
+ files.setText(nuri, text, false)
+ end
end
end
end