summaryrefslogtreecommitdiff
path: root/script/files.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-26 15:51:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-26 15:51:05 +0800
commitaec13d09d7e54e0032b882744abf206369c6f93a (patch)
tree6d333096b552f9b9d152fc05162923e3c1575337 /script/files.lua
parent3a14ad38c15c21e61f15330ca8f8c0d76a10459c (diff)
downloadlua-language-server-aec13d09d7e54e0032b882744abf206369c6f93a.zip
fix diff
Diffstat (limited to 'script/files.lua')
-rw-r--r--script/files.lua23
1 files changed, 19 insertions, 4 deletions
diff --git a/script/files.lua b/script/files.lua
index 05a7e099..fd8216ca 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -430,10 +430,12 @@ function m.offset(uri, position)
end
local row = position.line + 1
local start = guide.lineRange(lines, row)
+ local offset
if start <= 0 or start > #text then
- return #text + 1
+ offset = #text + 2
+ else
+ offset = utf8.offset(text, position.character + 1, start) or (#text + 1)
end
- local offset = utf8.offset(text, position.character + 1, start) or (#text + 1)
if file._diffInfo then
offset = smerger.getOffset(file._diffInfo, offset)
end
@@ -457,10 +459,12 @@ function m.offsetOfWord(uri, position)
end
local row = position.line + 1
local start = guide.lineRange(lines, row)
+ local offset
if start <= 0 or start > #text then
- return #text + 1
+ offset = #text + 2
+ else
+ offset = utf8.offset(text, position.character + 1, start) or (#text + 1)
end
- local offset = utf8.offset(text, position.character + 1, start) or (#text + 1)
if file._diffInfo then
offset = smerger.getOffset(file._diffInfo, offset)
end
@@ -501,6 +505,17 @@ function m.diffedOffsetBack(uri, offset)
return smerger.getOffsetBack(file._diffInfo, offset)
end
+function m.clearDiff(uri)
+ uri = m.getUri(uri)
+ local file = m.fileMap[uri]
+ if not file then
+ return
+ end
+ file._diffInfo = nil
+ file.text = file.originText
+ m.linesMap[uri] = m.originLinesMap[uri]
+end
+
--- 将光标位置转化为 position
---@param uri uri
---@param offset integer