vscode-js-debug: Variable renamed incorrectly, leading to thrown error
Describe the bug
When debugging the TS codebase (which is bundled with esbuild), I periodically hit cases where the variable name I’m using in the debug console doesn’t work and ends up throwing.
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/microsoft/TypeScript, npm install, etc
- Set breakpoint on the line after
const links = ...
ingetTypeOfVariableOrParameterOrProperty
in checker.ts. - With
.vscode/launch.template.json
copied to.vscode/launch.json
, open2dArrays.ts
and run the test via the “mocha tests” launcher. - Once the breakpoint is hit, open the debug console and type
links
. - Note the stack trace which mentions
links2
. - Disable source mapped stepping; note the variable is called
links
, notlinks2
, and now the debug console works.
Log File
vscode-debugadapter-07d5029d.json.gz
VS Code Version: 1.74.3 with debugger v2023.1.3017
Additional context
Also, the error that’s thrown bypasses #1259, somehow; the error is huge.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 23 (23 by maintainers)
Commits related to this issue
- fix: make variable renames scope-aware Fixes #1542 — committed to microsoft/vscode-js-debug by connor4312 a year ago
Yeah, I think that one is somewhat the same as: https://github.com/microsoft/vscode-js-debug/issues/1542#issuecomment-1416537774
I played with actually doing the parsing to make renames scope-aware. As expected, it can be slow for large files. But if I put it in a worker, it should be okay: https://github.com/microsoft/vscode-js-debug/pull/1548
A faster approach for just this would be doing curly-brace matching instead of full AST parsing, which could be sufficient, but not as correct, since we want to actually include everything in the containing statement rather than just variables declared in each block (such as function parameters)