From 7253c49258c847601fe27d7e623d7d416556ba06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 23 Sep 2021 16:39:54 +0800 Subject: update --- script/proto/converter.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'script') diff --git a/script/proto/converter.lua b/script/proto/converter.lua index b8744181..d2be23d2 100644 --- a/script/proto/converter.lua +++ b/script/proto/converter.lua @@ -1,4 +1,5 @@ local guide = require 'parser.guide' +local files = require 'files' local m = {} @@ -10,6 +11,12 @@ 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) + end return { line = row, character = col, @@ -20,7 +27,14 @@ end ---@param position position ---@return integer function m.unpackPosition(uri, position) - local pos = guide.positionOf(position.line, position.character) + 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 + end + local pos = guide.positionOf(row, col) return pos end -- cgit v1.2.3