Skip to content

Commit 08dd0ca

Browse files
authored
Merge pull request #2834 from Wild-W/fix-vm-plugins
Fix VM plugins
2 parents 5083f1c + 36fe749 commit 08dd0ca

File tree

5 files changed

+18
-58
lines changed

5 files changed

+18
-58
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `NEW` Custom documentation exporter
66
* `NEW` Setting: `Lua.docScriptPath`: Path to a script that overrides `cli.doc.export`, allowing user-specified documentation exporting.
7+
* `FIX` Fix `VM.OnCompileFunctionParam` function in plugins
78
* `FIX` Lua 5.1: fix incorrect warning when using setfenv with an int as first parameter
89

910
## 3.10.5

script/plugin.lua

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ local scope = require 'workspace.scope'
77
local ws = require 'workspace'
88
local fs = require 'bee.filesystem'
99

10-
---@class pluginInterfaces
11-
local pluginConfigs = {
12-
-- create plugin for vm module
13-
VM = {
14-
OnCompileFunctionParam = function (next, func, source)
15-
end
16-
}
17-
}
18-
1910
---@class plugin
2011
local m = {}
2112

@@ -60,14 +51,13 @@ function m.dispatch(event, uri, ...)
6051
return failed == 0, res1, res2
6152
end
6253

63-
function m.getVmPlugin(uri)
54+
function m.getPluginInterfaces(uri)
6455
local scp = scope.getScope(uri)
65-
---@type pluginInterfaces
6656
local interfaces = scp:get('pluginInterfaces')
6757
if not interfaces then
6858
return
6959
end
70-
return interfaces.VM
60+
return interfaces
7161
end
7262

7363
---@async
@@ -100,40 +90,6 @@ local function checkTrustLoad(scp)
10090
return true
10191
end
10292

103-
local function createMethodGroup(interfaces, key, methods)
104-
local methodGroup = {}
105-
106-
for method in pairs(methods) do
107-
local funcs = setmetatable({}, {
108-
__call = function (t, next, ...)
109-
if #t == 0 then
110-
return next(...)
111-
else
112-
local result
113-
for _, fn in ipairs(t) do
114-
result = fn(next, ...)
115-
end
116-
return result
117-
end
118-
end
119-
})
120-
for _, interface in ipairs(interfaces) do
121-
local func = interface[method]
122-
if not func then
123-
local namespace = interface[key]
124-
if namespace then
125-
func = namespace[method]
126-
end
127-
end
128-
if func then
129-
funcs[#funcs+1] = func
130-
end
131-
end
132-
methodGroup[method] = funcs
133-
end
134-
return #methodGroup>0 and methodGroup or nil
135-
end
136-
13793
---@param uri uri
13894
local function initPlugin(uri)
13995
await.call(function () ---@async
@@ -206,10 +162,6 @@ local function initPlugin(uri)
206162
interfaces[#interfaces+1] = interface
207163
end
208164

209-
for key, config in pairs(pluginConfigs) do
210-
interfaces[key] = createMethodGroup(interfaces, key, config)
211-
end
212-
213165
ws.resetFiles(scp)
214166
end)
215167
end

script/vm/compiler.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,10 +1385,17 @@ local function compileLocal(source)
13851385
end
13861386
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
13871387
local func = source.parent.parent
1388-
local vmPlugin = plugin.getVmPlugin(guide.getUri(source))
1389-
local hasDocArg = vmPlugin and vmPlugin.OnCompileFunctionParam(compileFunctionParam, func, source)
1390-
or compileFunctionParam(func, source)
1391-
if not hasDocArg then
1388+
local interfaces = plugin.getPluginInterfaces(guide.getUri(source))
1389+
local hasDocArg = false
1390+
if interfaces then
1391+
for _, interface in ipairs(interfaces) do
1392+
if interface.VM then
1393+
hasDocArg = interface.VM.OnCompileFunctionParam(compileFunctionParam, func, source)
1394+
if hasDocArg then break end
1395+
end
1396+
end
1397+
end
1398+
if not hasDocArg and not compileFunctionParam(func, source) then
13921399
vm.setNode(source, vm.declareGlobal('type', 'any'))
13931400
end
13941401
end

test/plugins/node/test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ local function TestPlugin(script)
3030
---@field b string
3131
]]
3232
---@param checker fun(state:parser.state)
33-
return function (plugin, checker)
33+
return function (interfaces, checker)
3434
files.open(TESTURI)
3535
files.setText(TESTURI, prefix .. script, true)
36-
scope.getScope(TESTURI):set('pluginInterfaces', plugin)
36+
scope.getScope(TESTURI):set('pluginInterfaces', interfaces)
3737
local state = files.getState(TESTURI)
3838
assert(state)
3939
checker(state)
@@ -45,7 +45,7 @@ TestPlugin [[
4545
local function t(a)
4646
a.components:test()
4747
end
48-
]](myplugin, function (state)
48+
]]({ myplugin }, function (state)
4949
guide.eachSourceType(state.ast, 'local', function (src)
5050
if guide.getKeyName(src) == 'a' then
5151
local node = vm.compileNode(src)

test/type_inference/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function TEST(wanted)
3939
if wanted ~= result then
4040
vm.getInfer(source):view(TESTURI)
4141
end
42-
assert(wanted == result)
42+
assert(wanted == result, "Assertion failed! Wanted: " .. tostring(wanted) .. " Got: " .. tostring(result))
4343
files.remove(TESTURI)
4444
end
4545
end

0 commit comments

Comments
 (0)