diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 16:39:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 16:39:54 +0800 |
commit | 7253c49258c847601fe27d7e623d7d416556ba06 (patch) | |
tree | 5a9b50d4bf9c0f047b9131e21e25aa23249dae71 /script | |
parent | 1b2ca30ec04f69d0fbc8127bb72eff488218e086 (diff) | |
download | lua-language-server-7253c49258c847601fe27d7e623d7d416556ba06.zip |
update
Diffstat (limited to 'script')
-rw-r--r-- | script/proto/converter.lua | 16 |
1 files changed, 15 insertions, 1 deletions
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 |