LuaLS / LuaLS/lua-language-server

Register function environment variables

Open
#15 5 comments 0 reactions 0 assignees View on GitHub
enhancement feat/LuaCats Annotations priority.normal
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:
![image](https://user-images.githubusercontent.com/1635608/55824214-b3bc4380-5b03-11e9-87a0-7fd50d08a633.png)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.