From ff842e9ff2584392ec190e2613d3818d1859b554 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 27 Oct 2026 17:54:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(lsp):=20=E4=B8=89=E5=85=83=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E6=8C=89=E6=BA=90=E7=A0=81=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E9=81=8D=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IfExp 原先先走 test 再走 body,生成的 occurrence 顺序与源码相反,body 的 token 被编码器丢弃或产生负增量。改为 body/test/orelse;gate10 增加三元 body 与 else 的跨模块 token/跳转断言。 --- App/lib/lsp/LspSymbols.vp | 3 ++- Tools/lsp/fixtures/gate10_use.vp | 4 ++++ Tools/lsp/probe.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/App/lib/lsp/LspSymbols.vp b/App/lib/lsp/LspSymbols.vp index eb94845..5c2b0d7 100644 --- a/App/lib/lsp/LspSymbols.vp +++ b/App/lib/lsp/LspSymbols.vp @@ -1377,8 +1377,9 @@ def _WalkExpr(pool: memhub.MemManager*, a: LspAnalysis*, scope: LspScope*, return if k == ast.ASTKind.IfExp: ie: ast.IfExp* = (ast.IfExp*)(node) - _WalkExpr(pool, a, scope, ie.test) + # Source order is `body if test else orelse`; the token stream must stay sorted. _WalkExpr(pool, a, scope, ie.body) + _WalkExpr(pool, a, scope, ie.test) _WalkExpr(pool, a, scope, ie.orelse) return if k == ast.ASTKind.Dict: diff --git a/Tools/lsp/fixtures/gate10_use.vp b/Tools/lsp/fixtures/gate10_use.vp index 5071d0a..7aef0fe 100644 --- a/Tools/lsp/fixtures/gate10_use.vp +++ b/Tools/lsp/fixtures/gate10_use.vp @@ -44,6 +44,10 @@ def reexport_use() -> int: return gate10_pkg.reexport_fn(1) +def ternary_use(flag: int) -> int: + return extra_fn(EXTRA_CONST) if flag != 0 else extra_fn(EXTRA_CONST + 1) + + def else_block(flag: int) -> int: if flag != 0: return 1 diff --git a/Tools/lsp/probe.py b/Tools/lsp/probe.py index 7fccdd0..ab8443f 100644 --- a/Tools/lsp/probe.py +++ b/Tools/lsp/probe.py @@ -1535,6 +1535,23 @@ def gate10(exe: str) -> int: raise AssertionError(f"package re-export definition failed: {re_def}") if not re_def[0]["uri"].replace("\\", "/").endswith("gate10_pkg/leaf.vp"): raise AssertionError(f"package re-export definition is wrong: {re_def}") + for needle, delta, label in ( + ("return extra_fn(EXTRA_CONST) if", 7, "ternary body"), + ("else extra_fn(EXTRA_CONST + 1)", 5, "ternary else"), + ): + pos = _position(text, needle) + pos["character"] += delta + if not _find_token(sem_tokens, pos["line"], pos["character"], sem_types.index("function")): + raise AssertionError(f"missing function token in {label}: {pos}") + t_def = client.request( + "textDocument/definition", + {"textDocument": {"uri": uri}, "position": pos}, + timeout=120.0, + ).get("result") + if not isinstance(t_def, list) or not t_def: + raise AssertionError(f"missing definition in {label}: {t_def}") + if not t_def[0]["uri"].replace("\\", "/").endswith("gate10_extra.vp"): + raise AssertionError(f"wrong definition in {label}: {t_def}") const_pos = _position(text, "EXTRA_CONST") if not _find_token_mods(sem_tokens, const_pos["line"], const_pos["character"], sem_types.index("variable"),