LuaLS / LuaLS/lua-language-server

Undefined global `var` in a function which has injected `var` into env

Open
#1,151 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
`luv -v`: `LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/`

```lua
local A = {}

function A.sync(executor)
local env = getfenv(executor)
env.await = A.wait
-- ......
executor()
end

function A.wait(promise)
print('go')
end

A.sync(function()
await() -- Undefined global `await`.
end)

return A
```

**Expected behavior**
No `Undefined global`

If it's hard to fix, how can I trick the server into treating `awati` as a global variable but not become an item in completion outside the `executor` function.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the Lua example in a running Lua language server and inspect how the analyzer handles getfenv, injected environment members, and global diagnostics. No source file or test is named in the issue, so first locate the relevant global-analysis and completion entry points. Done means await is not reported as undefined inside the executor while remaining absent from completion outside it.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
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.