LuaLS / LuaLS/lua-language-server
VM.OnCompileFunctionParam does not work at all
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### 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](url), `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
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:
```Lua
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_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc tái hiện plugin trong plugin.lua và đường dẫn tải được tham chiếu bởi script\plugin.lua:157, sau đó so sánh điểm vào VM.OnCompileFunctionParam được ghi trong tài liệu với hook OnSetText đang hoạt động. Tái hiện lỗi VM nil bằng cấu hình .vscode/settings.json được hiển thị. Được xem là hoàn tất khi callback có thể được định nghĩa và gọi mà không có lỗi VM toàn cục.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- devtools, tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100