@@ -5,6 +5,7 @@ local rpath = require 'workspace.require-path'
55local files = require ' files'
66--- @class vm
77local vm = require ' vm.vm'
8+ local plugin = require ' plugin'
89
910--- @class parser.object
1011--- @field _compiledNodes boolean
@@ -1030,6 +1031,55 @@ local function compileForVars(source, target)
10301031 return false
10311032end
10321033
1034+ --- @param source parser.object
1035+ local function compileFunctionParam (func , source )
1036+ -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
1037+ local funcNode = vm .compileNode (func )
1038+ for n in funcNode :eachObject () do
1039+ if n .type == ' doc.type.function' then
1040+ for index , arg in ipairs (n .args ) do
1041+ if func .args [index ] == source then
1042+ local argNode = vm .compileNode (arg )
1043+ for an in argNode :eachObject () do
1044+ if an .type ~= ' doc.generic.name' then
1045+ vm .setNode (source , an )
1046+ end
1047+ end
1048+ return true
1049+ end
1050+ end
1051+ end
1052+ end
1053+ if func .parent .type == ' local' then
1054+ local refs = func .parent .ref
1055+ local findCall
1056+ if refs then
1057+ for i , ref in ipairs (refs ) do
1058+ if ref .parent .type == ' call' then
1059+ findCall = ref .parent
1060+ break
1061+ end
1062+ end
1063+ end
1064+ if findCall and findCall .args then
1065+ local index
1066+ for i , arg in ipairs (source .parent ) do
1067+ if arg == source then
1068+ index = i
1069+ break
1070+ end
1071+ end
1072+ if index then
1073+ local callerArg = findCall .args [index ]
1074+ if callerArg then
1075+ vm .setNode (source , vm .compileNode (callerArg ))
1076+ return true
1077+ end
1078+ end
1079+ end
1080+ end
1081+ end
1082+
10331083--- @param source parser.object
10341084local function compileLocal (source )
10351085 local myNode = vm .setNode (source , source )
@@ -1069,56 +1119,11 @@ local function compileLocal(source)
10691119 vm .setNode (source , vm .compileNode (setfield .node ))
10701120 end
10711121 end
1072-
10731122 if source .parent .type == ' funcargs' and not hasMarkDoc and not hasMarkParam then
10741123 local func = source .parent .parent
1075- -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
1076- local funcNode = vm .compileNode (func )
1077- local hasDocArg
1078- for n in funcNode :eachObject () do
1079- if n .type == ' doc.type.function' then
1080- for index , arg in ipairs (n .args ) do
1081- if func .args [index ] == source then
1082- local argNode = vm .compileNode (arg )
1083- for an in argNode :eachObject () do
1084- if an .type ~= ' doc.generic.name' then
1085- vm .setNode (source , an )
1086- end
1087- end
1088- hasDocArg = true
1089- end
1090- end
1091- end
1092- end
1093- if not hasDocArg
1094- and func .parent .type == ' local' then
1095- local refs = func .parent .ref
1096- local findCall
1097- if refs then
1098- for i , ref in ipairs (refs ) do
1099- if ref .parent .type == ' call' then
1100- findCall = ref .parent
1101- break
1102- end
1103- end
1104- end
1105- if findCall and findCall .args then
1106- local index
1107- for i , arg in ipairs (source .parent ) do
1108- if arg == source then
1109- index = i
1110- break
1111- end
1112- end
1113- if index then
1114- local callerArg = findCall .args [index ]
1115- if callerArg then
1116- hasDocArg = true
1117- vm .setNode (source , vm .compileNode (callerArg ))
1118- end
1119- end
1120- end
1121- end
1124+ local vmPlugin = plugin .getVmPlugin (guide .getUri (source ))
1125+ local hasDocArg = vmPlugin and vmPlugin .OnCompileFunctionParam (compileFunctionParam , func , source )
1126+ or compileFunctionParam (func , source )
11221127 if not hasDocArg then
11231128 vm .setNode (source , vm .declareGlobal (' type' , ' any' ))
11241129 end
0 commit comments