diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-01-22 10:34:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-01-22 10:34:15 +0800 |
commit | 59b9f2343ef3c7b526a4ea5c4694cdc1ef8c4011 (patch) | |
tree | c1a20e8fc9fc62c4367dd4337f6922389d4eb940 | |
parent | 8022336ee8a574d84ba0f4fa9e377577fd318552 (diff) | |
download | lua-language-server-59b9f2343ef3c7b526a4ea5c4694cdc1ef8c4011.zip |
compatible plugin
-rw-r--r-- | script/files.lua | 21 | ||||
-rw-r--r-- | script/provider/provider.lua | 2 |
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) |