lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

VM.OnCompileFunctionParam doesn't function as documented

Open Wild-W opened this issue 1 year ago • 2 comments

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

Defining the global VM.OnCompileFunctionParam in a plugin should create an intermediary step in compiling function parameters.

Actual Behaviour

Attempt to index nil 'VM' and when setting VM manually, nothing happens.

Reproduction steps

  1. Create plugin.lua
  2. Set runtime.plugin to the plugin.lua directory
  3. Insert this code into plugin.lua
local vm = require "vm"
local log = require "log"

log.info("Loaded test plugin!") -- Appears in log

function OnCompileFunctionParam(next, func, param)
    log.info("Inside OnCompileFunctionParam!") -- Does not appear in log
    -- Set type to number (test)
    vm.setNode(param, vm.declareGlobal('type', 'number'))
    return true
end

-- VM does not exist, so I tried declaring it globally
VM = VM or {}
VM.OnCompileFunctionParam = OnCompileFunctionParam

-- Also does not work when returned
return {
    VM = VM,
    OnCompileFunctionParam = OnCompileFunctionParam
}
  1. Restart LLS and observe that the plugin loads by verifying in the logs but does not set the parameters of any functions to numbers.

Additional Notes

image Image demonstrating that the parameters are not numbers.

If this is a bug, I would be happy to look into it myself if the maintainers have their hands full with other issues. Let me know if I should.

If this is not a bug and in some way, it's actually my own user error, then perhaps some changes should be made to the documentation to better reflect the intended functionality of OnCompileFunctionParam. On that note, there are actually a few more issues with the documentation for OnCompileFunctionParam that should probably be addressed, since the code snippet used as example appears to be copy-pasted from the tests and does not define many of the variables it references. require is also misspelt as reuqire on the snippet's first line.

Log File

file_c%3A_smbx%20lls%20plugin.log

Wild-W avatar Aug 28 '24 18:08 Wild-W