diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 20:02:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-25 20:02:35 +0800 |
commit | 025fb18d576f2edb0863ab2d69f4f30db3fab835 (patch) | |
tree | 9715a96cfbec207a88cb48b1a8e4f9a288568adf | |
parent | 8d88695d3897384cdee001f49b702a1a3586597b (diff) | |
download | lua-language-server-025fb18d576f2edb0863ab2d69f4f30db3fab835.zip |
#234 修错了
-rw-r--r-- | script-beta/proto/define.lua | 8 | ||||
-rw-r--r-- | script/parser/lines.lua | 3 |
2 files changed, 7 insertions, 4 deletions
diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index 3afd5dc7..124ca42c 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -11,8 +11,8 @@ 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 + if start > #text then + return #text + 1 end local offset = utf8.offset(text, position.character + 1, start) return offset - 1 @@ -26,8 +26,8 @@ end function m.offsetOfWord(lines, text, position) local row = position.line + 1 local start = guide.lineRange(lines, row) - if start >= #text then - return 0 + if start > #text then + return #text + 1 end local offset = utf8.offset(text, position.character + 1, start) if offset > #text diff --git a/script/parser/lines.lua b/script/parser/lines.lua index f2f076e1..a5fe8116 100644 --- a/script/parser/lines.lua +++ b/script/parser/lines.lua @@ -66,6 +66,9 @@ function mt:position(row, col, code) end local pos if code == 'utf8' then + if start > finish then + return finish + end pos = utf8.offset(self.buf, col, start) or finish else pos = start + col - 1 |