diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 22:15:47 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-23 22:15:47 +0800 |
commit | c95e9c91236bccb4593a0d9d218dca78bcb06ae0 (patch) | |
tree | 08109d0b434bdc799758936fc759d89ae8dd0266 /script/parser/guide.lua | |
parent | 291a7b3a7fcaee5bc761722ca46265f3cd7f70f3 (diff) | |
download | lua-language-server-c95e9c91236bccb4593a0d9d218dca78bcb06ae0.zip |
update
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r-- | script/parser/guide.lua | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 28a275cf..b65d9680 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -759,17 +759,19 @@ function m.positionOf(row, col) return row * 10000 + col end +function m.positionToOffsetByLines(lines, position) + local row, col = m.rowColOf(position) + return lines[row] + col - 1 +end + --- 返回全文光标位置 ---@param state any ---@param position integer function m.positionToOffset(state, position) - local lines = state.lines - local row, col = m.rowColOf(position) - return lines[row] + col - 1 + return m.positionToOffsetByLines(state.lines, position) end -function m.offsetToPosition(state, offset) - local lines = state.lines +function m.offsetToPositionByLines(lines, offset) local left = 0 local right = #lines local row = 0 @@ -794,16 +796,8 @@ function m.offsetToPosition(state, offset) return m.positionOf(row, col) end -function m.lineContent(lines, text, row, ignoreNL) - local line = lines[row] - if not line then - return '' - end - if ignoreNL then - return text:sub(line.start, line.range) - else - return text:sub(line.start, line.finish) - end +function m.offsetToPosition(state, offset) + return m.offsetToPositionByLines(state.lines, offset) end local isSetMap = { |