diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 16:16:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 16:16:27 +0800 |
commit | ed1bf904bc15c97344dc59745c32d3f741eb1449 (patch) | |
tree | 5996f587858d62241f2bd483c7bcc0affca6e4d8 /src/parser/calcline.lua | |
parent | 14f6d57ba711eb2d64470270ee7191181bfa25dc (diff) | |
download | lua-language-server-ed1bf904bc15c97344dc59745c32d3f741eb1449.zip |
转到定义
Diffstat (limited to 'src/parser/calcline.lua')
-rw-r--r-- | src/parser/calcline.lua | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/parser/calcline.lua b/src/parser/calcline.lua index ef0bfa3c..0c692a85 100644 --- a/src/parser/calcline.lua +++ b/src/parser/calcline.lua @@ -7,7 +7,6 @@ local NL = (m.P'\r\n' + m.S'\r\n') * m.Cp() / function (pos) fl = pos end local ROWCOL = (NL + m.P(1))^0 - local function rowcol(str, n) row = 1 fl = 1 @@ -16,6 +15,28 @@ local function rowcol(str, n) return row, col end +local function position(str, _row, _col) + local cur = 1 + local row = 1 + while true do + if row == _row then + return cur + _col - 1 + elseif row > _row then + return cur - 1 + end + local pos = str:find('[\r\n]', cur) + if not pos then + return #str + end + row = row + 1 + if str:sub(pos, pos+1) == '\r\n' then + cur = pos + 2 + else + cur = pos + 1 + end + end +end + local NL = m.P'\r\n' + m.S'\r\n' local function line(str, row) @@ -37,4 +58,5 @@ end return { rowcol = rowcol, line = line, + position = position, } |