diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-19 20:55:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-19 20:55:57 +0800 |
commit | 9b3315fe6330fb24fec3071c39118a3dd46631d7 (patch) | |
tree | 551326f15c9dbc202dde6e0a311b095db3c018b6 | |
parent | bab7e475ff015e5768f27fcac60ba39a4a3ca1dc (diff) | |
download | lua-language-server-9b3315fe6330fb24fec3071c39118a3dd46631d7.zip |
fix
-rw-r--r-- | script/files.lua | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/script/files.lua b/script/files.lua index b1e9f1f5..52607c99 100644 --- a/script/files.lua +++ b/script/files.lua @@ -607,15 +607,22 @@ function m.offset(uri, position, isFinish) text = m.getOriginText(uri) end local row = position.line + 1 - local start, finish = guide.lineRange(lines, row) - local char = position.character + local start, finish, char + if row > #lines then + start, finish = guide.lineRange(lines, #lines) + char = utf8.len(text, start, finish) + else + start, finish = guide.lineRange(lines, row) + char = position.character + end local utf8Len = utf8.len(text, start, finish) local offset if char <= 0 then offset = start - elseif char >= utf8Len then - offset = finish else + if char >= utf8Len then + char = utf8Len + end local left = utf8.offset(text, char, start) local right = utf8.offset(text, char + 1, start) if isFinish then @@ -651,15 +658,22 @@ function m.offsetOfWord(uri, position) text = m.getOriginText(uri) end local row = position.line + 1 - local start, finish = guide.lineRange(lines, row) - local char = position.character + local start, finish, char + if row > #lines then + start, finish = guide.lineRange(lines, #lines) + char = utf8.len(text, start, finish) + else + start, finish = guide.lineRange(lines, row) + char = position.character + end local utf8Len = utf8.len(text, start, finish) local offset if char <= 0 then offset = start - elseif char >= utf8Len then - offset = finish else + if char >= utf8Len then + char = utf8Len + end local left = utf8.offset(text, char, start) local right = utf8.offset(text, char + 1, start) if isNameChar(text:sub(left, right - 1)) |