fix(vscode): clamp open file positions#5711
Conversation
|
@qwen-code /triage |
|
Thanks for the PR! Template looks good ✓ On direction: this is a straightforward bug fix for a real user-facing issue — web UI file links with zero-based line/column values crash the VS Code On approach: scope is tight and appropriate. The fix extracts a small Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ 方向:这是一个直接的用户问题修复——web UI 文件链接中的零值行号/列号会导致 VS Code 方案:范围紧凑合理。提取了一个小的 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
Code ReviewThe diff is minimal and well-focused — exactly what a bug fix should look like. Production code ( Test code ( Reuse check: the No correctness issues, no security concerns, no AGENTS.md violations. TestingUnit TestsAll 8 tests pass, including the new regression test: Regression Verification (reverted fix + re-ran test)To confirm the test actually catches the bug, I reverted the production code change and re-ran: Without the clamp, Tmux / CLI TestingNot applicable — this is a VS Code extension internal handler, not a CLI-invokable feature. The behavior only manifests through the VS Code companion webview messaging API. Type CheckThe 中文说明代码审查Diff 极简且聚焦——正是 bug fix 应有的样子。 生产代码( 测试代码( 复用检查: 无正确性问题,无安全隐患,无 AGENTS.md 违规。 测试单元测试8 个测试全部通过,包括新增的回归测试。 回归验证(回退修复 + 重跑测试)为确认测试真正能捕捉该 bug,我回退了生产代码改动并重新运行:没有 clamp 时, Tmux / CLI 测试不适用——这是 VS Code 扩展内部 handler,不是 CLI 可调用的功能。 类型检查
— Qwen Code · qwen3.7-max |
ReflectionThis is exactly the kind of PR that's easy to approve: a small, focused fix for a real bug, with a test that actually catches the failure mode. My independent proposal was The mock additions (Position, Selection, Range throwing on negative values) are a nice touch — they make the test a real safety net rather than a rubber stamp. Every change in the diff serves the stated goal. No scope creep, no drive-by refactors. The only nit I had was the helper method name being slightly long, but that's genuinely not worth a round trip. Ships it. 中文说明总结这是一个非常容易批准的 PR:一个针对真实 bug 的小而聚焦的修复,带有真正能捕捉失败模式的测试。 我的独立方案是内联 Mock 添加(Position、Selection、Range 在负值时抛出异常)是一个很好的设计——使测试成为真正的安全网而非橡皮图章。Diff 中的每一处改动都服务于既定目标。无范围蔓延,无顺手重构。 唯一的小瑕疵是 helper 方法名稍长,但不值得为此增加一轮往返。通过。 — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
✅ Local runtime verification — recommend mergeI verified this PR on Linux by driving the real
Behavioral evidence — real handler A/B (observed)Each row drives
This reproduces #5710 exactly: any zero-containing suffix (a web-UI link can emit a zero-based line) made BEFORE compute a negative position → Tests
RiskLow / surgical. Only the previously-broken zero-valued suffixes change behavior (now open at file start instead of erroring) — intended per #5710. Valid one-based Verdict: ✅ behaves exactly as described. Recommend merge. 🇨🇳 中文版(点击展开)✅ 本地运行时验证 — 建议合并我在 Linux 上做了真实验证:用一个忠实的 mock
行为证据 —— 真实 handler A/B(实测)每一行都驱动
这精确复现了 #5710:任何含零的后缀(web UI 链接可能发出零基行号)在 BEFORE 时会算出负数位置 → 测试
风险低 / 改动精准。 只有原本就坏掉的零值后缀行为会改变(现在打开到文件开头,而不是报错)—— 这正是 #5710 的目的。合法的一基 结论:✅ 行为与描述完全一致,建议合并。 |
|
I think the clamp is fine as defensive handling, but we should clarify the source of The handler only gets One related source is Could we either add a test through the real producer of |
✅ Local verification report (maintainer)Built and tested this PR locally to confirm the fix before merge. Environment
Results
Mutation test (the key evidence). I reverted
Correctness review
Verdict: LGTM. Correct, minimal, mutation-verified (reproduces #5710 exactly); merges cleanly, types/lint/format clean. Safe to merge from my side. 🇨🇳 中文版✅ 本地验证报告(维护者)合并前在本地构建并测试了本 PR 以确认修复。 环境
结果
变异测试(关键证据)。 我把
正确性审查
结论:LGTM。 正确、最小化、经变异测试验证(精确复现 #5710);可干净合并,类型/lint/格式干净。从我这边看可以安全合并。 |
|
@yiliang114 Thanks — I traced the whole chain against the code. Short version: the data-model inconsistency you spotted is real, but the off-by-one you describe isn't reachable today, and What's correct in your analysisThe 0-based vs 1-based mismatch is genuinely there in the data:
So Why the off-by-one isn't actually reachable (and
|
What this PR does
This PR normalizes VS Code companion
openFileline and column suffixes so zero values such assrc/app.ts:0:0resolve to the start of the file instead of producing negative editor positions.It also extends the
FileMessageHandlertest mock with the VS Code position/range APIs used by the open-file path and adds a regression test for the zero line/column case.Why it's needed
The web UI can emit file links with a zero-based line value. The VS Code companion treats incoming line/column suffixes as one-based values and subtracts one before creating
vscode.Position. When the incoming value is0, the handler can try to createvscode.Position(-1, -1), which makes the open-file request fail instead of opening the file.Clamping the converted position keeps the existing one-based behavior for normal
:line:columnlinks while making zero-valued links safe.Reviewer Test Plan
How to verify
Run
npm test --workspace=packages/vscode-ide-companion -- FileMessageHandler.test.tsand confirm the newopenFile clamps zero line and column values to the file starttest passes. Reviewers can also confirm thatsrc/app.ts:0:0openssrc/app.tsand selects line 0 / column 0 in the mocked VS Code editor instead of surfacing an open-file error.Evidence (Before & After)
Before:
src/app.ts:0:0was converted by subtracting one directly, producing negative VS Code editor positions.After:
src/app.ts:0:0is clamped to line 0 / column 0, and the regression test asserts that no error is shown and the editor selection/reveal range point at the file start.Tested on
Environment (optional)
Local workspace tests on macOS with the repository npm workspace setup.
Commands run:
npm test --workspace=packages/vscode-ide-companion -- FileMessageHandler.test.ts npx prettier --check packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.ts packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.test.ts npx eslint packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.ts packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.test.ts npm run check-types --workspace=packages/vscode-ide-companion git diff --checkSub-agent review: no blocking issues found.
Risk & Scope
:0or:0:0location now opens at the file start rather than failing the open-file request.src/app.ts:-1:0are not treated as line/column suffixes by the existing parser and are unchanged.Linked Issues
Fixes #5710
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.
中文说明
What this PR does
这个 PR 会规范 VS Code companion 的
openFile行号和列号后缀解析,让src/app.ts:0:0这样的零值位置打开到文件开头,而不是产生负数编辑器位置。同时,测试里的 VS Code mock 补上了 open-file 路径实际用到的 position/range API,并增加了零行号/零列号的回归测试。
Why it's needed
Web UI 可能发出带零基行号的文件链接。VS Code companion 会把收到的行号/列号后缀当作一基值处理,并在创建
vscode.Position前减一。当传入值是0时,handler 可能会创建vscode.Position(-1, -1),导致打开文件请求失败,而不是正常打开文件。转换后做下限 clamp 可以保留普通
:line:column链接的一基行为,同时让零值链接安全落到文件开头。Reviewer Test Plan
How to verify
运行
npm test --workspace=packages/vscode-ide-companion -- FileMessageHandler.test.ts,确认新增的openFile clamps zero line and column values to the file start测试通过。Reviewer 也可以确认src/app.ts:0:0会打开src/app.ts,并在 mock 的 VS Code editor 中选择 line 0 / column 0,而不是显示打开文件错误。Evidence (Before & After)
Before:
src/app.ts:0:0会被直接减一转换,产生负数 VS Code 编辑器位置。After:
src/app.ts:0:0会被 clamp 到 line 0 / column 0,回归测试断言不会显示错误,并且 editor selection/reveal range 指向文件开头。Tested on
Environment (optional)
在 macOS 上使用仓库 npm workspace 进行本地测试。
已运行命令:
npm test --workspace=packages/vscode-ide-companion -- FileMessageHandler.test.ts npx prettier --check packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.ts packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.test.ts npx eslint packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.ts packages/vscode-ide-companion/src/webview/handlers/FileMessageHandler.test.ts npm run check-types --workspace=packages/vscode-ide-companion git diff --check子代理审查:未发现阻塞问题。
Risk & Scope
:0或:0:0位置现在会打开到文件开头,而不是让打开文件请求失败。src/app.ts:-1:0这类负数后缀不会被现有 parser 当作行号/列号后缀处理,本 PR 不改变这部分行为。Linked Issues
Fixes #5710
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.