-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Fix debug expression hover for TypeScript non-null assertions (!) #252116
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
Conversation
…ixes regex pattern Co-authored-by: roblourens <323878+roblourens@users.noreply.github.com>
!
(like foo!.bar
) while debugging does not evaluate the expression@@ -35,6 +35,10 @@ suite('Debug - Utils', () => { | |||
assert.deepStrictEqual(getExactExpressionStartAndEnd('var t = a.b.c.d.name', 16, 20), { start: 9, end: 20 }); | |||
assert.deepStrictEqual(getExactExpressionStartAndEnd('MyClass::StaticProp', 10, 20), { start: 1, end: 19 }); | |||
assert.deepStrictEqual(getExactExpressionStartAndEnd('largeNumber = myVar?.prop', 21, 25), { start: 15, end: 25 }); | |||
// Test non-null assertion operator - this should work like optional chaining | |||
assert.deepStrictEqual(getExactExpressionStartAndEnd('largeNumber = myVar!.prop', 21, 25), { start: 15, end: 25 }); | |||
assert.deepStrictEqual(getExactExpressionStartAndEnd('a!.length', 1, 2), { start: 1, end: 9 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 30679a9. The issue was in the expression truncation logic - when hovering over the first character of a!.length
, it was incorrectly truncating at the word boundary after a
. Added special handling for the non-null assertion operator to prevent truncation when a word is immediately followed by !
.
// Match any character except a set of characters which often break interesting sub-expressions | ||
const expression: RegExp = /([^()\[\]{}<>\s+\-/%~#^;=|,`!]|\->)+/g; | ||
const expression: RegExp = /([^()\[\]{}<>\s+\-/%~#^;=|,`]|\->)+/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that !foo
is broken now, add a test case to ensure it would be resolved as foo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test case and fix in commit 5a61ddc. Now !foo
correctly resolves to foo
when hovering over the variable part, while preserving !foo
when hovering directly over the !
operator.
Co-authored-by: roblourens <323878+roblourens@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: roblourens <323878+roblourens@users.noreply.github.com>
Run the hygiene npm script |
Co-authored-by: roblourens <323878+roblourens@users.noreply.github.com>
Hygiene script completed successfully. Fixed formatting issue with trailing whitespace in ae9bf63. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
When debugging in VS Code, hovering over expressions containing the TypeScript non-null assertion operator
!
(likea!.length
) did not evaluate the complete expression. Instead, it would incorrectly break up the expression and only evaluate partial segments.Problem
The issue was in the
getExactExpressionStartAndEnd()
function indebugUtils.ts
. The regex pattern explicitly excluded the!
character:This caused expressions like
a!.length
to be broken up as separate tokens (a
and.length
) instead of being treated as a single evaluatable expression.Solution
Removed
!
from the character exclusion list in the regex pattern:Testing
Added comprehensive test cases for non-null assertion expressions:
Before fix: Hovering over
length
ina!.length
would only evaluate.length
(partial expression)After fix: Hovering over
length
ina!.length
correctly evaluatesa!.length
(complete expression)Verification
a!.length
) now work like optional chaining (a?.length
)myVar!.prop
) work correctlyFixes #238279.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.