summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-09-05 18:30:17 +0800
committerGitHub <noreply@github.com>2024-09-05 18:30:17 +0800
commit08dd0ca8956c8ca53876a95142b4531e454c9e48 (patch)
tree291372055a8523f5f49c583a31eb1e4e7725b322
parent5083f1cd9438da23f1022327ea24e7044bcc2f49 (diff)
parent36fe74925b83a59dca318b8fc2fdd6f815ca0f10 (diff)
downloadlua-language-server-08dd0ca8956c8ca53876a95142b4531e454c9e48.zip
Merge pull request #2834 from Wild-W/fix-vm-plugins
Fix VM plugins
-rw-r--r--changelog.md1
-rw-r--r--script/plugin.lua52
-rw-r--r--script/vm/compiler.lua15
-rw-r--r--test/plugins/node/test.lua6
-rw-r--r--test/type_inference/init.lua2
5 files changed, 18 insertions, 58 deletions
diff --git a/changelog.md b/changelog.md
index 18c85610..bfd1f467 100644
--- a/changelog.md
+++ b/changelog.md
@@ -4,6 +4,7 @@
<!-- Add all new changes here. They will be moved under a version at release -->
* `NEW` Custom documentation exporter
* `NEW` Setting: `Lua.docScriptPath`: Path to a script that overrides `cli.doc.export`, allowing user-specified documentation exporting.
+* `FIX` Fix `VM.OnCompileFunctionParam` function in plugins
* `FIX` Lua 5.1: fix incorrect warning when using setfenv with an int as first parameter
## 3.10.5
diff --git a/script/plugin.lua b/script/plugin.lua
index ec55875e..f2a108fa 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -7,15 +7,6 @@ local scope = require 'workspace.scope'
local ws = require 'workspace'
local fs = require 'bee.filesystem'
----@class pluginInterfaces
-local pluginConfigs = {
- -- create plugin for vm module
- VM = {
- OnCompileFunctionParam = function (next, func, source)
- end
- }
-}
-
---@class plugin
local m = {}
@@ -60,14 +51,13 @@ function m.dispatch(event, uri, ...)
return failed == 0, res1, res2
end
-function m.getVmPlugin(uri)
+function m.getPluginInterfaces(uri)
local scp = scope.getScope(uri)
- ---@type pluginInterfaces
local interfaces = scp:get('pluginInterfaces')
if not interfaces then
return
end
- return interfaces.VM
+ return interfaces
end
---@async
@@ -100,40 +90,6 @@ local function checkTrustLoad(scp)
return true
end
-local function createMethodGroup(interfaces, key, methods)
- local methodGroup = {}
-
- for method in pairs(methods) do
- local funcs = setmetatable({}, {
- __call = function (t, next, ...)
- if #t == 0 then
- return next(...)
- else
- local result
- for _, fn in ipairs(t) do
- result = fn(next, ...)
- end
- return result
- end
- end
- })
- for _, interface in ipairs(interfaces) do
- local func = interface[method]
- if not func then
- local namespace = interface[key]
- if namespace then
- func = namespace[method]
- end
- end
- if func then
- funcs[#funcs+1] = func
- end
- end
- methodGroup[method] = funcs
- end
- return #methodGroup>0 and methodGroup or nil
-end
-
---@param uri uri
local function initPlugin(uri)
await.call(function () ---@async
@@ -206,10 +162,6 @@ local function initPlugin(uri)
interfaces[#interfaces+1] = interface
end
- for key, config in pairs(pluginConfigs) do
- interfaces[key] = createMethodGroup(interfaces, key, config)
- end
-
ws.resetFiles(scp)
end)
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 5f3317b9..deab2033 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1385,10 +1385,17 @@ local function compileLocal(source)
end
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
local func = source.parent.parent
- local vmPlugin = plugin.getVmPlugin(guide.getUri(source))
- local hasDocArg = vmPlugin and vmPlugin.OnCompileFunctionParam(compileFunctionParam, func, source)
- or compileFunctionParam(func, source)
- if not hasDocArg then
+ local interfaces = plugin.getPluginInterfaces(guide.getUri(source))
+ local hasDocArg = false
+ if interfaces then
+ for _, interface in ipairs(interfaces) do
+ if interface.VM then
+ hasDocArg = interface.VM.OnCompileFunctionParam(compileFunctionParam, func, source)
+ if hasDocArg then break end
+ end
+ end
+ end
+ if not hasDocArg and not compileFunctionParam(func, source) then
vm.setNode(source, vm.declareGlobal('type', 'any'))
end
end
diff --git a/test/plugins/node/test.lua b/test/plugins/node/test.lua
index 15e4d16c..9b69935f 100644
--- a/test/plugins/node/test.lua
+++ b/test/plugins/node/test.lua
@@ -30,10 +30,10 @@ local function TestPlugin(script)
---@field b string
]]
---@param checker fun(state:parser.state)
- return function (plugin, checker)
+ return function (interfaces, checker)
files.open(TESTURI)
files.setText(TESTURI, prefix .. script, true)
- scope.getScope(TESTURI):set('pluginInterfaces', plugin)
+ scope.getScope(TESTURI):set('pluginInterfaces', interfaces)
local state = files.getState(TESTURI)
assert(state)
checker(state)
@@ -45,7 +45,7 @@ TestPlugin [[
local function t(a)
a.components:test()
end
-]](myplugin, function (state)
+]]({ myplugin }, function (state)
guide.eachSourceType(state.ast, 'local', function (src)
if guide.getKeyName(src) == 'a' then
local node = vm.compileNode(src)
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 35900bc3..4eaad03d 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -39,7 +39,7 @@ function TEST(wanted)
if wanted ~= result then
vm.getInfer(source):view(TESTURI)
end
- assert(wanted == result)
+ assert(wanted == result, "Assertion failed! Wanted: " .. tostring(wanted) .. " Got: " .. tostring(result))
files.remove(TESTURI)
end
end