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

无法提示ipair中的的类型 #435

Closed
sniper00 opened this issue Mar 2, 2021 · 33 comments
Closed

无法提示ipair中的的类型 #435

sniper00 opened this issue Mar 2, 2021 · 33 comments
Labels
bug Something isn't working

Comments

@sniper00
Copy link

sniper00 commented Mar 2, 2021

Describe the bug
A clear and concise description of what the bug is.

---@class TypeA
---@field public a integer
---@field public b integer
---@field public c integer

---@class TypeB
---@field public data TypeA[]

---@type TypeB
local arr = {}

for _, v in ipairs(arr.data) do
    if v.b == 10 then ---v 提示类型是any
        print("hello")
    end
end

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Windows
  • Client: VSCode

Additional context
Add any other context about the problem here.

@sumneko sumneko added the bug Something isn't working label Mar 2, 2021
@sumneko sumneko closed this as completed in 679689b Mar 2, 2021
@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

怎么手动更新最新版?

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

自己手动替换文件/应用更改

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

pairs 也有同样问题

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

pairs暂时只支持 table<K, V> 的注解

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

替换之后报这个错误

    [1] = "ECode",
    finish = 21249,
    loc = {
        [1] = "ECode",
        effect = 252,
        finish = 223,
        parent = "<Deep>",
        range = 251,
        ref = "<Deep>",
        start = 219,
        type = "local",
        value = "<Deep>",
    },
    next = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 21258,
        node = "<Loop>",
        parent = "<Deep>",
        start = 21245,
        type = "getfield",
    },
    node = {
        [1] = "ECode",
        effect = 252,
        finish = 223,
        parent = "<Deep>",
        range = 251,
        ref = "<Deep>",
        start = 219,
        type = "local",
        value = "<Deep>",
    },
    parent = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 21258,
        node = "<Loop>",
        parent = "<Deep>",
        start = 21245,
        type = "getfield",
    },
    start = 21245,
    type = "getlocal",
}
[10:30:51.675][warn] [#0:script.parser.guide:29]: status.depth overflow

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

这个一般是你的代码比较复杂,搜索深度达到上限了(也有可能是插件bug导致搜索时发生了死循环)。如果不影响结果的话无视即可。
如果你觉得代码并没有那么复杂的话,请尝试制作一个演示脚本给我。

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

项目代码,不好分享。 替换前是没这个问题的,替换后解析文件会超级慢。

@sumneko sumneko reopened this Mar 3, 2021
@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

你可以尝试做个演示脚本

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

嗯,我试试

sumneko added a commit that referenced this issue Mar 3, 2021
@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

可不可以通过添加日志定位下问题? 我发现只要代码多一些基本就一直卡在:正在诊断状态,lua-language-server进程使用的内存能达到 4G, 还继续增长,并且跑满了一个核CPU

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

听起来很有可能是死循环了,我加一些限制试试

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

cc6ec7e
试试这个

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

我重启了下,这次没出现内存爆涨,大概等了2分钟,诊断结束,但结果好像不对。
1
2
3
4

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

替换了你刚才发的最新的, 我们项目300多个lua文件,每个1k-30K, 改动一行代码, 2分钟左右才诊断结束。

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

在你第一次手动更新这个issue提到的问题前,诊断速度是合理的对吗?

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

vscode 只调整过文件大小限制 其它配置是默认的, 确认了下 速度值是 100

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

替换了你刚才发的最新的, 还是会出现 一直在诊断某个文件, cpu 20%, 内存缓慢增长,15分钟涨到了1GB

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

我还在尝试复现这个问题,先不要应用我的新提交

sumneko added a commit that referenced this issue Mar 3, 2021
@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

试试这个提交

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

还是很慢

[20:48:16.624][warn] [#0:script.parser.guide:29]: Queue too large!
[20:48:16.624][warn] [#0:script.vm.eachRef:22]: requestReference	100000	1.472	file:///d%3a/
  [1] = "allianceData",
    finish = 13734,
    loc = {
        [1] = "allianceData",
        effect = 13476,
        finish = 13430,
        parent = "<Deep>",
        range = 13475,
        ref = "<Deep>",
        start = 13419,
        type = "local",
        value = "<Deep>",
    },
    next = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 13742,
        next = "<Deep>",
        node = "<Loop>",
        parent = "<Deep>",
        start = 13723,
        type = "getfield",
    },
    node = {
        [1] = "allianceData",
        effect = 13476,
        finish = 13430,
        parent = "<Deep>",
        range = 13475,
        ref = "<Deep>",
        start = 13419,
        type = "local",
        value = "<Deep>",
    },
    parent = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 13742,
        next = "<Deep>",
        node = "<Loop>",
        parent = "<Deep>",
        start = 13723,
        type = "getfield",
    },
    start = 13723,
    type = "getlocal",
}

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

