summaryrefslogtreecommitdiff
path: root/server-beta/src/parser/guide.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/parser/guide.lua')
-rw-r--r--server-beta/src/parser/guide.lua25
1 files changed, 23 insertions, 2 deletions
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index 7cec136d..d3ae7100 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -174,6 +174,27 @@ function m.getLabel(root, block, name)
error('guide.getLocal overstack')
end
+--- 判断source是否包含offset
+function m.isContain(source, offset)
+ if not source.start then
+ return false
+ end
+ return source.start <= offset and source.finish >= offset - 1
+end
+
+--- 遍历所有包含offset的source
+function m.eachSource(root, offset, callback)
+ for i = 1, #root do
+ local source = root[i]
+ if m.isContain(source, offset) then
+ local res = callback(source)
+ if res ~= nil then
+ return res
+ end
+ end
+ end
+end
+
--- 获取偏移对应的坐标(row从0开始,col为光标位置)
---@param lines table
---@return integer {name = 'row'}
@@ -231,7 +252,7 @@ function m.offsetOf(lines, row, col)
end
function m.lineContent(lines, text, row)
- local line = lines[row]
+ local line = lines[row + 1]
if not line then
return ''
end
@@ -239,7 +260,7 @@ function m.lineContent(lines, text, row)
end
function m.lineRange(lines, row)
- local line = lines[row]
+ local line = lines[row + 1]
if not line then
return 0, 0
end