summaryrefslogtreecommitdiff
path: root/script/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-29 15:47:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-29 15:47:21 +0800
commit6c452f5c36417289f5030074ce4834783e56d06f (patch)
treed5c19f7f5dcba99eb19eae730d5d8ac7e91503bc /script/parser
parent990596122167d4fa5bdc113f10d05027bb3a6bdf (diff)
downloadlua-language-server-6c452f5c36417289f5030074ce4834783e56d06f.zip
stash
Diffstat (limited to 'script/parser')
-rw-r--r--script/parser/guide.lua21
-rw-r--r--script/parser/luadoc.lua8
2 files changed, 22 insertions, 7 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 82871d90..0c1462ef 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -640,8 +640,7 @@ function m.eachSourceBetween(ast, start, finish, callback)
end
end
---- 遍历所有指定类型的source
-function m.eachSourceType(ast, type, callback)
+local function getSourceTypeCache(ast)
local cache = ast.typeCache
if not cache then
cache = {}
@@ -659,6 +658,12 @@ function m.eachSourceType(ast, type, callback)
myCache[#myCache+1] = source
end)
end
+ return cache
+end
+
+--- 遍历所有指定类型的source
+function m.eachSourceType(ast, type, callback)
+ local cache = getSourceTypeCache(ast)
local myCache = cache[type]
if not myCache then
return
@@ -668,6 +673,18 @@ function m.eachSourceType(ast, type, callback)
end
end
+function m.eachSourceTypes(ast, tps, callback)
+ local cache = getSourceTypeCache(ast)
+ for x = 1, #tps do
+ local tpCache = cache[tps[x]]
+ if tpCache then
+ for i = 1, #tpCache do
+ callback(tpCache[i])
+ end
+ end
+ end
+end
+
--- 遍历所有的source
function m.eachSource(ast, callback)
local cache = ast.eachCache
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index a7062862..5b34b11e 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -1344,7 +1344,7 @@ local function bindDoc(sources, lns, binded)
bindClassAndFields(binded)
end
-local bindDocAccept = util.arrayToHash {
+local bindDocAccept = {
'local' , 'setlocal' , 'setglobal',
'setfield' , 'setmethod' , 'setindex' ,
'tablefield', 'tableindex',
@@ -1355,10 +1355,8 @@ local function bindDocs(state)
tracy.ZoneBeginN('bindDocs #1')
local text = state.lua
local sources = {}
- guide.eachSource(state.ast, function (src)
- if bindDocAccept[src.type] then
- sources[#sources+1] = src
- end
+ guide.eachSourceTypes(state.ast, bindDocAccept, function (src)
+ sources[#sources+1] = src
end)
tracy.ZoneEnd()
tracy.ZoneBeginN('bindDocs #2')