diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 22b28cd3ffe..40b18b1edc4 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -318,10 +318,19 @@ module ts.BreakpointResolver { } } + function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionDeclaration) { + return !!(functionDeclaration.flags & NodeFlags.Export); + } + function spanInFunctionDeclaration(functionDeclaration: FunctionDeclaration): TypeScript.TextSpan { // No breakpoints in the function signature if (!functionDeclaration.body) { - return; + return undefined; + } + + if (canFunctionHaveSpanInWholeDeclaration(functionDeclaration)) { + // Set the span on whole function declaration + return textSpan(functionDeclaration); } // Set span in function body @@ -329,12 +338,12 @@ module ts.BreakpointResolver { } function spanInFunctionBlock(block: Block): TypeScript.TextSpan { - if (block.statements.length) { - return spanInFirstStatementOfBlock(block); + var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken(); + if (canFunctionHaveSpanInWholeDeclaration(block.parent)) { + return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock); } - // On close parenthesis - return spanInNode(block.getLastToken()); + return spanInNode(nodeForSpanInBlock); } function spanInFirstStatementOfBlock(block: Block): TypeScript.TextSpan { diff --git a/tests/baselines/reference/bpSpan_functions.baseline b/tests/baselines/reference/bpSpan_functions.baseline index 623474ec93b..535f177c0f6 100644 --- a/tests/baselines/reference/bpSpan_functions.baseline +++ b/tests/baselines/reference/bpSpan_functions.baseline @@ -97,6 +97,276 @@ >:=> (line 12, col 4) to (line 12, col 10) -------------------------------- 13 >} - ~ => Pos: (323 to 323) SpanInfo: {"start":323,"length":1} + + ~~ => Pos: (323 to 324) SpanInfo: {"start":323,"length":1} >} - >:=> (line 13, col 0) to (line 13, col 1) \ No newline at end of file + >:=> (line 13, col 0) to (line 13, col 1) +-------------------------------- +14 >module m { + + ~~~~~~~~~~~ => Pos: (325 to 335) SpanInfo: {"start":325,"length":389} + >module m { + > var greetings = 0; + > function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 14, col 0) to (line 28, col 1) +-------------------------------- +15 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (336 to 358) SpanInfo: {"start":340,"length":17} + >var greetings = 0 + >:=> (line 15, col 4) to (line 15, col 21) +-------------------------------- +16 > function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (359 to 405) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +17 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (406 to 426) SpanInfo: {"start":414,"length":11} + >greetings++ + >:=> (line 17, col 8) to (line 17, col 19) +-------------------------------- +18 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (427 to 452) SpanInfo: {"start":435,"length":16} + >return greetings + >:=> (line 18, col 8) to (line 18, col 24) +-------------------------------- +19 > } + + ~~~~~~ => Pos: (453 to 458) SpanInfo: {"start":457,"length":1} + >} + >:=> (line 19, col 4) to (line 19, col 5) +-------------------------------- +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (459 to 495) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (496 to 515) SpanInfo: {"start":497,"length":6} + >n = 10 + >:=> (line 20, col 38) to (line 20, col 44) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (516 to 548) SpanInfo: {"start":517,"length":23} + >...restParams: string[] + >:=> (line 20, col 58) to (line 20, col 81) +20 > function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (549 to 551) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +21 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (552 to 572) SpanInfo: {"start":560,"length":11} + >greetings++ + >:=> (line 21, col 8) to (line 21, col 19) +-------------------------------- +22 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (573 to 598) SpanInfo: {"start":581,"length":16} + >return greetings + >:=> (line 22, col 8) to (line 22, col 24) +-------------------------------- +23 > } + + ~~~~~~ => Pos: (599 to 604) SpanInfo: {"start":603,"length":1} + >} + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (605 to 638) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (639 to 658) SpanInfo: {"start":640,"length":6} + >n = 10 + >:=> (line 24, col 35) to (line 24, col 41) +24 > function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (659 to 684) SpanInfo: {"start":660,"length":23} + >...restParams: string[] + >:=> (line 24, col 55) to (line 24, col 78) +-------------------------------- +25 > { + + ~~~~~~ => Pos: (685 to 690) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +26 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (691 to 706) SpanInfo: {"start":699,"length":6} + >return + >:=> (line 26, col 8) to (line 26, col 14) +-------------------------------- +27 > } + + ~~~~~~ => Pos: (707 to 712) SpanInfo: {"start":711,"length":1} + >} + >:=> (line 27, col 4) to (line 27, col 5) +-------------------------------- +28 >} + + ~~ => Pos: (713 to 714) SpanInfo: {"start":713,"length":1} + >} + >:=> (line 28, col 0) to (line 28, col 1) +-------------------------------- +29 >module m1 { + + ~~~~~~~~~~~~ => Pos: (715 to 726) SpanInfo: {"start":715,"length":411} + >module m1 { + > var greetings = 0; + > export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >} + >:=> (line 29, col 0) to (line 43, col 1) +-------------------------------- +30 > var greetings = 0; + + ~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (727 to 749) SpanInfo: {"start":731,"length":17} + >var greetings = 0 + >:=> (line 30, col 4) to (line 30, col 21) +-------------------------------- +31 > export function greet(greeting: string): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (750 to 803) SpanInfo: {"start":754,"length":102} + >export function greet(greeting: string): number { + > greetings++; + > return greetings; + > } + >:=> (line 31, col 4) to (line 34, col 5) +-------------------------------- +32 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (804 to 824) SpanInfo: {"start":812,"length":11} + >greetings++ + >:=> (line 32, col 8) to (line 32, col 19) +-------------------------------- +33 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (825 to 850) SpanInfo: {"start":833,"length":16} + >return greetings + >:=> (line 33, col 8) to (line 33, col 24) +-------------------------------- +34 > } + + ~~~~~~ => Pos: (851 to 856) SpanInfo: {"start":855,"length":1} + >} + >:=> (line 34, col 4) to (line 34, col 5) +-------------------------------- +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (857 to 900) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (901 to 920) SpanInfo: {"start":902,"length":6} + >n = 10 + >:=> (line 35, col 45) to (line 35, col 51) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (921 to 953) SpanInfo: {"start":922,"length":23} + >...restParams: string[] + >:=> (line 35, col 65) to (line 35, col 88) +35 > export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + + ~~~=> Pos: (954 to 956) SpanInfo: {"start":861,"length":148} + >export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { + > greetings++; + > return greetings; + > } + >:=> (line 35, col 4) to (line 38, col 5) +-------------------------------- +36 > greetings++; + + ~~~~~~~~~~~~~~~~~~~~~ => Pos: (957 to 977) SpanInfo: {"start":965,"length":11} + >greetings++ + >:=> (line 36, col 8) to (line 36, col 19) +-------------------------------- +37 > return greetings; + + ~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (978 to 1003) SpanInfo: {"start":986,"length":16} + >return greetings + >:=> (line 37, col 8) to (line 37, col 24) +-------------------------------- +38 > } + + ~~~~~~ => Pos: (1004 to 1009) SpanInfo: {"start":1008,"length":1} + >} + >:=> (line 38, col 4) to (line 38, col 5) +-------------------------------- +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (1010 to 1050) SpanInfo: {"start":1014,"length":110} + >export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + > { + > return; + > } + >:=> (line 39, col 4) to (line 42, col 5) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~=> Pos: (1051 to 1070) SpanInfo: {"start":1052,"length":6} + >n = 10 + >:=> (line 39, col 42) to (line 39, col 48) +39 > export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) + + ~~~~~~~~~~~~~~~~~~~~~~~~~~=> Pos: (1071 to 1096) SpanInfo: {"start":1072,"length":23} + >...restParams: string[] + >:=> (line 39, col 62) to (line 39, col 85) +-------------------------------- +40 > { + + ~~~~~~ => Pos: (1097 to 1102) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +41 > return; + + ~~~~~~~~~~~~~~~~ => Pos: (1103 to 1118) SpanInfo: {"start":1111,"length":6} + >return + >:=> (line 41, col 8) to (line 41, col 14) +-------------------------------- +42 > } + + ~~~~~~ => Pos: (1119 to 1124) SpanInfo: {"start":1123,"length":1} + >} + >:=> (line 42, col 4) to (line 42, col 5) +-------------------------------- +43 >} + ~ => Pos: (1125 to 1125) SpanInfo: {"start":1125,"length":1} + >} + >:=> (line 43, col 0) to (line 43, col 1) \ No newline at end of file diff --git a/tests/baselines/reference/bpSpan_module.baseline b/tests/baselines/reference/bpSpan_module.baseline index bdf5d486175..14145512658 100644 --- a/tests/baselines/reference/bpSpan_module.baseline +++ b/tests/baselines/reference/bpSpan_module.baseline @@ -66,9 +66,11 @@ -------------------------------- 10 > export function foo() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":137,"length":11} - >return m4.x - >:=> (line 11, col 8) to (line 11, col 19) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (101 to 128) SpanInfo: {"start":105,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 10, col 4) to (line 12, col 5) -------------------------------- 11 > return m4.x; @@ -192,9 +194,11 @@ -------------------------------- 29 > export function foo() { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":337,"length":11} - >return m4.x - >:=> (line 30, col 8) to (line 30, col 19) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => Pos: (301 to 328) SpanInfo: {"start":305,"length":50} + >export function foo() { + > return m4.x; + > } + >:=> (line 29, col 4) to (line 31, col 5) -------------------------------- 30 > return m4.x; diff --git a/tests/cases/fourslash/breakpointValidationFunctions.ts b/tests/cases/fourslash/breakpointValidationFunctions.ts index 4ab0c7c577e..0f38394d8e0 100644 --- a/tests/cases/fourslash/breakpointValidationFunctions.ts +++ b/tests/cases/fourslash/breakpointValidationFunctions.ts @@ -15,4 +15,35 @@ ////{ //// return; ////} +////module m { +//// var greetings = 0; +//// function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} +////module m1 { +//// var greetings = 0; +//// export function greet(greeting: string): number { +//// greetings++; +//// return greetings; +//// } +//// export function greet2(greeting: string, n = 10, x?: string, ...restParams: string[]): number { +//// greetings++; +//// return greetings; +//// } +//// export function foo(greeting: string, n = 10, x?: string, ...restParams: string[]) +//// { +//// return; +//// } +////} + verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file