summaryrefslogtreecommitdiff
path: root/script/proto/define.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-05 19:12:20 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-05 19:12:20 +0800
commitb41c1e1f26804469d322312597f46ccb81ec0674 (patch)
treee288a05c30c41b9a2d95ab64a0f1bd98796658db /script/proto/define.lua
parent2f53b27a582059ae990525042caed656f82a75c0 (diff)
downloadlua-language-server-b41c1e1f26804469d322312597f46ccb81ec0674.zip
close #144
Diffstat (limited to 'script/proto/define.lua')
-rw-r--r--script/proto/define.lua25
1 files changed, 16 insertions, 9 deletions
diff --git a/script/proto/define.lua b/script/proto/define.lua
index 7b58fdb4..1425395a 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -44,19 +44,26 @@ end
---@param offset integer
---@return position
function m.position(lines, text, offset)
- local row, col = guide.positionOf(lines, offset)
- local start = guide.lineRange(lines, row)
+ local row, col = guide.positionOf(lines, offset)
+ local start, finish = guide.lineRange(lines, row, true)
if start < 1 then
start = 1
end
- local ucol = util.utf8Len(text, start, start + col - 1)
- if row < 1 then
- row = 1
+ if col <= finish then
+ local ucol = util.utf8Len(text, start, start + col - 1)
+ if row < 1 then
+ row = 1
+ end
+ return {
+ line = row - 1,
+ character = ucol,
+ }
+ else
+ return {
+ line = row,
+ character = 0,
+ }
end
- return {
- line = row - 1,
- character = ucol,
- }
end
--- 将起点与终点位置转化为 range