File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44<!-- Add all new changes here. They will be moved under a version at release -->
5+ * ` NEW ` using ` enum (partial) ` , it suggests all fields with the same ` enum ` type rather than just the fields from the current table.
6+ * ` NEW ` When using ` enum["<key>" or <index>] ` , undefined fields will raise an 'undefined' error.
57* ` FIX ` Renaming files in the directory leads to the auto-correction in "require" adding extra characters.
68
79## 3.10.4
Original file line number Diff line number Diff line change @@ -52,6 +52,39 @@ return function (uri, callback)
5252 }
5353 end
5454 end
55+ --- @async
56+ local function checkUndefinedFieldByIndexEnum (src )
57+ await .delay ()
58+ local isEnum = false
59+ for _ , node in ipairs (vm .compileNode (src .node )) do
60+ local docs = node .bindDocs
61+ if docs then
62+ for _ , doc in ipairs (docs ) do
63+ if doc .type == " doc.enum" then
64+ isEnum = true
65+ break
66+ end
67+ end
68+ end
69+ end
70+ if not isEnum then
71+ return
72+ end
73+ if vm .hasDef (src ) then
74+ return
75+ end
76+ local keyName = guide .getKeyName (src )
77+ if not keyName then
78+ return
79+ end
80+ local message = lang .script (' DIAG_UNDEF_FIELD' , guide .getKeyName (src ))
81+ callback {
82+ start = src .index .start ,
83+ finish = src .index .finish ,
84+ message = message ,
85+ }
86+ end
5587 guide .eachSourceType (ast .ast , ' getfield' , checkUndefinedField )
5688 guide .eachSourceType (ast .ast , ' getmethod' , checkUndefinedField )
89+ guide .eachSourceType (ast .ast , ' getindex' , checkUndefinedFieldByIndexEnum )
5790end
Original file line number Diff line number Diff line change @@ -189,6 +189,41 @@ local searchFieldSwitch = util.switch()
189189 end
190190 end
191191 end
192+ local docs = source .bindDocs
193+ if docs then
194+ for _ , doc in ipairs (docs ) do
195+ if doc .type == ' doc.enum' then
196+ if not vm .docHasAttr (doc , ' partial' ) then
197+ return
198+ end
199+ for _ , def in ipairs (vm .getDefs (doc )) do
200+ if def .type ~= ' doc.enum' then
201+ goto CONTINUE
202+ end
203+ local tbl = def .bindSource
204+ if not tbl then
205+ return
206+ end
207+ for _ , field in ipairs (tbl ) do
208+ if field .type == ' tablefield'
209+ or field .type == ' tableindex' then
210+ if not field .value then
211+ goto CONTINUE
212+ end
213+ local fieldKey = guide .getKeyName (field )
214+ if key == vm .ANY
215+ or key == fieldKey then
216+ hasFiled = true
217+ pushResult (field )
218+ end
219+ :: CONTINUE::
220+ end
221+ end
222+ :: CONTINUE::
223+ end
224+ end
225+ end
226+ end
192227 end )
193228 : case ' string'
194229 : case ' doc.type.string'
You can’t perform that action at this time.
0 commit comments