diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 19:50:20 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 19:50:20 +0800 |
commit | 7e6bb85af1ffccc01f7504cd427fc8123d3179d0 (patch) | |
tree | 9ff95898def38a99987b2c5ed330bf303de0d382 | |
parent | c848377b107594759492c6ba6566705c9821df32 (diff) | |
download | lua-language-server-7e6bb85af1ffccc01f7504cd427fc8123d3179d0.zip |
#234 修正一个字符位置越界的错误
-rw-r--r-- | script-beta/proto/define.lua | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index 92403518..3afd5dc7 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -11,6 +11,9 @@ local m = {} function m.offset(lines, text, position) local row = position.line + 1 local start = guide.lineRange(lines, row) + if start >= #text then + return 0 + end local offset = utf8.offset(text, position.character + 1, start) return offset - 1 end @@ -23,6 +26,9 @@ end function m.offsetOfWord(lines, text, position) local row = position.line + 1 local start = guide.lineRange(lines, row) + if start >= #text then + return 0 + end local offset = utf8.offset(text, position.character + 1, start) if offset > #text or text:sub(offset-1, offset):match '[%w_][^%w_]' then |