LuaLS / LuaLS/lua-language-server
Better global recognizing for loadfile
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
In some cases you might need to make the plugin recognize a specific local variable as global, without declaring that variable as an actual global, one of these cases are using load and loadfile were you can pass an env variable that represents the chunk environment.
*mainFile.lua
local env = setmetatable(
{foo = function(a, b) return a == b end},
{__index = _G}
)
loadfile('./secondFile.lua', 't', env)
*secondFile.lua
foo(1, 2) -- Undefined global `foo` . Lua Diagnostics.(undefined-global)
So i would suggest better recognizing for load/loadfile/loadstring environment or/and a custom emmylua annotations --- @global that marks the local var as a global one.
Thanks in advance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the language server reports the undefined-global diagnostic and how it handles load, loadfile, and loadstring environments. Compare that behavior with the mainFile.lua and secondFile.lua example, then determine whether environment recognition or an @global annotation is the intended scope. Done means the example no longer reports foo as undefined under the chosen behavior.
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
- 25/100