LuaLS / LuaLS/lua-language-server

Unexpected repeated alias expanding 类型别名错误地重复展开

オープン
#2,780 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
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?

Hover

Expected Behaviour

hover.expandAliasfalse时,如下标注
Set hover.expandAlias to false, and do annotations like this:

---while `hover.expandAlias` is `false`
---@alias T string | [T, T]

当鼠标置于[T, T]中的任意一个T时,应为(alias) T 展开为 string | [T, T]
When the mouse is placed on one T of [T, T], it should be expanded to (alias) T 展开为 string | [T, T]

Actual Behaviour

如图所示
As is seen:
image

对于任何一个出现了多于一次递归引用的别名,都会这样
For any alias that has more than one recursive reference, this will be the case:
image

单次递归引用,或者是简单得没有意义的别名,则不会发生
A single recursive reference, or a simply meaningless alias, will not be with glitches:
image
image

此外,若hover.expandAliastrue,展开的效果非常惊悚
In addition, if hover. extpandAlias is set to true, the effect is very frightening:
image

Reproduction steps
---while `hover.expandAlias` is `true`
---@alias S string | [S] | [S, S]


---while `hover.expandAlias` is `false`
---@alias T string | [T, T]


---while `hover.expandAlias` is `false`
---@alias U string | {msg: U} | {err: U}


---while `hover.expandAlias` is `false`
---@alias V string | V[]


---while `hover.expandAlias` is `false`
---@alias W {[string]: W} | W[]
Additional Notes

我查阅了一下代码,做出一种猜想:

getInfer时的compileNode错误地使用了先前已缓存的节点(其并未标记这是一个不应该展开的别名),在_eraseAlias发挥效用前就展开了这个别名,并没有经过hover.expandAlias的判断,未在_drop集合中附上标注。这也是在单次使用递归时不会触发 bug 但两次使用递归就会触发的原因。

I looked up the code and made a guess:

When using getInfer, the compileNode mistakenly used a previously cached node which was not marked as an alias that should not be expanded. Without going through the judgment of hover.expandAlias, it expanded the alias before _eraseAlias takes into effect, which failed in marking in _drop set. This is the reason why it will not cause glitch when using recursion once, but only when using recursion twice.

作为本仓库的贡献者之一,我非常乐意协助这个 bug 的修复。但这个 bug 似乎太底层,有点超出我力所能及的范围了。故我提交本次 Issue,抛砖引玉一下。

As one of the contributors to this repository, I am more than happy to assist in fixing this glitch. But this glitch seems too fundamental for me to fix. So I am here to submit this issue for further discussion.

Log File

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

レポートで特定されているとおり、まず script/vm/infer.lua の getInfer と _eraseAlias から始め、次に script/vm/compiler.lua の compileNode を調べます。hover.expandAlias を切り替えながら、再帰的なエイリアス S、T、U、V、W でホバーの動作を再現します。再帰的なエイリアスが繰り返し展開されなくなり、ホバー出力が期待される1回の展開と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。