建议用 hash 来处理超长队列, table.remove(t, 1)的方式算法复杂度是n平方

local queue = {h = 1,t = 0}

---push
local t = queue.t + 1
queue.t = t
queue[t] = {}---value
---push

---pop
if queue.h > queue.t then
    -- queue is empty
    queue.h = 1
    queue.t = 0
    ---reutrn nil
else
    -- pop queue
    local h = queue.h
    local value = queue[h]
    queue[h] = nil
    queue.h = h + 1
    ---return value
end
---pop

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

建议用 hash 来处理超长队列, table.remove(t, 1)的方式算法复杂度是n平方

local queue = {h = 1,t = 0}

---push
local t = queue.t + 1
queue.t = t
queue[t] = {}---value
---push

---pop
if queue.h > queue.t then
    -- queue is empty
    queue.h = 1
    queue.t = 0
    ---reutrn nil
else
    -- pop queue
    local h = queue.h
    local value = queue[h]
    queue[h] = nil
    queue.h = h + 1
    ---return value
end
---pop

不确定你说的是什么意思,插件代码中并没有这样的用法

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

ast.lua:1432 行, local func = tableRemove(exp, 1), 不确定你这个exp 是否是个超长数组,table.remove(t, 1)的方式算法复杂度是n平方,会极大影响性能

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

我贴的那段代码是用 hash模拟队列 ,算法复杂度不会随着元素变多n平方增长

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

你说的这个地方长度有多大,取决于你 for _ in a1, a2, a3, a4, a5, a6 ... do 写的有多长。
这些代码和问题没有太大关系,主要还是我无法复现,最好是你能想办法提供一个能复现的例子。

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

感觉和 #437 这个问题差不多

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

#437 (comment) 提供了一个演示项目,我在1.17.3中修复了,不过依然有人表示他用1.17.3打开这个项目有问题。不确定是真的有问题还是他自己侧错了,你也来测试一下看看?

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

我试试

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

我这里依然很慢,一直显示正在诊断中

@sniper00
Copy link
Author

sniper00 commented Mar 3, 2021

[21:13:34.316][warn] [#0:script.parser.guide:29]: Queue too large!
[21:13:34.316][warn] [#0:script.vm.eachRef:22]: requestReference	100000	2.963	file:///d%3a/	{
    dot = {
        finish = 14705,
        start = 14705,
        type = ".",
    },
    field = {
        [1] = "info",
        finish = 14709,
        parent = "<Loop>",
        start = 14706,
        type = "field",
    },
    finish = 14709,
    next = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 14715,
        node = "<Loop>",
        parent = "<Deep>",
        start = 14693,
        type = "getfield",
    },
    node = {
        [1] = "allianceData",
        finish = 14704,
        loc = "<Deep>",
        next = "<Loop>",
        node = "<Deep>",
        parent = "<Loop>",
        start = 14693,
        type = "getlocal",
    },
    parent = {
        dot = "<Deep>",
        field = "<Deep>",
        finish = 14715,
        node = "<Loop>",
        parent = "<Deep>",
        start = 14693,
        type = "getfield",
    },
    start = 14693,
    type = "getfield",
}
[21:13:35.066][warn] [#0:script.await:166]: Await step takes [0.223] sec.

@sumneko
Copy link
Collaborator

sumneko commented Mar 3, 2021

你的问题应该和 #437 不同,把日志发我看看吧(打开 #437 中提供的演示项目)

@sumneko
Copy link
Collaborator

sumneko commented Mar 5, 2021

此 issue 标题的部分已经修复,关于性能问题请单独开个新的 issue ,并提供上述测试的日志,谢谢!

@sumneko sumneko closed this as completed Mar 5, 2021
@sniper00
Copy link
Author

sniper00 commented Mar 5, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants