diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 63701d1645c..23a2189d448 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -58,16 +58,21 @@ module ts.BreakpointResolver { return spanInVariableStatement(node); case SyntaxKind.VariableDeclaration: + case SyntaxKind.Property: return spanInVariableDeclaration(node); case SyntaxKind.Parameter: return spanInParameterDeclaration(node); case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: return spanInFunctionDeclaration(node); case SyntaxKind.FunctionBlock: - return spanInFirstStatementOfBlock(node); + return spanInFunctionBlock(node); case SyntaxKind.Block: case SyntaxKind.TryBlock: @@ -136,8 +141,7 @@ module ts.BreakpointResolver { return spanInModuleDeclaration(node); case SyntaxKind.ClassDeclaration: - // TODO - return; + return spanInClassDeclaration(node); case SyntaxKind.BinaryExpression: case SyntaxKind.PostfixOperator: @@ -274,6 +278,15 @@ module ts.BreakpointResolver { return spanInNode(functionDeclaration.body); } + function spanInFunctionBlock(block: Block): TypeScript.TextSpan { + if (block.statements.length) { + return spanInFirstStatementOfBlock(block); + } + + // On close parenthesis + return spanInNode(block.getLastToken()); + } + function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { // Set breakpoint in first statement return spanInNode(block.statements[0]); @@ -396,6 +409,14 @@ module ts.BreakpointResolver { return spanInNode(moduleDeclaration.body); } + function spanInClassDeclaration(classDeclaration: ClassDeclaration): TypeScript.TextSpan { + if (classDeclaration.members.length) { + return spanInNode(classDeclaration.members[0]); + } + + return spanInNode(classDeclaration.getLastToken()); + } + function spanInExpression(expression: Expression): TypeScript.TextSpan { //TODO (pick this up later) for now lets fix do-while baseline if (node.parent.kind === SyntaxKind.DoStatement) { // Set span as if on while keyword @@ -415,6 +436,10 @@ module ts.BreakpointResolver { function spanInCommaToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Method: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: case SyntaxKind.VariableStatement: case SyntaxKind.EnumDeclaration: return spanInPreviousNode(node); @@ -426,24 +451,19 @@ module ts.BreakpointResolver { } function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { - switch (node.parent.kind) { - case SyntaxKind.FunctionBlock: - // Span on first statement - return spanInFirstStatementOfBlock(node.parent); - - case SyntaxKind.SwitchStatement: - return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); - - // Default to parent node - default: - return spanInNode(node.parent); + if (node.parent.kind === SyntaxKind.SwitchStatement) { + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); } + + // Default to parent node + return spanInNode(node.parent); } function spanInCloseBraceToken(node: Node): TypeScript.TextSpan { switch (node.parent.kind) { case SyntaxKind.FunctionBlock: case SyntaxKind.EnumDeclaration: + case SyntaxKind.ClassDeclaration: // Span on close brace token return textSpan(node); diff --git a/tests/baselines/reference/bpSpan_class.baseline b/tests/baselines/reference/bpSpan_class.baseline new file mode 100644 index 00000000000..a628510bb9e --- /dev/null +++ b/tests/baselines/reference/bpSpan_class.baseline @@ -0,0 +1,120 @@ + +1 >class Greeter { + + ~~~~~~~~~~~~~~~~ => Pos: (0 to 15) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~ => Pos: (16 to 31) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (32 to 55) SpanInfo: {"start":32,"length":23} + >public greeting: string + >:=> (line 2, col 16) to (line 2, col 39) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~~~~~~~~~~~~~~=> Pos: (56 to 71) SpanInfo: {"start":57,"length":14} + >...b: string[] + >:=> (line 2, col 41) to (line 2, col 55) +2 > constructor(public greeting: string, ...b: string[]) { + + ~~~=> Pos: (72 to 74) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +3 > } + + ~~~~~~ => Pos: (75 to 80) SpanInfo: {"start":79,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) +-------------------------------- +4 > greet() { + + ~~~~~~~~~~~~~~ => Pos: (81 to 94) SpanInfo: {"start":103,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 5, col 8) to (line 5, col 47) +-------------------------------- +5 > return "

" + this.greeting + "

"; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (95 to 143) SpanInfo: {"start":103,"length":39} + >return "

" + this.greeting + "

" + >:=> (line 5, col 8) to (line 5, col 47) +-------------------------------- +6 > } + + ~~~~~~ => Pos: (144 to 149) SpanInfo: {"start":148,"length":1} + >} + >:=> (line 6, col 4) to (line 6, col 5) +-------------------------------- +7 > private x: string; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (150 to 172) SpanInfo: undefined +-------------------------------- +8 > private x1: number = 10; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (173 to 201) SpanInfo: {"start":177,"length":24} + >private x1: number = 10; + >:=> (line 8, col 4) to (line 8, col 28) +-------------------------------- +9 > private fn() { + + ~~~~~~~~~~~~~~~~~~~ => Pos: (202 to 220) SpanInfo: {"start":229,"length":20} + >return this.greeting + >:=> (line 10, col 8) to (line 10, col 28) +-------------------------------- +10 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (221 to 250) SpanInfo: {"start":229,"length":20} + >return this.greeting + >:=> (line 10, col 8) to (line 10, col 28) +-------------------------------- +11 > } + + ~~~~~~ => Pos: (251 to 256) SpanInfo: {"start":255,"length":1} + >} + >:=> (line 11, col 4) to (line 11, col 5) +-------------------------------- +12 > get greetings() { + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (257 to 278) SpanInfo: {"start":287,"length":20} + >return this.greeting + >:=> (line 13, col 8) to (line 13, col 28) +-------------------------------- +13 > return this.greeting; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (279 to 308) SpanInfo: {"start":287,"length":20} + >return this.greeting + >:=> (line 13, col 8) to (line 13, col 28) +-------------------------------- +14 > } + + ~~~~~~ => Pos: (309 to 314) SpanInfo: {"start":313,"length":1} + >} + >:=> (line 14, col 4) to (line 14, col 5) +-------------------------------- +15 > set greetings(greetings: string) { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (315 to 353) SpanInfo: {"start":362,"length":25} + >this.greeting = greetings + >:=> (line 16, col 8) to (line 16, col 33) +-------------------------------- +16 > this.greeting = greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (354 to 388) SpanInfo: {"start":362,"length":25} + >this.greeting = greetings + >:=> (line 16, col 8) to (line 16, col 33) +-------------------------------- +17 > } + + ~~~~~~ => Pos: (389 to 394) SpanInfo: {"start":393,"length":1} + >} + >:=> (line 17, col 4) to (line 17, col 5) +-------------------------------- +18 >} + ~ => Pos: (395 to 395) SpanInfo: {"start":395,"length":1} + >} + >:=> (line 18, col 0) to (line 18, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_classAmbient.baseline b/tests/baselines/reference/bpSpan_classAmbient.baseline new file mode 100644 index 00000000000..b168c5416c5 --- /dev/null +++ b/tests/baselines/reference/bpSpan_classAmbient.baseline @@ -0,0 +1,31 @@ + +1 >declare class Greeter { + + ~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (0 to 23) SpanInfo: undefined +-------------------------------- +2 > public greeting: string; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (24 to 52) SpanInfo: undefined +-------------------------------- +3 > constructor(greeting: string, ...b: string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (53 to 103) SpanInfo: undefined +-------------------------------- +4 > greet(): string; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (104 to 124) SpanInfo: undefined +-------------------------------- +5 > private val; + + ~~~~~~~~~~~~~~~~~ => Pos: (125 to 141) SpanInfo: undefined +-------------------------------- +6 > static x: number; + + ~~~~~~~~~~~~~~~~~~~~~~ => Pos: (142 to 163) SpanInfo: undefined +-------------------------------- +7 > static fn(a: number, ...b:string[]); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (164 to 204) SpanInfo: undefined +-------------------------------- +8 >} + ~ => Pos: (205 to 205) SpanInfo: undefined \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_exportAssignment.baseline b/tests/baselines/reference/bpSpan_exportAssignment.baseline index 19e4a4ba9bb..9086e218329 100644 --- a/tests/baselines/reference/bpSpan_exportAssignment.baseline +++ b/tests/baselines/reference/bpSpan_exportAssignment.baseline @@ -9,7 +9,9 @@ -------------------------------- 3 >} - ~~ => Pos: (24 to 25) SpanInfo: undefined + ~~ => Pos: (24 to 25) SpanInfo: {"start":24,"length":1} + >} + >:=> (line 3, col 0) to (line 3, col 1) -------------------------------- 4 >export = a; ~~~~~~~~~~~ => Pos: (26 to 36) SpanInfo: {"start":26,"length":10} diff --git a/tests/baselines/reference/bpSpan_import.baseline b/tests/baselines/reference/bpSpan_import.baseline index ef94afb42f0..bc729447306 100644 --- a/tests/baselines/reference/bpSpan_import.baseline +++ b/tests/baselines/reference/bpSpan_import.baseline @@ -1,15 +1,21 @@ 1 >module m { - ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: undefined + ~~~~~~~~~~~ => Pos: (0 to 10) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 2 > class c { - ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: undefined + ~~~~~~~~~~~~~~ => Pos: (11 to 24) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 3 > } - ~~~~~~ => Pos: (25 to 30) SpanInfo: undefined + ~~~~~~ => Pos: (25 to 30) SpanInfo: {"start":29,"length":1} + >} + >:=> (line 3, col 4) to (line 3, col 5) -------------------------------- 4 >} diff --git a/tests/cases/fourslash_old/breakpointValidationClass.ts b/tests/cases/fourslash/breakpointValidationClass.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClass.ts rename to tests/cases/fourslash/breakpointValidationClass.ts diff --git a/tests/cases/fourslash_old/breakpointValidationClassAmbient.ts b/tests/cases/fourslash/breakpointValidationClassAmbient.ts similarity index 100% rename from tests/cases/fourslash_old/breakpointValidationClassAmbient.ts rename to tests/cases/fourslash/breakpointValidationClassAmbient.ts