fix(lsp): else/finally 语句体按语句遍历

If/For/While 的 orelse 和 Try 的 finalbody 是语句列表,却用 _WalkExpr 遍历,else 里的调用基址/属性/名字没有 occurrence,只剩字符串高亮。改用 _WalkBody;gate10 增加多行 else 与单行 else 的跨模块 token/跳转断言。
This commit is contained in:
TermiNexus committed 2026-10-27 17:34:59 +08:00
1 parent 4770f57567
commit 4e3331d442
3 files changed
+32 -5

No files matched your search

+5 -5
View File
@@ -1156,19 +1156,19 @@ def _WalkStmt(pool: memhub.MemManager*, a: LspAnalysis*, scope: LspScope*,
_WalkExpr(pool, a, scope, fr.target)
_WalkExpr(pool, a, scope, fr.iter)
_WalkBody(pool, a, scope, node.children)
_WalkList(pool, a, scope, fr.orelse)
_WalkBody(pool, a, scope, fr.orelse)
return
if k == ast.ASTKind.While:
wh: ast.While* = (ast.While*)(node)
_WalkExpr(pool, a, scope, wh.test)
_WalkBody(pool, a, scope, node.children)
_WalkList(pool, a, scope, wh.orelse)
_WalkBody(pool, a, scope, wh.orelse)
return
if k == ast.ASTKind.If:
iff: ast.If* = (ast.If*)(node)
_WalkExpr(pool, a, scope, iff.test)
_WalkBody(pool, a, scope, node.children)
_WalkList(pool, a, scope, iff.orelse)
_WalkBody(pool, a, scope, iff.orelse)
return
if k == ast.ASTKind.With:
wi: ast.With* = (ast.With*)(node)
@@ -1195,8 +1195,8 @@ def _WalkStmt(pool: memhub.MemManager*, a: LspAnalysis*, scope: LspScope*,
_WalkExpr(pool, a, scope, h.type)
_WalkBody(pool, a, scope, h.children)
i += 1
_WalkList(pool, a, scope, tr.orelse)
_WalkList(pool, a, scope, tr.finalbody)
_WalkBody(pool, a, scope, tr.orelse)
_WalkBody(pool, a, scope, tr.finalbody)
return
if k == ast.ASTKind.Match:
mt: ast.Match* = (ast.Match*)(node)
+12
View File
@@ -37,3 +37,15 @@ def stub_use(t: StubThing) -> int:
def stub_chain() -> int:
return StubThing.count
def else_block(flag: int) -> int:
if flag != 0:
return 1
else:
return extra_fn(EXTRA_CONST + 1)
def else_inline(flag: int) -> int:
if flag != 0: return 1
else: return extra_fn(EXTRA_CONST + 2)
+15
View File
@@ -1507,6 +1507,21 @@ def gate10(exe: str) -> int:
pos["character"] += delta
if not _find_token(sem_tokens, pos["line"], pos["character"], sem_types.index(token_name)):
raise AssertionError(f"missing cross-module semantic token for {label}: {pos}")
for needle, label in (("return extra_fn(EXTRA_CONST + 1)", "else block"),
("return extra_fn(EXTRA_CONST + 2)", "inline else")):
pos = _position(text, needle)
pos["character"] += 7
if not _find_token(sem_tokens, pos["line"], pos["character"], sem_types.index("function")):
raise AssertionError(f"missing cross-module token in {label}: {pos}")
else_def = client.request(
"textDocument/definition",
{"textDocument": {"uri": uri}, "position": pos},
timeout=120.0,
).get("result")
if not isinstance(else_def, list) or not else_def:
raise AssertionError(f"missing definition in {label}: {else_def}")
if not else_def[0]["uri"].replace("\\", "/").endswith("gate10_extra.vp"):
raise AssertionError(f"wrong definition in {label}: {else_def}")
const_pos = _position(text, "EXTRA_CONST")
if not _find_token_mods(sem_tokens, const_pos["line"], const_pos["character"],
sem_types.index("variable"),