-
- Notifications
You must be signed in to change notification settings - Fork 386
meta:support metatable #2106
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
meta:support metatable #2106
Conversation
| 好像没有办法添加__index字段,查找属性的时候直接就去找类定义中的‘table’类型,其实应该去找赋值__index字段的对象 |
| 晚点看一下,最近没空 |
嗯,这个需要你帮助,我也看不太清楚里面的流程 现在的流程变成了优先查找setmetatable参数的doc节点,而不是comment节点. |
| 这个PR的目的是什么 |
纯粹希望对metatable的字段 有智能提示,emmylua有,我也想加一个. |
| 因为按照目前的规则,显性申明了 |
是的.优先级上doc更高 |
| 解决了,拉一下最新版本吧。 |
诊断警告么 |
| 对的 |
好的,我尽快 |
| 你的修改跟我之前强制优先comment一样的结果 返回的仍然只有doc.class节点,这个才是我不太明白的地方,为什么同样的comment的节点在compileNode函数中compileByNode(source)这个调用返回不同的结果,不知道这里这么改. |
给个演示? |
你直接把测试用例改成这个,应该跑不过去 |
| 现在还有问题吗? |
| 有,现在的诊断,因为我改成了class metatable,诊断基本都失效了. |
| 给个例子? |
| 文件是test/diagnostic/type-check.lua 无法把class A赋值给metatable TEST [[ ---@class A local a = {} a.__index = a ---@class B: A local b = setmetatable({}, a) ]] TEST [[ ---@class A local a = {} ---@class B: A local b = setmetatable({}, {__index = a}) ]] TEST [[ 无法将metatable转化成B ---@class A local a = {} ---@class B local <!b!> = setmetatable({}, {__index = a}) ]] |
| 第二个参数的类型试试 |
| 还有 TEST[[ local mt = {} mt.a = 1 mt.b = 2 mt.c = 3 local <?obj?> = setmetatable({}, {__index = mt}) ]] [[ local obj: { a: integer = 1, b: integer = 2, c: integer = 3, } ]]这是最后一个测试错误了 |
| 这个hover会显示什么?如果包含 |
| 好了,他返回的是 local obj : table | nil {...} |
| 感觉不对,为什么会有 |
因为每个字段我都加了nil类型 |
|
|
很有道理,不应该有nil |
| 我调试了一下,getReturnOfSetMetaTable这个函数对于__index这个字段 返回了两个node { cate='type', name='nil' }, { cate='type', name='table', } |
| 嗯,应该是因为 |
| 好了,可以合并了. |


No description provided.