diff options
-rw-r--r-- | script-beta/parser/guide.lua | 49 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 11 | ||||
-rw-r--r-- | test-beta/references/init.lua | 5 |
3 files changed, 59 insertions, 6 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 1ae96097..cab37dc1 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -205,6 +205,18 @@ function m.getBreakBlock(obj) error('guide.getBreakBlock overstack') end +--- 寻找doc的主体 +function m.getDocState(obj) + for _ = 1, 1000 do + local parent = obj.parent + if parent.type == 'doc' then + return obj + end + obj = parent + end + error('guide.getDocState overstack') +end + --- 寻找根区块 function m.getRoot(obj) for _ = 1, 1000 do @@ -1378,6 +1390,39 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) end end +function m.checkSameSimpleByBindDocs(status, obj, start, queue) + if not obj.bindDocs then + return + end + local results = {} + for _, doc in ipairs(obj.bindDocs) do + if doc.type == 'doc.class' then + results = stepRefOfDocType(status, doc.class, 'ref') + elseif doc.type == 'doc.type' then + for _, piece in ipairs(doc.types) do + local pieceResult = stepRefOfDocType(status, piece, 'ref') + for _, res in ipairs(pieceResult) do + results[#results+1] = res + end + end + end + end + local mark = {} + for _, res in ipairs(results) do + local ref = m.getDocState(res) + if not mark[ref] then + mark[ref] = true + if ref.bind then + queue[#queue+1] = { + obj = ref.bind, + start = start, + force = true, + } + end + end + end +end + function m.checkSameSimpleInArg1OfSetMetaTable(status, obj, start, queue) local args = obj.parent if not args or args.type ~= 'callargs' then @@ -1846,8 +1891,10 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) m.checkSameSimpleInArg1OfSetMetaTable(status, ref, i, queue) -- 检查自己作为 setmetatable 调用的情况 m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue) - -- 检查自己是特殊分支的情况 + -- 检查自己是特殊变量的分支的情况 m.checkSameSimpleInSpecialBranch(status, ref, i, queue) + -- 检查 doc + m.checkSameSimpleByBindDocs(status, ref, i, queue) if cmode == 'ref' and not status.simple then -- 检查形如 { a = f } 的情况 m.checkSameSimpleAsTableField(status, ref, i, queue) diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 121b25eb..e2aa950d 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -705,7 +705,10 @@ local function bindDoc(state, lns, binded) or src.type == 'tablefield' or src.type == 'tableindex' or src.type == 'function' then - src.docs = binded + src.bindDocs = binded + for _, doc in ipairs(binded) do + doc.bind = src + end end end) end @@ -715,7 +718,7 @@ local function bindDocs(state) local binded for _, doc in ipairs(state.ast.docs) do if not isNextLine(lns, binded, doc) then - bindDoc(state, binded) + bindDoc(state, lns, binded) binded = {} end binded[#binded+1] = doc @@ -750,5 +753,9 @@ return function (_, state) end end + if #ast.docs == 0 then + return + end + bindDocs(state) end diff --git a/test-beta/references/init.lua b/test-beta/references/init.lua index af9c38af..dc05a63b 100644 --- a/test-beta/references/init.lua +++ b/test-beta/references/init.lua @@ -48,7 +48,6 @@ function TEST(script) end assert(founded(target, positions)) else - local results = core('', pos) assert(#target == 0) end end @@ -279,12 +278,12 @@ TEST [[ ---@class Class local <?t?> ---@type Class -local <!t!> +local <!x!> ]] TEST [[ ---@class Class local <!t!> ---@type Class -local <?t?> +local <?x?> ]] |