Skip to content

Commit 6edba30

Browse files
authored
Fix spread operator with debug hover (microsoft#252123)
For microsoft#252122
1 parent e760e15 commit 6edba30

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/vs/workbench/contrib/debug/common/debugUtils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ export function isDebuggerMainContribution(dbg: IDebuggerContribution) {
7878
return dbg.type && (dbg.label || dbg.program || dbg.runtime);
7979
}
8080

81+
/**
82+
* Note- uses 1-indexed numbers
83+
*/
8184
export function getExactExpressionStartAndEnd(lineContent: string, looseStart: number, looseEnd: number): { start: number; end: number } {
8285
let matchingExpression: string | undefined = undefined;
8386
let startOffset = 0;
8487

85-
// Some example supported expressions: myVar.prop, a.b.c.d, myVar?.prop, myVar->prop, MyClass::StaticProp, *myVar
88+
// Some example supported expressions: myVar.prop, a.b.c.d, myVar?.prop, myVar->prop, MyClass::StaticProp, *myVar, ...foo
8689
// Match any character except a set of characters which often break interesting sub-expressions
8790
const expression: RegExp = /([^()\[\]{}<>\s+\-/%~#^;=|,`!]|\->)+/g;
8891
let result: RegExpExecArray | null = null;
@@ -99,6 +102,15 @@ export function getExactExpressionStartAndEnd(lineContent: string, looseStart: n
99102
}
100103
}
101104

105+
// Handle spread syntax: if the expression starts with '...', extract just the identifier
106+
if (matchingExpression) {
107+
const spreadMatch = matchingExpression.match(/^\.\.\.(.+)/);
108+
if (spreadMatch) {
109+
matchingExpression = spreadMatch[1];
110+
startOffset += 3; // Skip the '...' prefix
111+
}
112+
}
113+
102114
// If there are non-word characters after the cursor, we want to truncate the expression then.
103115
// For example in expression 'a.b.c.d', if the focus was under 'b', 'a.b' would be evaluated.
104116
if (matchingExpression) {

src/vs/workbench/contrib/debug/test/browser/debugUtils.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ suite('Debug - Utils', () => {
2525

2626
test('getExactExpressionStartAndEnd', () => {
2727
assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 2), { start: 1, end: 3 });
28+
assert.deepStrictEqual(getExactExpressionStartAndEnd('!foo', 2, 3), { start: 2, end: 4 });
2829
assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 3), { start: 1, end: 3 });
2930
assert.deepStrictEqual(getExactExpressionStartAndEnd('foo', 1, 4), { start: 1, end: 3 });
3031
assert.deepStrictEqual(getExactExpressionStartAndEnd('this.name = "John"', 1, 10), { start: 1, end: 9 });
@@ -44,6 +45,10 @@ suite('Debug - Utils', () => {
4445

4546
assert.deepStrictEqual(getExactExpressionStartAndEnd('var aøñéå文 = a.b.c-d.name', 5, 5), { start: 5, end: 10 });
4647
assert.deepStrictEqual(getExactExpressionStartAndEnd('aøñéå文.aøñéå文.aøñéå文', 9, 9), { start: 1, end: 13 });
48+
49+
// Spread syntax should extract just the identifier
50+
assert.deepStrictEqual(getExactExpressionStartAndEnd('[...bar]', 5, 7), { start: 5, end: 7 });
51+
assert.deepStrictEqual(getExactExpressionStartAndEnd('...variable', 5, 5), { start: 4, end: 11 });
4752
});
4853

4954
test('config presentation', () => {

0 commit comments

Comments
 (0)