@@ -513,217 +513,6 @@ function vm.getClassFields(suri, object, key, pushResult)
513513 searchGlobal (object )
514514end
515515
516- --- for exporting, only gets unique, noninherited fields
517- --- @param suri uri
518- --- @param object vm.global
519- --- @param key string | number | integer | boolean | vm.global | vm.ANY
520- --- @param pushResult fun ( field : vm.object | vm.global , isMark ?: boolean , discardParentFields ?: boolean )
521- function vm .getSimpleClassFields (suri , object , key , pushResult )
522- local mark = {}
523- local function searchClass (class , searchedFields , discardParentFields )
524- local name = class .name
525- if mark [name ] then
526- return
527- end
528- mark [name ] = true
529- searchedFields = searchedFields or {}
530- searchedFields [1 ] = searchedFields [1 ] or {}
531- searchedFields [name ] = searchedFields [name ] or {}
532- local function uniqueOrOverrideField (fieldKey )
533- if (class == object ) then
534- -- search only this class's tree if end of branch
535- return not searchedFields [name ][fieldKey ]
536- else
537- -- search whole tree
538- return not searchedFields [1 ][fieldKey ]
539- end
540- end
541-
542- local hasFounded = {}
543- local function copyToSearched ()
544- for fieldKey in pairs (hasFounded ) do
545- searchedFields [name ][fieldKey ] = true
546- searchedFields [1 ][fieldKey ] = true
547- hasFounded [fieldKey ] = nil
548- end
549- end
550-
551- local sets = class :getSets (suri )
552- -- go fully up the class tree first and exhaust it all
553- for _ , set in ipairs (sets ) do
554- if set .type == ' doc.class' then
555- -- look into extends(if field not found)
556- if not searchedFields [key ] and set .extends then
557- for _ , extend in ipairs (set .extends ) do
558- if extend .type == ' doc.extends.name' then
559- local extendType = vm .getGlobal (' type' , extend [1 ])
560- if extendType then
561- pushResult (extendType , true , false )
562- searchClass (extendType , searchedFields , true )
563- end
564- end
565- end
566- end
567- end
568- end
569- copyToSearched ()
570-
571- for _ , set in ipairs (sets ) do
572- if set .type == ' doc.class' then
573- -- check ---@field
574- for _ , field in ipairs (set .fields ) do
575- local fieldKey = guide .getKeyName (field )
576- if fieldKey then
577- -- ---@field x boolean -> class.x
578- if key == vm .ANY
579- or fieldKey == key then
580- if uniqueOrOverrideField (fieldKey ) then
581- pushResult (field , true , discardParentFields )
582- hasFounded [fieldKey ] = true
583- end
584- end
585- goto CONTINUE
586- end
587- if key == vm .ANY then
588- pushResult (field , true , discardParentFields )
589- goto CONTINUE
590- end
591- if hasFounded [key ] then
592- goto CONTINUE
593- end
594- local keyType = type (key )
595- if keyType == ' table' then
596- -- ---@field [integer] boolean -> class[integer]
597- local fieldNode = vm .compileNode (field .field )
598- if vm .isSubType (suri , key .name , fieldNode ) then
599- local nkey = ' |' .. key .name
600- if uniqueOrOverrideField (nkey ) then
601- pushResult (field , true , discardParentFields )
602- hasFounded [nkey ] = true
603- end
604- end
605- else
606- local keyObject
607- if keyType == ' number' then
608- if math.tointeger (key ) then
609- keyObject = { type = ' integer' , [1 ] = key }
610- else
611- keyObject = { type = ' number' , [1 ] = key }
612- end
613- elseif keyType == ' boolean'
614- or keyType == ' string' then
615- keyObject = { type = keyType , [1 ] = key }
616- end
617- if keyObject and field .field .type ~= ' doc.field.name' then
618- -- ---@field [integer] boolean -> class[1]
619- local fieldNode = vm .compileNode (field .field )
620- if vm .isSubType (suri , keyObject , fieldNode ) then
621- local nkey = ' |' .. keyType
622- if uniqueOrOverrideField (nkey ) then
623- pushResult (field , true , discardParentFields )
624- hasFounded [nkey ] = true
625- end
626- end
627- end
628- end
629- :: CONTINUE::
630- end
631- end
632- end
633- copyToSearched ()
634-
635- for _ , set in ipairs (sets ) do
636- if set .type == ' doc.class' then
637- -- check local field and global field
638- if uniqueOrOverrideField (key ) and set .bindSource then
639- local src = set .bindSource
640- if src .value and src .value .type == ' table' then
641- searchFieldSwitch (' table' , suri , src .value , key , function (field )
642- local fieldKey = guide .getKeyName (field )
643- if fieldKey then
644- if uniqueOrOverrideField (fieldKey )
645- and guide .isAssign (field ) then
646- hasFounded [fieldKey ] = true
647- pushResult (field , true , discardParentFields )
648- end
649- end
650- end )
651- end
652- if src .value
653- and src .value .type == ' select'
654- and src .value .vararg .type == ' call' then
655- local func = src .value .vararg .node
656- local args = src .value .vararg .args
657- if func .special == ' setmetatable'
658- and args
659- and args [1 ]
660- and args [1 ].type == ' table' then
661- searchFieldSwitch (' table' , suri , args [1 ], key , function (field )
662- local fieldKey = guide .getKeyName (field )
663- if fieldKey then
664- if uniqueOrOverrideField (fieldKey )
665- and guide .isAssign (field ) then
666- hasFounded [fieldKey ] = true
667- pushResult (field , true , discardParentFields )
668- end
669- end
670- end )
671- end
672- end
673- end
674- end
675- end
676- copyToSearched ()
677-
678- for _ , set in ipairs (sets ) do
679- if set .type == ' doc.class' then
680- if uniqueOrOverrideField (key ) and set .bindSource then
681- local src = set .bindSource
682- searchFieldSwitch (src .type , suri , src , key , function (field )
683- local fieldKey = guide .getKeyName (field )
684- if fieldKey and uniqueOrOverrideField (fieldKey ) then
685- if uniqueOrOverrideField (fieldKey )
686- and guide .isAssign (field )
687- and field .value then
688- if vm .getVariableID (field )
689- and vm .getVariableID (field ) == vm .getVariableID (field .value ) then
690- elseif vm .getGlobalNode (src )
691- and vm .getGlobalNode (src ) == vm .getGlobalNode (field .value ) then
692- else
693- hasFounded [fieldKey ] = true
694- end
695- pushResult (field , true , discardParentFields )
696- end
697- end
698- end )
699- end
700- end
701- end
702- copyToSearched ()
703- end
704-
705- local function searchGlobal (class )
706- if class .cate == ' type' and class .name == ' _G' then
707- if key == vm .ANY then
708- local sets = vm .getGlobalSets (suri , ' variable' )
709- for _ , set in ipairs (sets ) do
710- pushResult (set )
711- end
712- elseif type (key ) == ' string' then
713- local global = vm .getGlobal (' variable' , key )
714- if global then
715- for _ , set in ipairs (global :getSets (suri )) do
716- pushResult (set )
717- end
718- end
719- end
720- end
721- end
722-
723- searchClass (object )
724- searchGlobal (object )
725- end
726-
727516--- @param func parser.object
728517--- @param index integer
729518--- @return (parser.object | vm.generic )?
@@ -1316,7 +1105,7 @@ local function compileFunctionParam(func, source)
13161105 end
13171106 end
13181107 end
1319-
1108+
13201109 local derviationParam = config .get (guide .getUri (func ), ' Lua.type.inferParamType' )
13211110 if derviationParam and func .parent .type == ' local' and func .parent .ref then
13221111 local refs = func .parent .ref
0 commit comments