Skip to content

VM.OnCompileFunctionParam does not work at all #3343

Open

Description

@LJSonik

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Plugins

Expected Behaviour

According to https://luals.github.io/wiki/plugins/#vmoncompilefunctionparam, VM.OnCompileFunctionParam() is supposed to work.

Actual Behaviour

It simply does not work, and throws this error instead:

2026-01-28 20:58:08.342 [info] C:\Path\plugin.lua:4: attempt to index a nil value (global 'VM')
stack traceback:
	C:\Path\plugin.lua:4: in main chunk
	[C]: in global 'xpcall'
	script\plugin.lua:157: in function <script\plugin.lua:95>

2026-01-28 20:58:08.348 [info] [Error - 8:58:08 PM] An error occurred in the plugin, please report it to the plugin author.
Please check the details in the output or log.
Plugin path: C:\Path\plugin.lua

Reproduction steps

  1. Write function VM.OnCompileFunctionParam(next, func, param) end in plugin.lua
  2. Add "Lua.runtime.plugin": "C:/Path/plugin.lua" to .vscode/settings.json or similar
  3. The error happens

Additional Notes

Please note that OnSetText() works as advertised, so the plugin system works; it is only this specific feature that does not seem to be working correctly.

For context, my library has JS-style event callbacks that work roughly like this:

addHook("PlayerUpdate", function(player)
end)

As you probably guessed already, I was hoping to use VM.OnCompileFunctionParam() to make it detect the parameter's type without requiring explicitly annotations, since generics do not seem to support this pattern at the moment?
I could also use OnSetText() instead, but it sounds like a less reliable method as it depends on the formatting, and it would also cause a warning about duplicate annotations if the user typed the ---@param explicitly.

Log File

No response

Activity

  1. LJSonik commented on Jan 28, 2026

    @LJSonik
    Author

    My apologies, after fiddling around with the extension's code for a while, I realised all I had to do was define VM = {} manually, like this:

    VM = {}
    
    local hookParamTypes = {
    	PlayerUpdate = { "Player", "float" },
    }
    
    function VM.OnCompileFunctionParam(next, hookCallback, hookParam)
    	if next(hookCallback, hookParam) then return true end
    
    	local addHookArgs = hookCallback.parent
    	if addHookArgs.type ~= "callargs" then return end
    
    	local addHookCall = addHookArgs.parent
    	local addHookName = addHookCall.node[1]
    	if addHookName ~= "addHook" then return end
    
    	if addHookArgs[1].type ~= "string" then return end
    
    	local hookType = addHookArgs[1][1]
    	if hookType ~= "PlayerUpdate" then return end
    
    	local hookParams = hookParam.parent
    	local hookParamName = hookParam[1]
    
    	local hookParamIndex = nil
    	for i = 1, #hookParams do
    		local otherParamName = hookParams[i][1]
    		if otherParamName == hookParamName then
    			hookParamIndex = i
    			break
    		end
    	end
    
    	if not hookParamIndex then return end
    
    	-- local type = vm.declareGlobal("type", "TestClass", uri)
    	-- vm.setNode(source, vm.createNode(type, source))
    end

    It works now, but that wiki page should probably be updated, since the example it gives for this function is very unclear and not functional at all.

  2. CppCXY commented on Jan 29, 2026

    @CppCXY
    Member

    maybe overload function:

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions