Skip to content

Commit 3663550

Browse files
committed
Breakpoint spans in try,catch,finally blocks and throw statement
1 parent 5bdeaa9 commit 3663550

3 files changed

Lines changed: 160 additions & 0 deletions

File tree

src/services/breakpoints.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ module ts.BreakpointResolver {
7070
return spanInFirstStatementOfBlock(<Block>node);
7171

7272
case SyntaxKind.Block:
73+
case SyntaxKind.TryBlock:
74+
case SyntaxKind.CatchBlock:
75+
case SyntaxKind.FinallyBlock:
7376
return spanInBlock(<Block>node);
7477

7578
case SyntaxKind.ExpressionStatement:
@@ -110,6 +113,12 @@ module ts.BreakpointResolver {
110113
case SyntaxKind.DefaultClause:
111114
return spanInCaseOrDefaultClause(<CaseOrDefaultClause>node);
112115

116+
case SyntaxKind.TryStatement:
117+
return spanInTryStatement(<TryStatement>node);
118+
119+
case SyntaxKind.ThrowStatement:
120+
return spanInThrowStatement(<ThrowStatement>node);
121+
113122
case SyntaxKind.BinaryExpression:
114123
case SyntaxKind.PostfixOperator:
115124
case SyntaxKind.PrefixOperator:
@@ -143,6 +152,8 @@ module ts.BreakpointResolver {
143152
return spanInWhileKeyword(node);
144153

145154
case SyntaxKind.ElseKeyword:
155+
case SyntaxKind.CatchKeyword:
156+
case SyntaxKind.FinallyKeyword:
146157
return spanInNextNode(node);
147158

148159
default:
@@ -332,6 +343,14 @@ module ts.BreakpointResolver {
332343
return spanInNode(caseOrDefaultClause.statements[0]);
333344
}
334345

346+
function spanInTryStatement(tryStatement: TryStatement): TypeScript.TextSpan {
347+
return spanInBlock(tryStatement.tryBlock);
348+
}
349+
350+
function spanInThrowStatement(throwStatement: ThrowStatement): TypeScript.TextSpan {
351+
return textSpan(throwStatement, throwStatement.expression);
352+
}
353+
335354
function spanInExpression(expression: Expression): TypeScript.TextSpan {
336355
//TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) {
337356
// Set span as if on while keyword
@@ -367,6 +386,9 @@ module ts.BreakpointResolver {
367386
return spanInFirstStatementOfBlock(<Block>node.parent);
368387

369388
case SyntaxKind.Block:
389+
case SyntaxKind.TryBlock:
390+
case SyntaxKind.CatchBlock:
391+
case SyntaxKind.FinallyBlock:
370392
return spanInBlock(<Block>node.parent);
371393

372394
case SyntaxKind.SwitchStatement:
@@ -385,6 +407,9 @@ module ts.BreakpointResolver {
385407
return textSpan(node);
386408

387409
case SyntaxKind.Block:
410+
case SyntaxKind.TryBlock:
411+
case SyntaxKind.CatchBlock:
412+
case SyntaxKind.FinallyBlock:
388413
return spanInLastStatementOfBlock(<Block>node.parent);
389414

390415
case SyntaxKind.SwitchStatement:
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
2+
1 >var x = 10;
3+
4+
~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10}
5+
>var x = 10
6+
>:=> (line 1, col 0) to (line 1, col 10)
7+
--------------------------------
8+
2 >try {
9+
10+
~~~~~~ => Pos: (12 to 17) SpanInfo: {"start":22,"length":9}
11+
>x = x + 1
12+
>:=> (line 3, col 4) to (line 3, col 13)
13+
--------------------------------
14+
3 > x = x + 1;
15+
16+
~~~~~~~~~~~~~~~ => Pos: (18 to 32) SpanInfo: {"start":22,"length":9}
17+
>x = x + 1
18+
>:=> (line 3, col 4) to (line 3, col 13)
19+
--------------------------------
20+
4 >} catch (e) {
21+
22+
~ => Pos: (33 to 33) SpanInfo: {"start":22,"length":9}
23+
>x = x + 1
24+
>:=> (line 3, col 4) to (line 3, col 13)
25+
4 >} catch (e) {
26+
27+
~~~~~~~~~~~~~ => Pos: (34 to 46) SpanInfo: {"start":51,"length":9}
28+
>x = x - 1
29+
>:=> (line 5, col 4) to (line 5, col 13)
30+
--------------------------------
31+
5 > x = x - 1;
32+
33+
~~~~~~~~~~~~~~~ => Pos: (47 to 61) SpanInfo: {"start":51,"length":9}
34+
>x = x - 1
35+
>:=> (line 5, col 4) to (line 5, col 13)
36+
--------------------------------
37+
6 >} finally {
38+
39+
~ => Pos: (62 to 62) SpanInfo: {"start":51,"length":9}
40+
>x = x - 1
41+
>:=> (line 5, col 4) to (line 5, col 13)
42+
6 >} finally {
43+
44+
~~~~~~~~~~~ => Pos: (63 to 73) SpanInfo: {"start":78,"length":10}
45+
>x = x * 10
46+
>:=> (line 7, col 4) to (line 7, col 14)
47+
--------------------------------
48+
7 > x = x * 10;
49+
50+
~~~~~~~~~~~~~~~~ => Pos: (74 to 89) SpanInfo: {"start":78,"length":10}
51+
>x = x * 10
52+
>:=> (line 7, col 4) to (line 7, col 14)
53+
--------------------------------
54+
8 >}
55+
56+
~~ => Pos: (90 to 91) SpanInfo: {"start":78,"length":10}
57+
>x = x * 10
58+
>:=> (line 7, col 4) to (line 7, col 14)
59+
--------------------------------
60+
9 >try
61+
62+
~~~~ => Pos: (92 to 95) SpanInfo: {"start":102,"length":9}
63+
>x = x + 1
64+
>:=> (line 11, col 4) to (line 11, col 13)
65+
--------------------------------
66+
10 >{
67+
68+
~~ => Pos: (96 to 97) SpanInfo: {"start":102,"length":9}
69+
>x = x + 1
70+
>:=> (line 11, col 4) to (line 11, col 13)
71+
--------------------------------
72+
11 > x = x + 1;
73+
74+
~~~~~~~~~~~~~~~ => Pos: (98 to 112) SpanInfo: {"start":102,"length":9}
75+
>x = x + 1
76+
>:=> (line 11, col 4) to (line 11, col 13)
77+
--------------------------------
78+
12 > throw new Error();
79+
80+
~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (113 to 135) SpanInfo: {"start":117,"length":17}
81+
>throw new Error()
82+
>:=> (line 12, col 4) to (line 12, col 21)
83+
--------------------------------
84+
13 >}
85+
86+
~~ => Pos: (136 to 137) SpanInfo: {"start":117,"length":17}
87+
>throw new Error()
88+
>:=> (line 12, col 4) to (line 12, col 21)
89+
--------------------------------
90+
14 >catch (e)
91+
92+
~~~~~~~~~~ => Pos: (138 to 147) SpanInfo: {"start":154,"length":9}
93+
>x = x - 1
94+
>:=> (line 16, col 4) to (line 16, col 13)
95+
--------------------------------
96+
15 >{
97+
98+
~~ => Pos: (148 to 149) SpanInfo: {"start":154,"length":9}
99+
>x = x - 1
100+
>:=> (line 16, col 4) to (line 16, col 13)
101+
--------------------------------
102+
16 > x = x - 1;
103+
104+
~~~~~~~~~~~~~~~ => Pos: (150 to 164) SpanInfo: {"start":154,"length":9}
105+
>x = x - 1
106+
>:=> (line 16, col 4) to (line 16, col 13)
107+
--------------------------------
108+
17 >}
109+
110+
~~ => Pos: (165 to 166) SpanInfo: {"start":154,"length":9}
111+
>x = x - 1
112+
>:=> (line 16, col 4) to (line 16, col 13)
113+
--------------------------------
114+
18 >finally
115+
116+
~~~~~~~~ => Pos: (167 to 174) SpanInfo: {"start":181,"length":10}
117+
>x = x * 10
118+
>:=> (line 20, col 4) to (line 20, col 14)
119+
--------------------------------
120+
19 >{
121+
122+
~~ => Pos: (175 to 176) SpanInfo: {"start":181,"length":10}
123+
>x = x * 10
124+
>:=> (line 20, col 4) to (line 20, col 14)
125+
--------------------------------
126+
20 > x = x * 10;
127+
128+
~~~~~~~~~~~~~~~~ => Pos: (177 to 192) SpanInfo: {"start":181,"length":10}
129+
>x = x * 10
130+
>:=> (line 20, col 4) to (line 20, col 14)
131+
--------------------------------
132+
21 >}
133+
~ => Pos: (193 to 193) SpanInfo: {"start":181,"length":10}
134+
>x = x * 10
135+
>:=> (line 20, col 4) to (line 20, col 14)

tests/cases/fourslash_old/breakpointValidationTryCatchFinally.ts renamed to tests/cases/fourslash/breakpointValidationTryCatchFinally.ts

File renamed without changes.

0 commit comments

Comments
 (0)