New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable renamed incorrectly, leading to thrown error #1542
Comments
This also appears to be related; when at the same breakpoint (and anywhere in debugging, really), if I write: (node) => node Into the debug console, I get:
But disabling source mapped stepping makes the problem go away. |
I think we may try to rename Renames are not AST-aware, we just try to get the closest rename. In general I really want to avoid having to parse source AST's. Maybe it's sufficient to generate a set of fallbacks, like |
To be clear, you mean avoiding parsing the AST of the debug console input? I would expect that to always be small so not actually expensive in practice.
That set of fallbacks won't work if the variable happens to be undefined already, though. I'm a little confused, though; in this case, node is not something that's actually in scope, so why is it getting a renaming at all? This to me sounds like the first part of the issue where it's spuriously using the name E.g. without source mapping:
|
We do parse debug console input, but we don't parse sources in the runtime. Sourcemaps just say "the thing at this location is now named something else", so to deal with renames we just pull the closest rename to the current stackframe for each identifier we find in the evaluate input.
If only one of the aliases is defined, it would still return undefined. Alternatively we could do a big try/catch to access each variable. Which would probably be fine...
If it's anywhere in the source before the current stackframe, we'll try to rename it. |
Hm, I guess I thought that the info from whatever powers the "variables" panel was in use here, since that seems to have the up-to-date scope information. But, obviously I'm not an expert at this. |
Yea, we could be a bit smarter about not renaming things that aren't in |
I suppose that's true, but you'd have to be careful about something like |
For me, doing that generates |
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: #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) |
Here's a trace log of the |
Wow, very odd, it's transforming it to:
|
Ahh, yep, that would do it. We added support for member access renames, but I didn't update the replacer to account for that. |
I'm hitting what I think is still this bug more and more. For example, I was debugging our parser and wanted completions on the scanner but didn't get any. Checking the variable, the debug console instead gave me the wrong thing entirely; compare source mapped versus not. I think @andrewbranch hit a case just like this with hover yesterday afternoon. |
Yep, I spent like 20 minutes trying to figure out why something was |
I'm on vacation currently and for the duration of next week, so this will not be fixed immediately, but soon. My current thinking is that I still really dislike parsing the AST of compiled code. Even in a worker, taking a second to do that means an (extra) second of delay before variables are available. One thing I'm considering is writing a script that:
(or use a lexer that can do this; currently we use acorn for parsing and manipulation, but it doesn't have a 'lex-only' mode) |
So far the best workaround I've had is to follow the instructions to install nightly, then downgrade the nightly verison to EDIT: except, breakpoints don't seem to work in this revision, so, not sure what's happening there. |
Yeah, I think that one is somewhat the same as: #1542 (comment) |
Looked at a few solutions. Using swc in webassembly is a bit faster than Acorn's parser, running 2.5 ops/s instead of acorn.parse()'s 0.9 ops/s for TypeScript's In my search I found https://github.com/guybedford/es-module-lexer, which is a lexer dedicated to the purpose of extracting import/export statements. It's widely used (12M downloads/month), tiny, and incredibly fast, handling run.js at 1,500,000 ops/s. My plan is to fork and repurpose that module for extracting the relevant information we need for scopes--or write something similar to it in rust or javascript. I have a 6 hour train ride today, so we'll see how far I can get :) |
Given a user's going to also have the TypeScript extension running, I wonder if it'd be possible to grab the info from there instead, given it should be already parsed and unlikely to change (so maybe quick). |
Although I guess these are output files so they wouldn't be immediate. I am curious about our parser's perf, of course. |
This is gone in #1566 |
Thanks! Looking forward to the next nightly or stable so I can try it out. |
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:
const links = ...
ingetTypeOfVariableOrParameterOrProperty
in checker.ts..vscode/launch.template.json
copied to.vscode/launch.json
, open2dArrays.ts
and run the test via the "mocha tests" launcher.links
.links2
.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.
The text was updated successfully, but these errors were encountered: