LuaLS / LuaLS/lua-language-server

Support for module-style includes?

Open
#3,195 10 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?

Other

### Which OS are you using?

Windows

### What is the issue affecting?

Diagnostics/Syntax Checking

### Expected Behaviour

Lua files from my project are found automatically without adding a workspace library path.

### Actual Behaviour

Incorrect diagnostics due to LSP seemingly being unable to find the lua files in the path. Also go to definition and such don't work.

### Reproduction steps

.

### Additional Notes

I have a lot of files in my project which I import like so:
```lua
import 'game.physics'
import 'game.ball.request'
import 'game.world'
```

Note that we use `import` instead of `require`. It doesn't do anything special regarding the paths, and I have the following setting:
```json
"Lua.runtime.special": {
"import" : "require"
}
```

These paths are relative to the workspace, plus some folders. The actual paths are like so:
```
/src/script-game/game/physics.lua
/src/script-game/game/ball/request.lua
/src/script-game/game/world.lua
```

From reading the documentation, it seems like the default `Lua.runtime.path` should pick these files up no problem, but I get diagnostics like "Undefined global "physics"", and I can't go to definition or get completions for those files (details omitted, sorry):
![Image](https://github.com/user-attachments/assets/3428bcdf-63d3-46c2-9817-8f7fd06da9dd)

---

If I then add a config for `Lua.workspace.library`, I can make it work:
```
"Lua.workspace.library": [
"\\src\\script-game"
],
```

But this feels wrong. These are my files and they're part of my project. I shouldn't need to add them as a library path, should I? Additionally, I could only get it to work as an absolute path, so I need to update this whenever I switch projects. I tried "src/script-game" and "src\\script-game" and both reverted back to the broken behaviour.

Am I missing something? Do I need to set something custom in `Lua.runtime.path`?

### Log File

Unfortunately I can't provide this as most of it is under NDA.

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

Start by comparing the Lua.runtime.path, Lua.workspace.library, and Lua.runtime.special settings described in the issue, especially with import mapped to require. Reproduce the project-relative imports under src/script-game and verify that diagnostics, go to definition, and completions work without an absolute library path.

Written by the indexing model from the issue text.

Assessment

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