summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-27 16:59:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-27 16:59:05 +0800
commite72f5143dc1d2d41763b74809b1ffe5ec5f426c2 (patch)
tree50065e80f626ab286795e13c4cdfa195305be31f
parent219c802e4e6a67aa9c4a1b4a5bd7886f8181b7c4 (diff)
downloadlua-language-server-e72f5143dc1d2d41763b74809b1ffe5ec5f426c2.zip
fix modifying the code before loading finish
-rw-r--r--script/files.lua6
-rw-r--r--script/provider/provider.lua19
-rw-r--r--script/workspace/workspace.lua2
3 files changed, 20 insertions, 7 deletions
diff --git a/script/files.lua b/script/files.lua
index 1e7c15e9..7e14bd9c 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -122,7 +122,7 @@ end
--- 设置文件文本
---@param uri uri
---@param text string
-function m.setText(uri, text)
+function m.setText(uri, text, isTrust)
if not text then
return
end
@@ -139,11 +139,15 @@ function m.setText(uri, text)
m._pairsCache = nil
end
local file = m.fileMap[uri]
+ if file.trusted and not isTrust then
+ return
+ end
local newText = pluginOnSetText(file, text)
if file.text == newText then
return
end
file.text = newText
+ file.trusted = isTrust
file.originText = text
m.linesMap[uri] = nil
m.originLinesMap[uri] = nil
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 7c7721a4..8ba5bb1c 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -149,7 +149,10 @@ proto.on('workspace/didChangeWatchedFiles', function (params)
elseif change.type == define.FileChangeType.Changed then
-- 如果文件处于关闭状态,则立即更新;否则等待didChange协议来更新
if files.isLua(uri) and not files.isOpen(uri) then
- files.setText(uri, pub.awaitTask('loadFile', uri))
+ while not plugin.isReady() do
+ await.sleep(0.1)
+ end
+ files.setText(uri, pub.awaitTask('loadFile', uri), false)
else
local path = furi.decode(uri)
local filename = fs.path(path):filename():string()
@@ -170,9 +173,12 @@ proto.on('textDocument/didOpen', function (params)
local text = doc.text
files.open(uri)
while not plugin.isReady() do
+ if not files.isOpen(uri) then
+ return
+ end
await.sleep(0.1)
end
- files.setText(uri, text)
+ files.setText(uri, text, true)
end)
proto.on('textDocument/didClose', function (params)
@@ -188,8 +194,11 @@ proto.on('textDocument/didChange', function (params)
local doc = params.textDocument
local changes = params.contentChanges
local uri = doc.uri
- if not files.isLua(uri) and not files.isOpen(uri) then
- return
+ while not plugin.isReady() or not files.exists(uri) do
+ if not files.isLua(uri) and not files.isOpen(uri) then
+ return
+ end
+ await.sleep(0.1)
end
files.clearDiff(uri)
local text = files.getText(uri) or ''
@@ -201,7 +210,7 @@ proto.on('textDocument/didChange', function (params)
text = change.text
end
end
- files.setText(uri, text)
+ files.setText(uri, text, true)
end)
proto.on('textDocument/hover', function (params)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index ec30c9ea..94b1d9e5 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -200,7 +200,7 @@ local function loadFileFactory(root, progressData, isLibrary)
log.info('++++As library of:', root)
files.setLibraryPath(uri, root)
end
- files.setText(uri, text)
+ files.setText(uri, text, false)
else
files.remove(uri)
end