LuaLS / LuaLS/lua-language-server
Support for module-style includes?
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
### 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):

---
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先比较 issue 中描述的 Lua.runtime.path、Lua.workspace.library 和 Lua.runtime.special 设置,尤其是在将 import 映射到 require 的情况下。在 src/script-game 下复现项目相对导入,并验证无需绝对库路径时诊断、转到定义和补全都能正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100