From 4a8a8920a2b53d38e7522ef1f9a99df3e0da4326 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 20 Oct 2014 23:01:06 -0700 Subject: [PATCH] Do not set breakpoints on the blank line or comment only line --- src/services/breakpoints.ts | 9 +++++-- .../reference/bpSpan_classes.baseline | 24 +++++-------------- .../reference/bpSpan_inBlankLine.baseline | 15 ++++++++++++ .../reference/bpSpan_inComments.baseline | 19 +++++++++++++++ .../reference/bpSpan_module.baseline | 4 +--- .../breakpointValidationInBlankLine.ts | 9 +++++++ .../breakpointValidationInComments.ts | 10 ++++++++ 7 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 tests/baselines/reference/bpSpan_inBlankLine.baseline create mode 100644 tests/baselines/reference/bpSpan_inComments.baseline create mode 100644 tests/cases/fourslash/breakpointValidationInBlankLine.ts create mode 100644 tests/cases/fourslash/breakpointValidationInComments.ts diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index a9c9bfaff77..a7527d92614 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -10,7 +10,7 @@ module ts.BreakpointResolver { export function spanInSourceFileAtLocation(sourceFile: SourceFile, position: number) { // Cannot set breakpoint in dts file if (sourceFile.flags & NodeFlags.DeclarationFile) { - return; + return undefined; } var tokenAtLocation = getTokenAtPosition(sourceFile, position); @@ -22,11 +22,16 @@ module ts.BreakpointResolver { // token at position will return var keyword on second line as the token but we would like to use // token on same line if trailing trivia (comments or white spaces on same line) part of the last token on that line tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile); + + // Its a blank line + if (!tokenAtLocation || sourceFile.getLineAndCharacterFromPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) { + return undefined; + } } // Cannot set breakpoint in ambient declarations if (isInAmbientContext(tokenAtLocation)) { - return; + return undefined; } // Get the span in the node based on its syntax diff --git a/tests/baselines/reference/bpSpan_classes.baseline b/tests/baselines/reference/bpSpan_classes.baseline index 88409460d03..73089699a2b 100644 --- a/tests/baselines/reference/bpSpan_classes.baseline +++ b/tests/baselines/reference/bpSpan_classes.baseline @@ -45,9 +45,7 @@ -------------------------------- 7 > - ~ => Pos: (113 to 113) SpanInfo: {"start":111,"length":1} - >} - >:=> (line 6, col 8) to (line 6, col 9) + ~ => Pos: (113 to 113) SpanInfo: undefined -------------------------------- 8 > greet() { @@ -75,15 +73,11 @@ -------------------------------- 12 > - ~ => Pos: (201 to 201) SpanInfo: {"start":199,"length":1} - >} - >:=> (line 11, col 4) to (line 11, col 5) + ~ => Pos: (201 to 201) SpanInfo: undefined -------------------------------- 13 > - ~ => Pos: (202 to 202) SpanInfo: {"start":199,"length":1} - >} - >:=> (line 11, col 4) to (line 11, col 5) + ~ => Pos: (202 to 202) SpanInfo: undefined -------------------------------- 14 > function foo(greeting: string): Greeter { @@ -110,9 +104,7 @@ -------------------------------- 17 > - ~ => Pos: (293 to 293) SpanInfo: {"start":291,"length":1} - >} - >:=> (line 16, col 4) to (line 16, col 5) + ~ => Pos: (293 to 293) SpanInfo: undefined -------------------------------- 18 > var greeter = new Greeter("Hello, world!"); @@ -213,9 +205,7 @@ -------------------------------- 27 > - ~ => Pos: (695 to 695) SpanInfo: {"start":639,"length":44} - >greeters.push(new Greeter(restGreetings[i])) - >:=> (line 25, col 12) to (line 25, col 56) + ~ => Pos: (695 to 695) SpanInfo: undefined -------------------------------- 28 > return greeters; @@ -231,9 +221,7 @@ -------------------------------- 30 > - ~ => Pos: (727 to 727) SpanInfo: {"start":725,"length":1} - >} - >:=> (line 29, col 4) to (line 29, col 5) + ~ => Pos: (727 to 727) SpanInfo: undefined -------------------------------- 31 > var b = foo2("Hello", "World", "!"); diff --git a/tests/baselines/reference/bpSpan_inBlankLine.baseline b/tests/baselines/reference/bpSpan_inBlankLine.baseline new file mode 100644 index 00000000000..40fe26a16a6 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inBlankLine.baseline @@ -0,0 +1,15 @@ + +1 >var x = 10; + + ~~~~~~~~~~~~ => Pos: (0 to 11) SpanInfo: {"start":0,"length":10} + >var x = 10 + >:=> (line 1, col 0) to (line 1, col 10) +-------------------------------- +2 > + + ~ => Pos: (12 to 12) SpanInfo: undefined +-------------------------------- +3 >var y = 10; + ~~~~~~~~~~~ => Pos: (13 to 23) SpanInfo: {"start":13,"length":10} + >var y = 10 + >:=> (line 3, col 0) to (line 3, col 10) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_inComments.baseline b/tests/baselines/reference/bpSpan_inComments.baseline new file mode 100644 index 00000000000..5c167293513 --- /dev/null +++ b/tests/baselines/reference/bpSpan_inComments.baseline @@ -0,0 +1,19 @@ + +1 >/*comment here*/ var x = 10; /*comment here*/ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (0 to 45) SpanInfo: {"start":17,"length":10} + >var x = 10 + >:=> (line 1, col 17) to (line 1, col 27) +-------------------------------- +2 >// comment only line + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (46 to 66) SpanInfo: undefined +-------------------------------- +3 >/*multiline comment + + ~~~~~~~~~~~~~~~~~~~~ => Pos: (67 to 86) SpanInfo: undefined +-------------------------------- +4 >another line of multiline comment */ var y = 10; // comment here + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (87 to 150) SpanInfo: {"start":124,"length":10} + >var y = 10 + >:=> (line 4, col 37) to (line 4, col 47) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index f00595e2b1e..cdeae25a1dd 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -49,9 +49,7 @@ -------------------------------- 9 > - ~ => Pos: (100 to 100) SpanInfo: {"start":98,"length":1} - >} - >:=> (line 8, col 4) to (line 8, col 5) + ~ => Pos: (100 to 100) SpanInfo: undefined -------------------------------- 10 > export function foo() { diff --git a/tests/cases/fourslash/breakpointValidationInBlankLine.ts b/tests/cases/fourslash/breakpointValidationInBlankLine.ts new file mode 100644 index 00000000000..03814fd8157 --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInBlankLine.ts @@ -0,0 +1,9 @@ +/// + +// @BaselineFile: bpSpan_inBlankLine.baseline +// @Filename: bpSpan_inBlankLine.ts +////var x = 10; +//// +////var y = 10; + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationInComments.ts b/tests/cases/fourslash/breakpointValidationInComments.ts new file mode 100644 index 00000000000..3369db00eeb --- /dev/null +++ b/tests/cases/fourslash/breakpointValidationInComments.ts @@ -0,0 +1,10 @@ +/// + +// @BaselineFile: bpSpan_inComments.baseline +// @Filename: bpSpan_inComments.ts +/////*comment here*/ var x = 10; /*comment here*/ +////// comment only line +/////*multiline comment +////another line of multiline comment */ var y = 10; // comment here + +verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file