@@ -18,7 +18,7 @@ local vm = require 'vm.vm'
1818
1919local searchFieldSwitch = util .switch ()
2020 : case ' table'
21- : call (function (suri , source , key , pushResult )
21+ : call (function (suri , source , key , ref , pushResult )
2222 local hasFiled = false
2323 for _ , field in ipairs (source ) do
2424 if field .type == ' tablefield'
@@ -52,16 +52,16 @@ local searchFieldSwitch = util.switch()
5252 end
5353 end )
5454 : case ' string'
55- : call (function (suri , source , key , pushResult )
55+ : call (function (suri , source , key , ref , pushResult )
5656 -- change to `string: stringlib` ?
5757 local stringlib = globalMgr .getGlobal (' type' , ' stringlib' )
5858 if stringlib then
59- vm .getClassFields (suri , stringlib , key , pushResult )
59+ vm .getClassFields (suri , stringlib , key , ref , pushResult )
6060 end
6161 end )
6262 : case ' local'
6363 : case ' self'
64- : call (function (suri , node , key , pushResult )
64+ : call (function (suri , node , key , ref , pushResult )
6565 local fields
6666 if key then
6767 fields = localID .getSources (node , key )
@@ -70,12 +70,14 @@ local searchFieldSwitch = util.switch()
7070 end
7171 if fields then
7272 for _ , src in ipairs (fields ) do
73- pushResult (src )
73+ if ref or guide .isSet (src ) then
74+ pushResult (src )
75+ end
7476 end
7577 end
7678 end )
7779 : case ' doc.type.array'
78- : call (function (suri , source , key , pushResult )
80+ : call (function (suri , source , key , ref , pushResult )
7981 if type (key ) == ' number' then
8082 if key < 1
8183 or not math.tointeger (key ) then
@@ -85,7 +87,7 @@ local searchFieldSwitch = util.switch()
8587 pushResult (source .node )
8688 end )
8789 : case ' doc.type.table'
88- : call (function (suri , source , key , pushResult )
90+ : call (function (suri , source , key , ref , pushResult )
8991 for _ , field in ipairs (source .fields ) do
9092 local fieldKey = field .name
9193 if fieldKey .type == ' doc.type' then
@@ -111,7 +113,7 @@ local searchFieldSwitch = util.switch()
111113 end
112114 end )
113115 : case ' global'
114- : call (function (suri , node , key , pushResult )
116+ : call (function (suri , node , key , ref , pushResult )
115117 if node .cate == ' variable' then
116118 if key then
117119 if type (key ) ~= ' string' then
@@ -122,8 +124,10 @@ local searchFieldSwitch = util.switch()
122124 for _ , set in ipairs (global :getSets (suri )) do
123125 pushResult (set )
124126 end
125- for _ , get in ipairs (global :getGets (suri )) do
126- pushResult (get )
127+ if ref then
128+ for _ , get in ipairs (global :getGets (suri )) do
129+ pushResult (get )
130+ end
127131 end
128132 end
129133 else
@@ -132,17 +136,19 @@ local searchFieldSwitch = util.switch()
132136 for _ , set in ipairs (global :getSets (suri )) do
133137 pushResult (set )
134138 end
135- for _ , get in ipairs (global :getGets (suri )) do
136- pushResult (get )
139+ if ref then
140+ for _ , get in ipairs (global :getGets (suri )) do
141+ pushResult (get )
142+ end
137143 end
138144 end
139145 end
140146 end
141147 if node .cate == ' type' then
142- vm .getClassFields (suri , node , key , pushResult )
148+ vm .getClassFields (suri , node , key , ref , pushResult )
143149 end
144150 end )
145- : default (function (suri , source , key , pushResult )
151+ : default (function (suri , source , key , ref , pushResult )
146152 local node = source ._globalNode
147153 if not node then
148154 return
@@ -174,12 +180,12 @@ local searchFieldSwitch = util.switch()
174180 end
175181 end
176182 if node .cate == ' type' then
177- vm .getClassFields (suri , node , key , pushResult )
183+ vm .getClassFields (suri , node , key , ref , pushResult )
178184 end
179185 end )
180186
181187
182- function vm .getClassFields (suri , node , key , pushResult )
188+ function vm .getClassFields (suri , node , key , ref , pushResult )
183189 local mark = {}
184190
185191 local function searchClass (class , searchedFields )
@@ -206,7 +212,7 @@ function vm.getClassFields(suri, node, key, pushResult)
206212 -- check local field and global field
207213 if set .bindSources then
208214 for _ , src in ipairs (set .bindSources ) do
209- searchFieldSwitch (src .type , suri , src , key , function (field )
215+ searchFieldSwitch (src .type , suri , src , key , ref , function (field )
210216 local fieldKey = guide .getKeyName (field )
211217 if not searchedFields [fieldKey ]
212218 and guide .isSet (field ) then
@@ -215,7 +221,7 @@ function vm.getClassFields(suri, node, key, pushResult)
215221 end
216222 end )
217223 if src .value and src .value .type == ' table' then
218- searchFieldSwitch (' table' , suri , src .value , key , function (field )
224+ searchFieldSwitch (' table' , suri , src .value , key , ref , function (field )
219225 local fieldKey = guide .getKeyName (field )
220226 if not searchedFields [fieldKey ]
221227 and guide .isSet (field ) then
@@ -361,7 +367,7 @@ local function getReturnOfSetMetaTable(args)
361367 node :merge (vm .compileNode (tbl ))
362368 end
363369 if mt then
364- vm .compileByParentNode (mt , ' __index' , function (src )
370+ vm .compileByParentNode (mt , ' __index' , false , function (src )
365371 for n in vm .compileNode (src ):eachObject () do
366372 if n .type == ' global'
367373 or n .type == ' local'
@@ -529,11 +535,11 @@ end
529535--- @param source vm.node
530536--- @param key ? any
531537--- @param pushResult fun ( source : parser.object )
532- function vm .compileByParentNode (source , key , pushResult )
538+ function vm .compileByParentNode (source , key , ref , pushResult )
533539 local parentNode = vm .compileNode (source )
534540 local suri = guide .getUri (source )
535541 for node in parentNode :eachObject () do
536- searchFieldSwitch (node .type , suri , node , key , pushResult )
542+ searchFieldSwitch (node .type , suri , node , key , ref , pushResult )
537543 end
538544end
539545
@@ -903,7 +909,7 @@ local compilerSwitch = util.switch()
903909 if key == nil then
904910 return
905911 end
906- vm .compileByParentNode (source .node , key , function (src )
912+ vm .compileByParentNode (source .node , key , false , function (src )
907913 if src .type == ' doc.type.field'
908914 or src .type == ' doc.field' then
909915 vm .setNode (source , vm .compileNode (src ))
@@ -929,7 +935,7 @@ local compilerSwitch = util.switch()
929935 vm .setNode (source , value )
930936 end
931937 else
932- vm .compileByParentNode (source .node , key , function (src )
938+ vm .compileByParentNode (source .node , key , false , function (src )
933939 vm .setNode (source , vm .compileNode (src ))
934940 end )
935941 end
@@ -940,7 +946,7 @@ local compilerSwitch = util.switch()
940946 return
941947 end
942948 local key = guide .getKeyName (source )
943- vm .compileByParentNode (source .node , key , function (src )
949+ vm .compileByParentNode (source .node , key , false , function (src )
944950 if src .type == ' doc.type.field'
945951 or src .type == ' doc.field' then
946952 vm .setNode (source , vm .compileNode (src ))
@@ -953,7 +959,7 @@ local compilerSwitch = util.switch()
953959 return
954960 end
955961 local key = guide .getKeyName (source )
956- vm .compileByParentNode (source .node , key , function (src )
962+ vm .compileByParentNode (source .node , key , false , function (src )
957963 vm .setNode (source , vm .compileNode (src ))
958964 end )
959965 end )
@@ -976,7 +982,7 @@ local compilerSwitch = util.switch()
976982 end
977983
978984 if not hasMarkDoc then
979- vm .compileByParentNode (source .parent , guide .getKeyName (source ), function (src )
985+ vm .compileByParentNode (source .parent , guide .getKeyName (source ), false , function (src )
980986 vm .setNode (source , vm .compileNode (src ))
981987 end )
982988 end
0 commit comments