diff options
author | Dmytro Meleshko <dmytro.meleshko@gmail.com> | 2021-11-24 13:37:48 +0200 |
---|---|---|
committer | Dmytro Meleshko <dmytro.meleshko@gmail.com> | 2021-11-24 13:37:48 +0200 |
commit | 41bda6cd48338a2df2b7baeeb53a987e4f803fbb (patch) | |
tree | 61761dd5f99809f54bfd38b06ad7cb2bdaef3141 | |
parent | 1319f05cd4de50d7b01a297f39c4ad5a839ff7be (diff) | |
download | lua-language-server-41bda6cd48338a2df2b7baeeb53a987e4f803fbb.zip |
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 |