@@ -20,110 +20,6 @@ simpleSwitch = util.switch()
2020 end
2121 end )
2222
23- local searchFieldSwitch = util .switch ()
24- : case ' table'
25- : call (function (suri , obj , key , pushResult )
26- for _ , field in ipairs (obj ) do
27- if field .type == ' tablefield'
28- or field .type == ' tableindex' then
29- if guide .getKeyName (field ) == key then
30- pushResult (field )
31- end
32- end
33- end
34- end )
35- : case ' global'
36- --- @param obj vm.global
37- --- @param key string
38- : call (function (suri , obj , key , pushResult )
39- if obj .cate == ' variable' then
40- local newGlobal = vm .getGlobal (' variable' , obj .name , key )
41- if newGlobal then
42- for _ , set in ipairs (newGlobal :getSets (suri )) do
43- pushResult (set )
44- end
45- end
46- end
47- if obj .cate == ' type' then
48- vm .getClassFields (suri , obj , key , false , pushResult )
49- end
50- end )
51- : case ' local'
52- : call (function (suri , obj , key , pushResult )
53- local sources = vm .getLocalSourcesSets (obj , key )
54- if sources then
55- for _ , src in ipairs (sources ) do
56- pushResult (src )
57- end
58- end
59- end )
60- : case ' doc.type.table'
61- : call (function (suri , obj , key , pushResult )
62- for _ , field in ipairs (obj .fields ) do
63- local fieldKey = field .name
64- if fieldKey .type == ' doc.field.name' then
65- if fieldKey [1 ] == key then
66- pushResult (field )
67- end
68- end
69- end
70- end )
71-
72- local nodeSwitch ;nodeSwitch = util .switch ()
73- : case ' field'
74- : case ' method'
75- : call (function (source , lastKey , pushResult )
76- return nodeSwitch (source .parent .type , source .parent , lastKey , pushResult )
77- end )
78- : case ' getfield'
79- : case ' setfield'
80- : case ' getmethod'
81- : case ' setmethod'
82- : case ' getindex'
83- : case ' setindex'
84- : call (function (source , lastKey , pushResult )
85- local parentNode = vm .compileNode (source .node )
86- local uri = guide .getUri (source )
87- local key = guide .getKeyName (source )
88- if type (key ) ~= ' string' then
89- return
90- end
91- if lastKey then
92- key = key .. vm .ID_SPLITE .. lastKey
93- end
94- for pn in parentNode :eachObject () do
95- searchFieldSwitch (pn .type , uri , pn , key , pushResult )
96- end
97- return key , source .node
98- end )
99- : case ' tableindex'
100- : case ' tablefield'
101- : call (function (source , lastKey , pushResult )
102- if lastKey then
103- return
104- end
105- local key = guide .getKeyName (source )
106- if type (key ) ~= ' string' then
107- return
108- end
109- local uri = guide .getUri (source )
110- local parentNode = vm .compileNode (source .node )
111- for pn in parentNode :eachObject () do
112- searchFieldSwitch (pn .type , uri , pn , key , pushResult )
113- end
114- end )
115- : case ' doc.see.field'
116- : call (function (source , lastKey , pushResult )
117- if lastKey then
118- return
119- end
120- local parentNode = vm .compileNode (source .parent .name )
121- local uri = guide .getUri (source )
122- for pn in parentNode :eachObject () do
123- searchFieldSwitch (pn .type , uri , pn , source [1 ], pushResult )
124- end
125- end )
126-
12723--- @param source parser.object
12824--- @param pushResult fun ( src : parser.object )
12925local function searchBySimple (source , pushResult )
@@ -142,25 +38,6 @@ local function searchByLocalID(source, pushResult)
14238 end
14339end
14440
145- --- @param source parser.object
146- --- @param pushResult fun ( src : parser.object )
147- local function searchByParentNode (source , pushResult )
148- local lastKey
149- local src = source
150- while true do
151- local key , node = nodeSwitch (src .type , src , lastKey , pushResult )
152- if not key then
153- break
154- end
155- src = node
156- if lastKey then
157- lastKey = key .. vm .ID_SPLITE .. lastKey
158- else
159- lastKey = key
160- end
161- end
162- end
163-
16441local function searchByNode (source , pushResult )
16542 local node = vm .compileNode (source )
16643 local suri = guide .getUri (source )
@@ -200,7 +77,7 @@ function vm.getDefs(source)
20077
20178 searchBySimple (source , pushResult )
20279 searchByLocalID (source , pushResult )
203- searchByParentNode (source , pushResult )
80+ vm . compileByNodeChain (source , pushResult )
20481 searchByNode (source , pushResult )
20582
20683 return results
0 commit comments