summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/files.lua21
-rw-r--r--script/provider/provider.lua2
2 files changed, 18 insertions, 5 deletions
diff --git a/script/files.lua b/script/files.lua
index fd9a55ab..48a5b58b 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -116,14 +116,15 @@ function m.setText(uri, text)
m._pairsCache = nil
end
local suc, newText = plugin.dispatch('OnSetText', originUri, text)
- if suc then
- text = newText
+ if not suc then
+ newText = text
end
local file = m.fileMap[uri]
- if file.text == text then
+ if file.text == newText then
return
end
- file.text = text
+ file.text = newText
+ file.originText = text
m.linesMap[uri] = nil
m.astMap[uri] = nil
file.cache = {}
@@ -159,6 +160,18 @@ function m.getText(uri)
return file.text
end
+--- 获取文件原始文本
+---@param uri uri
+---@return string text
+function m.getOriginText(uri)
+ uri = getUriKey(uri)
+ local file = m.fileMap[uri]
+ if not file then
+ return nil
+ end
+ return file.originText
+end
+
--- 移除文件
---@param uri uri
function m.remove(uri)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 054e3ac3..bc6694f4 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -188,7 +188,7 @@ proto.on('textDocument/didChange', function (params)
if not files.isLua(uri) and not files.isOpen(uri) then
return
end
- local text = files.getText(uri) or ''
+ local text = files.getOriginText(uri) or ''
for _, change in ipairs(changes) do
if change.range then
local lines = files.getLines(uri)