diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-11-24 20:03:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 20:03:49 +0800 |
commit | b31836dd7e24914f7120bdaf947ed0c1fb2ff3b1 (patch) | |
tree | 885681abe57362aab68e2dff40effdb90e0882b1 | |
parent | 9c764ef056c7b6d906d5af60ce2d9f3d54cd4a86 (diff) | |
parent | 41bda6cd48338a2df2b7baeeb53a987e4f803fbb (diff) | |
download | lua-language-server-b31836dd7e24914f7120bdaf947ed0c1fb2ff3b1.zip |
Merge pull request #821 from dmitmel/refresh-cached-rows
Ensure that cachedRows of files are refreshed after didOpen
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/provider/provider.lua | 5 | ||||
-rw-r--r-- | script/text-merger.lua | 15 | ||||
-rw-r--r-- | test/basic/textmerger.lua | 5 |
4 files changed, 10 insertions, 16 deletions
diff --git a/script/files.lua b/script/files.lua index 4d649b29..da263dad 100644 --- a/script/files.lua +++ b/script/files.lua @@ -150,6 +150,7 @@ function m.setText(uri, text, isTrust, instance) file.text = newText file.trusted = isTrust file.originText = text + file.rows = nil file.words = nil m.astMap[uri] = nil file.cache = {} diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 8932c373..5ad07352 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -183,8 +183,11 @@ proto.on('textDocument/didChange', function (params) local changes = params.contentChanges local uri = doc.uri --log.debug('changes', util.dump(changes)) - local text = tm(uri, changes) + local text = files.getOriginText(uri) or '' + local rows = files.getCachedRows(uri) + text, rows = tm(text, rows, changes) files.setText(uri, text, true) + files.setCachedRows(uri, rows) end) proto.on('textDocument/hover', function (params) diff --git a/script/text-merger.lua b/script/text-merger.lua index afd3343f..d45a5800 100644 --- a/script/text-merger.lua +++ b/script/text-merger.lua @@ -91,25 +91,18 @@ local function mergeRows(rows, change) end end -return function (uri, changes) - local text +return function (text, rows, changes) for _, change in ipairs(changes) do if change.range then - local rows = files.getCachedRows(uri) - if not rows then - text = text or files.getOriginText(uri) or '' - rows = splitRows(text) - end + rows = rows or splitRows(text) mergeRows(rows, change) - files.setCachedRows(uri, rows) else - files.setCachedRows(uri, nil) + rows = nil text = change.text end end - local rows = files.getCachedRows(uri) if rows then text = table.concat(rows) end - return text + return text, rows end diff --git a/test/basic/textmerger.lua b/test/basic/textmerger.lua index a3a11f62..1ffd36f0 100644 --- a/test/basic/textmerger.lua +++ b/test/basic/textmerger.lua @@ -1,12 +1,9 @@ -local files = require 'files' local tm = require 'text-merger' local function TEST(source) return function (expect) return function (changes) - files.removeAll() - files.setText('', source) - local text = tm('', changes) + local text = tm(source, nil, changes) assert(text == expect) end end |