summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-10 23:29:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-10 23:29:36 +0800
commitffc383d45e4a4a21958ec88ae8815c4683d3f2f4 (patch)
tree4c5d1b5f0c1c4cbe3374d7752e97fadbea198e2b
parent74eb42c4f89b06a57e5c157b0b9b7a93b4d7139f (diff)
downloadlua-language-server-ffc383d45e4a4a21958ec88ae8815c4683d3f2f4.zip
处理一下坐标转换
-rw-r--r--server-beta/src/parser/guide.lua6
-rw-r--r--server-beta/src/proto/define.lua6
2 files changed, 9 insertions, 3 deletions
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index b8593865..1cc82143 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -361,7 +361,7 @@ end
---@return integer {name = 'col'}
function m.positionOf(lines, offset)
if offset < 1 then
- return 1, 1
+ return 0, 0
end
local lastLine = lines[#lines]
if offset > lastLine.finish then
@@ -394,7 +394,7 @@ end
---@return integer {name = 'offset'}
function m.offsetOf(lines, row, col)
if row < 1 then
- return 1
+ return 0
end
if row > #lines then
local lastLine = lines[#lines]
@@ -422,7 +422,7 @@ end
function m.lineRange(lines, row)
local line = lines[row]
if not line then
- return 1, 1
+ return 0, 0
end
return line.start, line.finish
end
diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua
index 5e6bd3cf..1bf45531 100644
--- a/server-beta/src/proto/define.lua
+++ b/server-beta/src/proto/define.lua
@@ -23,7 +23,13 @@ end
function m.position(lines, text, offset)
local row, col = guide.positionOf(lines, offset)
local start = guide.lineRange(lines, row)
+ if start < 1 then
+ start = 1
+ end
local ucol = utf8.len(text, start, start + col - 1, true)
+ if row < 1 then
+ row = 1
+ end
return {
line = row - 1,
character = ucol,