diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-09 16:47:36 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-09 16:47:36 +0800 |
commit | b5311472564006622cc3a2c79dc105a488ca5360 (patch) | |
tree | e3860627e6e0fd28d279568bd4be7361c8430928 /script-beta/parser/guide.lua | |
parent | c0e93478ef0e11aa8aa556af15815e6415cabc3f (diff) | |
download | lua-language-server-b5311472564006622cc3a2c79dc105a488ca5360.zip |
提升语义着色的性能
Diffstat (limited to 'script-beta/parser/guide.lua')
-rw-r--r-- | script-beta/parser/guide.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index e67d34f3..57d2d402 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -339,6 +339,14 @@ function m.isInRange(source, offset) return (source.vstart or source.start) <= offset and (source.range or source.finish) >= offset - 1 end +function m.isBetween(source, start, finish) + return source.start <= finish and source.finish >= start - 1 +end + +function m.isBetweenRange(source, start, finish) + return (source.vstart or source.start) <= finish and (source.range or source.finish) >= start - 1 +end + --- 添加child function m.addChilds(list, obj, map) local keys = map[obj.type] @@ -382,6 +390,32 @@ function m.eachSourceContain(ast, offset, callback) end end +--- 遍历所有在某个范围内的source +function m.eachSourceBetween(ast, start, finish, callback) + local list = { ast } + local mark = {} + while true do + local len = #list + if len == 0 then + return + end + local obj = list[len] + list[len] = nil + if not mark[obj] then + mark[obj] = true + if m.isBetweenRange(obj, start, finish) then + if m.isBetween(obj, start, finish) then + local res = callback(obj) + if res ~= nil then + return res + end + end + m.addChilds(list, obj, m.childMap) + end + end + end +end + --- 遍历所有指定类型的source function m.eachSourceType(ast, type, callback) local cache = ast.typeCache |