From 41bda6cd48338a2df2b7baeeb53a987e4f803fbb Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 24 Nov 2021 13:37:48 +0200 Subject: ensure that cachedRows of files are refreshed after didOpen --- script/files.lua | 1 + script/provider/provider.lua | 5 ++++- script/text-merger.lua | 15 ++++----------- 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 -- cgit v1.2.3