diff options
author | Connor Bren <wildweegee101@gmail.com> | 2024-08-29 21:49:38 -0600 |
---|---|---|
committer | Connor Bren <wildweegee101@gmail.com> | 2024-08-29 21:49:38 -0600 |
commit | b871eb6fa4dfa2edc01ba871b3890bfa01206a93 (patch) | |
tree | 406988777a64c1bc58a415dae0686ccc4b4b2575 | |
parent | eb0bf985b4b22e529cfb75b88d7e8c6814acacea (diff) | |
download | lua-language-server-b871eb6fa4dfa2edc01ba871b3890bfa01206a93.zip |
fix VM plugins
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/plugin.lua | 52 | ||||
-rw-r--r-- | script/vm/compiler.lua | 15 | ||||
-rw-r--r-- | test/plugins/node/test.lua | 6 | ||||
-rw-r--r-- | test/type_inference/init.lua | 2 |
5 files changed, 18 insertions, 58 deletions
diff --git a/changelog.md b/changelog.md index dd5dd5c4..23e52d48 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 ## 3.10.5 `2024-8-19` 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 |