LuaLS / LuaLS/lua-language-server
Register function environment variables
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
This extension is able to detect usage of undefined global variables:

However, `setfenv` is used on this function to define the missing variable, but at another point in the code that the parser can't detect. Is it possible to somehow tell the parser to ignore this diagnostic? Something like:
```lua
local block = function(_)
-- env: {block, assert, error}
block()
end
```
Then it would accept those values? I know you can define globals for the project, but this doesn't affect the entire project, only those functions, so it would be cool if you could define it somehow.
Alternatively, could we just disable the diagnostic?
```lua
local block = function(_)
-- disable: undefined-global
block()
end
```
I don't know if the parser supports reading comments like that, let me know if that won't work or if you have better ideas for it.
Contributor guide
Research direction
Start by tracing the parser's undefined-global diagnostic and how it reads project-level global definitions. Evaluate the proposed function-local environment annotation and diagnostic-disable comment from the issue, then verify that the selected syntax suppresses or resolves only the intended function-scoped warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100