@@ -57,30 +57,80 @@ local searchFieldMap = util.switch()
5757 if field .type == ' tablefield'
5858 or field .type == ' tableindex' then
5959 if guide .getKeyName (field ) == key then
60- pushResult (m . compileNode ( field ) )
60+ pushResult (field )
6161 end
6262 end
6363 end
6464 end )
6565 : case ' global'
6666 --- @param node vm.node.global
6767 : call (function (node , key , pushResult )
68- local global = globalMgr .getGlobal (' variable' , node .name , key )
69- if global then
70- pushResult (global )
68+ if node .cate == ' variable' then
69+ local global = globalMgr .getGlobal (' variable' , node .name , key )
70+ if global then
71+ pushResult (global )
72+ end
73+ end
74+ if node .cate == ' type' then
75+ m .getClassFields (node , key , pushResult )
7176 end
7277 end )
7378 : case ' local'
7479 : call (function (node , key , pushResult )
7580 local sources = localID .getSources (node , key )
7681 if sources then
7782 for _ , src in ipairs (sources ) do
78- pushResult (m . compileNode ( src ) )
83+ pushResult (src )
7984 end
8085 end
8186 end )
8287 : getMap ()
8388
89+
90+ function m .getClassFields (node , key , pushResult )
91+ local mark = {}
92+ local function searchClass (class )
93+ local name = class .name
94+ if mark [name ] then
95+ return
96+ end
97+ mark [name ] = true
98+ for _ , set in ipairs (class :getSets ()) do
99+ if set .type == ' doc.class' then
100+ -- check ---@field
101+ local hasFounded
102+ for _ , field in ipairs (set .fields ) do
103+ if guide .getKeyName (field ) == key then
104+ hasFounded = true
105+ pushResult (field )
106+ end
107+ end
108+ -- check local field and global field
109+ if set .bindSources then
110+ for _ , src in ipairs (set .bindSources ) do
111+ if searchFieldMap [src .type ] then
112+ searchFieldMap [src .type ](src , key , function (src )
113+ hasFounded = true
114+ pushResult (src )
115+ end )
116+ end
117+ end
118+ end
119+ -- look into extends(if field not found)
120+ if not hasFounded and set .extends then
121+ for _ , extend in ipairs (set .extends ) do
122+ local extendType = globalMgr .getGlobal (' type' , extend [1 ])
123+ if extendType then
124+ searchClass (extendType )
125+ end
126+ end
127+ end
128+ end
129+ end
130+ end
131+ searchClass (node )
132+ end
133+
84134local function getReturnOfFunction (func , index )
85135 if not func ._returns then
86136 func ._returns = util .defaultTable (function ()
@@ -101,8 +151,8 @@ local function getReturnOfSetMetaTable(source, args)
101151 m .setNode (source , m .compileNode (tbl ))
102152 end
103153 if mt then
104- m .compileByParentNode (mt , ' __index' , function (node )
105- m .setNode (source , node )
154+ m .compileByParentNode (mt , ' __index' , function (src )
155+ m .setNode (source , m . compileNode ( src ) )
106156 end )
107157 end
108158 return source ._node
136186
137187--- @param source vm.node
138188--- @param key any
139- --- @param pushResult fun ( node : vm.node )
189+ --- @param pushResult fun ( source : parser.object )
140190function m .compileByParentNode (source , key , pushResult )
141191 local parentNode = m .compileNode (source )
142192 if not parentNode then
@@ -244,8 +294,8 @@ local compilerMap = util.switch()
244294 : case ' getindex'
245295 : call (function (source )
246296 compileByLocalID (source )
247- m .compileByParentNode (source .node , guide .getKeyName (source ), function (node )
248- m .setNode (source , node )
297+ m .compileByParentNode (source .node , guide .getKeyName (source ), function (src )
298+ m .setNode (source , m . compileNode ( src ) )
249299 end )
250300 end )
251301 : case ' tablefield'
@@ -291,6 +341,10 @@ local compilerMap = util.switch()
291341 type :addGet (uri , source )
292342 m .setNode (source , type )
293343 end )
344+ : case ' doc.field'
345+ : call (function (source )
346+ m .setNode (source , m .compileNode (source .extends ))
347+ end )
294348 : getMap ()
295349
296350--- @param source parser.object
@@ -303,13 +357,18 @@ end
303357
304358--- @param source parser.object
305359local function compileByGlobal (source )
360+ if source .type == ' global' then
361+ m .setNode (source , source )
362+ return
363+ end
306364 if source ._globalNode then
307365 m .setNode (source , source ._globalNode )
308366 for _ , set in ipairs (source ._globalNode :getSets ()) do
309367 if set .value then
310368 m .setNode (source , m .compileNode (set .value ))
311369 end
312370 end
371+ return
313372 end
314373end
315374
@@ -320,8 +379,8 @@ function m.compileNode(source)
320379 return source ._node
321380 end
322381 source ._node = false
323- compileByNode (source )
324382 compileByGlobal (source )
383+ compileByNode (source )
325384
326385 localMgr .subscribeLocal (source , source ._node )
327386
0 commit comments