LuaLS / LuaLS/lua-language-server
Inconsistent Go To Definition Behavior
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking
Expected Behaviour
Consider the following code:
---@class A
---@field t table<string, number>
---@field s string
---@class B
---@field a A
---@type B
local b = {
a = {
t = { x = 1 },
s = 'hi',
}
}
When you ctrl+click (or Go To Definition) on a inside the declaration of variable b, the cursor moves to ---@field a A in the type definition of class B. That's useful behavior. Similarly, when you do the same on s inside the nested a declaration, it goes to --@field s string in class A as expected.
When you click on t however (in t = { x = 1 }, it takes you to the builtin.lua meta file and places the cursor on the definition for tables @class table<K, V>: { [K]: V }. Not only is that behavior not consistent with the above, but it's also completely useless.
Another example (and probably different issue) is if you move the variable declaration to another file, like this:
File 1:
---@class A
---@field t table<string, number>
---@field s string
---@class B
---@field a A
File 2:
---@type B
local b = {
a = {
t = { x = 1 },
s = 'hi',
}
}
Now going to the definition of t still takes you to builtin.lua, but going to the definition of a, or s does nothing at all. I assume it's because it's treating their "definition" as the same line where they are declared in File 2.
Ideally I would like Go to Definition to do something useful inside table declarations and take me to the type annotation. But if that's not possible it should at least be consistent. In my opinion it should never take you to builtin.lua if there's another more suitable definition.
I think this worked fine in a previous version. I only started to see this behavior in the last few months.
Actual Behaviour
See above.
Reproduction steps
See above.
Additional Notes
No response
Log File
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的 Lua 代码片段开始,在 Windows 上的 Visual Studio Code 扩展中复现 Go To Definition,并比较内联声明和跨文件声明。跟踪字段 t 被解析到 builtin.lua,而 a 和 s 以不同方式解析的原因。完成的标准是,表字段导航能够一致地到达相关类型注解,或避开 builtin 表定义,并为两个示例提供回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100