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:

  1. Clone https://github.com/microsoft/TypeScript, npm install, etc
  2. Set breakpoint on the line after const links = ... in getTypeOfVariableOrParameterOrProperty in checker.ts.
  3. With .vscode/launch.template.json copied to .vscode/launch.json, open 2dArrays.ts and run the test via the “mocha tests” launcher.
  4. Once the breakpoint is hit, open the debug console and type links.
  5. Note the stack trace which mentions links2.
  6. Disable source mapped stepping; note the variable is called links, not links2, 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

Most upvoted comments

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)