LuaLS / LuaLS/lua-language-server
Adding ---@class breaks auto completion
还没有人认领这个 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?
Linux
What is the issue affecting?
Completion
Expected Behaviour
I'm running into an issue where adding the ---@class annotation to a local variable seems to break auto completion. It should appear correctly even if the ---@class is affixed to a local variable.
Actual Behaviour
The autocomplete variables and functions are not appearing.
Reproduction steps
Here is a simple example of creating a new player class with the issue.
-- Here is a simple example of creating a new player class with the issue
-- Uncommenting the line below *breaks* the autocompletion for p.new()
-- ---@class err.Player
local Player = {}
Player.__index = Player
local function mixin_xy(o)
o.x = 0
o.y = 0
o.set_position = function(self, x, y)
self.x = x
self.y = y
end
return o
end
function Player.new()
local self = {}
self.happy = true
self = mixin_xy(self)
return setmetatable(self, Player)
end
local p = Player.new()
-- `p:set_position(), p.x, p.y, p.happy` no longer showing in auto complete if `---@class err.Player` is uncommented
When ---@class err.Player is uncommented, and above local Player = {}:
When ---@class err.Player is removed or commented:
The above image is the expected behaviour. However, when ---@class err.Player is added above local Player = {} it no longer works.
Additional Notes
No response
Log File
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用报告中的 Lua 示例在 Visual Studio Code 扩展中重现该问题,比较有和没有 ---@class err.Player 注解时的补全结果。跟踪类注解的补全处理,并验证在存在该注解时会出现 p:set_position()、p.x、p.y 和 p.happy。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100