test(lsp): 覆盖修复字面量后溢出诊断清除

gate2 在 push 与 pull 两条路径上都验证:把超长字面量改成 1 后诊断必须清空,防止词法错误状态串到下一次解析。
This commit is contained in:
TermiNexus committed 2026-10-28 15:19:08 +08:00
1 parent 86cced94dc
commit 7072acea82
1 file changed
+23
+23
View File
@@ -422,6 +422,18 @@ def gate2(exe: str) -> int:
functions = {(t["line"], t["character"]) for t in sem_tokens if t["type"] == function_type}
if (0, 4) not in functions or (3, 4) not in functions:
raise AssertionError(f"semantic tokens lost after a lexer error: {sem_tokens}")
# Fixing the literal must clear the overflow diagnostic (lexer fail-fast state is global and
# must be reset for the next parse, otherwise the stale error sticks to every later edit).
fixed_overflow = overflow.replace("1024000000000000000000", "1")
client.notify(
"textDocument/didChange",
{"textDocument": {"uri": uri, "version": 4},
"contentChanges": [{"text": fixed_overflow}]},
)
publish = client.wait_notification("textDocument/publishDiagnostics")
diagnostics = publish.get("params", {}).get("diagnostics")
if not isinstance(diagnostics, list) or len(diagnostics) != 0:
raise AssertionError(f"fixed overflow literal still reports diagnostics: {publish}")
client.notify("textDocument/didClose", {"textDocument": {"uri": uri}})
client.wait_notification("textDocument/publishDiagnostics")
@@ -455,6 +467,17 @@ def gate2(exe: str) -> int:
items = pulled.get("items", []) if isinstance(pulled, dict) else []
if len(items) != 1:
raise AssertionError(f"pull diagnostics returned {len(items)} items: {pulled}")
pull_client.notify(
"textDocument/didChange",
{"textDocument": {"uri": uri, "version": 5},
"contentChanges": [{"text": fixed_overflow}]},
)
pulled = pull_client.request(
"textDocument/diagnostic", {"textDocument": {"uri": uri}}, timeout=60.0
).get("result")
items = pulled.get("items", []) if isinstance(pulled, dict) else []
if len(items) != 0:
raise AssertionError(f"pull diagnostics kept the stale overflow: {pulled}")
pull_client.request("shutdown")
pull_client.close()