summaryrefslogtreecommitdiff
path: root/script/proto
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-23 17:34:51 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-23 17:34:51 +0800
commit48fe9fdd2071da918d3c7f0011f0e8c56b865b9f (patch)
treee8154b1ad6feb49e10f9f676405ba43b61a8e1da /script/proto
parente98031d6afff3e8a1b383ad0548d5857c3f06ace (diff)
downloadlua-language-server-48fe9fdd2071da918d3c7f0011f0e8c56b865b9f.zip
fix
Diffstat (limited to 'script/proto')
-rw-r--r--script/proto/converter.lua24
1 files changed, 14 insertions, 10 deletions
diff --git a/script/proto/converter.lua b/script/proto/converter.lua
index d2be23d2..9ff7e4dd 100644
--- a/script/proto/converter.lua
+++ b/script/proto/converter.lua
@@ -11,11 +11,13 @@ local m = {}
---@return position
function m.packPosition(uri, pos)
local row, col = guide.rowColOf(pos)
- local state = files.getState(uri)
- local text = files.getText(uri)
- if text then
- local lineOffset = state.lines[row]
- col = utf8.len(text, lineOffset, lineOffset + col - 1, true)
+ if col > 0 then
+ local state = files.getState(uri)
+ local text = files.getText(uri)
+ if text then
+ local lineOffset = state.lines[row]
+ col = utf8.len(text, lineOffset, lineOffset + col - 1, true)
+ end
end
return {
line = row,
@@ -28,11 +30,13 @@ end
---@return integer
function m.unpackPosition(uri, position)
local row, col = position.line, position.character
- local state = files.getState(uri)
- local text = files.getText(uri)
- if text then
- local lineOffset = state.lines[row]
- col = utf8.offset(text, lineOffset + col, lineOffset) - 1
+ if col > 0 then
+ local state = files.getState(uri)
+ local text = files.getText(uri)
+ if text then
+ local lineOffset = state.lines[row]
+ col = utf8.offset(text, col + 1, lineOffset) - 1
+ end
end
local pos = guide.positionOf(row, col)
return pos