Skip to content

Commit f9ab5c4

Browse files
committed
feat: support using @class on global variable created by rawset()
1 parent b9373fd commit f9ab5c4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

script/parser/luadoc.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,9 @@ local function bindDocsBetween(sources, binded, start, finish)
19881988
or src.type == 'setmethod'
19891989
or src.type == 'function'
19901990
or src.type == 'return'
1991-
or src.type == '...' then
1991+
or src.type == '...'
1992+
or src.type == 'call' -- for `rawset`
1993+
then
19921994
if bindDoc(src, binded) then
19931995
ok = true
19941996
end
@@ -2108,12 +2110,23 @@ local bindDocAccept = {
21082110
'setfield' , 'setmethod' , 'setindex' ,
21092111
'tablefield', 'tableindex', 'self' ,
21102112
'function' , 'return' , '...' ,
2113+
'call',
21112114
}
21122115

21132116
local function bindDocs(state)
21142117
local text = state.lua
21152118
local sources = {}
21162119
guide.eachSourceTypes(state.ast, bindDocAccept, function (src)
2120+
-- allow binding docs with rawset(_G, "key", value)
2121+
if src.type == 'call' then
2122+
if src.node.special ~= 'rawset' or not src.args then
2123+
return
2124+
end
2125+
local g, key = src.args[1], src.args[2]
2126+
if not g or not key or g.special ~= '_G' then
2127+
return
2128+
end
2129+
end
21172130
sources[#sources+1] = src
21182131
end)
21192132
table.sort(sources, function (a, b)

0 commit comments

Comments
 (0)