@@ -16,69 +16,86 @@ return function (uri, callback)
1616 await .delay ()
1717
1818 local defs = vm .getDefs (src )
19+ local sortedDefs = {}
1920 for _ , def in ipairs (defs ) do
20- if def .type == ' doc.class' and def . bindSource then
21- if guide .isInRange (def .bindSource , src .start ) then
21+ if def .type == ' doc.class' then
22+ if def . bindSource and guide .isInRange (def .bindSource , src .start ) then
2223 return
2324 end
25+ if not sortedDefs [def .class [1 ]] then
26+ sortedDefs [def .class [1 ]] = {}
27+ end
28+ local samedefs = sortedDefs [def .class [1 ]]
29+ samedefs [# samedefs + 1 ] = def
2430 end
2531 if def .type == ' doc.type.array'
2632 or def .type == ' doc.type.table' then
2733 return
2834 end
2935 end
30- local warnings = {}
31- for _ , def in ipairs (defs ) do
32- if def .type == ' doc.class' then
33- if not def .fields then
34- return
35- end
36+
37+ local Allwarnings = {}
38+ for _ , samedefs in pairs (sortedDefs ) do
39+ local warnings = {}
40+ for _ , def in ipairs (samedefs ) do
41+ if def .type == ' doc.class' then
42+ if not def .fields then
43+ goto continue
44+ end
3645
37- local requiresKeys = {}
38- for _ , field in ipairs (def .fields ) do
39- if not field .optional
40- and not vm .compileNode (field ):isNullable () then
46+ local requiresKeys = {}
47+ for _ , field in ipairs (def .fields ) do
48+ if not field .optional
49+ and not vm .compileNode (field ):isNullable () then
50+ local key = vm .getKeyName (field )
51+ if key and not requiresKeys [key ] then
52+ requiresKeys [key ] = true
53+ requiresKeys [# requiresKeys + 1 ] = key
54+ end
55+ end
56+ end
57+
58+ if # requiresKeys == 0 then
59+ goto continue
60+ end
61+ local myKeys = {}
62+ for _ , field in ipairs (src ) do
4163 local key = vm .getKeyName (field )
42- if key and not requiresKeys [key ] then
43- requiresKeys [key ] = true
44- requiresKeys [# requiresKeys + 1 ] = key
64+ if key then
65+ myKeys [key ] = true
4566 end
4667 end
47- end
4868
49- if # requiresKeys == 0 then
50- return
51- end
52- local myKeys = {}
53- for _ , field in ipairs (src ) do
54- local key = vm .getKeyName (field )
55- if key then
56- myKeys [key ] = true
69+ local missedKeys = {}
70+ for _ , key in ipairs (requiresKeys ) do
71+ if not myKeys [key ] then
72+ missedKeys [# missedKeys + 1 ] = (' `%s`' ):format (key )
73+ end
5774 end
58- end
5975
60- local missedKeys = {}
61- for _ , key in ipairs (requiresKeys ) do
62- if not myKeys [key ] then
63- missedKeys [# missedKeys + 1 ] = (' `%s`' ):format (key )
76+ if # missedKeys == 0 then
77+ goto continue
6478 end
65- end
6679
67- if # missedKeys == 0 then
68- return
80+ warnings [# warnings + 1 ] = lang .script (' DIAG_MISSING_FIELDS' , def .class [1 ], table.concat (missedKeys , ' , ' ))
81+ end
82+ :: continue::
83+ end
84+ if # warnings == 0 then
85+ return
86+ else
87+ for i = 1 , # warnings do
88+ Allwarnings [# Allwarnings + 1 ] = warnings [i ]
6989 end
70-
71- warnings [# warnings + 1 ] = lang .script (' DIAG_MISSING_FIELDS' , def .class [1 ], table.concat (missedKeys , ' , ' ))
7290 end
7391 end
74-
75- if # warnings == 0 then
92+ if # Allwarnings == 0 then
7693 return
7794 end
7895 callback {
7996 start = src .start ,
8097 finish = src .finish ,
81- message = table.concat (warnings , ' \n ' )
98+ message = table.concat (Allwarnings , ' \n ' )
8299 }
83100 end )
84101end
0 commit comments