diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/files.lua | 1 | ||||
-rw-r--r-- | script/provider/provider.lua | 5 | ||||
-rw-r--r-- | script/text-merger.lua | 15 |
3 files changed, 9 insertions, 12 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 |