Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library中的定义提示有问题 #816

Closed
Weiged opened this issue Nov 24, 2021 · 5 comments
Closed

Library中的定义提示有问题 #816

Weiged opened this issue Nov 24, 2021 · 5 comments
Labels
bug Something isn't working feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) Info Needed More information is required

Comments

@Weiged
Copy link

Weiged commented Nov 24, 2021

版本:2.4.10
---@type CS.FairyGUI.GList
local list

如果CS.FairyGUI.GList是在Library定义的文件夹内的,那么当我对list使用.时,无法提示任何方法,只有属性和字段,但是如果我手动写了出来,比如list:SetVirtual(),那么鼠标悬停到SetVirtual方法上是能正确索引过去的

@sumneko sumneko added bug Something isn't working feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) Info Needed More information is required labels Nov 24, 2021
@sumneko
Copy link
Collaborator

sumneko commented Nov 24, 2021

请提供另一个文件的演示代码

@Weiged
Copy link
Author

Weiged commented Nov 25, 2021

LibraryDefine.zip

@sumneko
Copy link
Collaborator

sumneko commented Nov 25, 2021

按照我现在的设计,你需要将代码改写为这样

---@class CS.FairyGUI.GList
---@field public defaultItem string
local GList

CS = {}
CS.FairyGUI = {}
CS.FairyGUI.GList = GList

---@return CS.FairyGUI.GList
function GList.New() end
function GList:Dispose() end
return GList

这里涉及到2个设计:

  1. ---@type 不再能注入字段,我参考了其他语言必须显性通过 ---@class 来声明字段。目前版本重复声明 ---@class 是有效的,只是会有警告,你可以暂时屏蔽掉这个警告,2.5.0版本我会修改诊断允许重复声明 ---@class
  2. ---@class 不再对字段声明生效,因此你演示代码中直接将 ---@type 改成 ---@class 是没用的,必须要照我这么改。

设计1我觉得没什么问题,以后就这样推行下去了,对严谨性和性能都有好处。
设计2我看了你的例子后有点动摇了,因为我是参考其他强类型语言才这么设计的,一般的强类型语言中 class 肯定是单独声明的,但是对于Lua这种半路出家的类型系统来说也许不适用,我还在考虑要不要重新支持字段声明

@sumneko
Copy link
Collaborator

sumneko commented Nov 25, 2021

考虑了一下还是重新支持 ---@class 对字段声明有效了,这个支持对性能基本没有副作用,也不会产生像---@type可以字段注入那样不明确的语义

修改后你只需要将 ---@type 改为 ---@class 即可(在2.5.0发布前你需要禁用诊断 duplicate-doc-class)

@Weiged
Copy link
Author

Weiged commented Nov 26, 2021

其实我感觉没关系,不需要改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) Info Needed More information is required
Projects
None yet
Development

No branches or pull requests

2 participants