LuaLS / LuaLS/lua-language-server

`module()` function isn't respected by the language server

Open
#2,901 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Linux

### What is the issue affecting?

Diagnostics/Syntax Checking

### Expected Behaviour

When `module()` is used in a script, functions defined "globally", like so:
```lua
module("MyExampleModule")

function HelloWorld() end
```
Are understood by the language server to belong to the table at `_G.MyExampleModule`

### Actual Behaviour

Using the above example, the language server incorrectly believes `HelloWorld()` is at `_G.HelloWorld()` as opposed to `_G.MyExampleModule.HelloWorld()`

### Reproduction steps

1. Copy the above example into a file
2. Create another file in the same workspace
3. Type "Hello"
4. Observe that the autocomplete suggests the function `_G.HelloWorld()`, which does not exist

### Additional Notes

This cannot be worked around with `setfenv()`

### Log File

N/A

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 issue in the Visual Studio Code extension using the two-file example and the autocomplete step described. Trace how module("MyExampleModule") is handled during diagnostics and completion, then verify that HelloWorld is suggested under _G.MyExampleModule rather than _G.HelloWorld.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.