From 0748f983c77d6e133959891823ee1c338d3deee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 9 Mar 2021 11:12:23 +0800 Subject: improve didChange --- script/files.lua | 16 ++++++++++++++-- script/provider/provider.lua | 1 + test/basic/init.lua | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/script/files.lua b/script/files.lua index 745c5354..c322bbe8 100644 --- a/script/files.lua +++ b/script/files.lua @@ -193,6 +193,19 @@ function m.setText(uri, text, isTrust) end end +function m.setRawText(uri, text) + if not text then + return + end + uri = getUriKey(uri) + local file = m.fileMap[uri] + file.text = text + file.originText = text + m.linesMap[uri] = nil + m.originLinesMap[uri] = nil + m.astMap[uri] = nil +end + --- 获取文件版本 function m.getVersion(uri) uri = getUriKey(uri) @@ -539,9 +552,8 @@ function m.offset(uri, position, isFinish) local row = position.line + 1 local start = guide.lineRange(lines, row) local offset - -- TODO if start <= 0 or start > #text then - offset = math.maxinteger + offset = #text + 1 else offset = utf8.offset(text, position.character + 1, start) or #text end diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 10b5fc8b..bf9dd9a0 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -279,6 +279,7 @@ proto.on('textDocument/didChange', function (params) else text = change.text end + files.setRawText(uri, text) end files.setText(uri, text, true) end) diff --git a/test/basic/init.lua b/test/basic/init.lua index 3c6d591f..f809a2f3 100644 --- a/test/basic/init.lua +++ b/test/basic/init.lua @@ -104,6 +104,7 @@ for _, change in ipairs(changes) do else text = change.text end + files.setRawText('', text) end assert(text == [[ -- cgit v1.2.3