From 7a500fbf5e4238d93443b4b7a7b05d55f1f5be86 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 Oct 2014 11:33:21 -0700 Subject: [PATCH] Set breakpoint on whole enum declaration if set on the enum name of enum keyword --- src/services/breakpoints.ts | 26 +-- .../baselines/reference/bpSpan_enums.baseline | 165 +++++++++++++++++- .../fourslash/breakpointValidationEnums.ts | 23 +++ 3 files changed, 187 insertions(+), 27 deletions(-) diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1bb1fafeb35..15140f6c64a 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -161,10 +161,8 @@ module ts.BreakpointResolver { return spanInImportDeclaration(node); case SyntaxKind.EnumDeclaration: - return spanInEnumDeclaration(node); - case SyntaxKind.EnumMember: - return spanInEnumMember(node); + return textSpan(node); case SyntaxKind.ModuleDeclaration: return spanInModuleDeclaration(node); @@ -431,19 +429,6 @@ module ts.BreakpointResolver { return textSpan(importDeclaration, importDeclaration.entityName || importDeclaration.externalModuleName); } - function spanInEnumDeclaration(enumDeclaration: EnumDeclaration): TypeScript.TextSpan { - if (enumDeclaration.members.length) { - return spanInEnumMember(enumDeclaration.members[0]); - } - - // On close brace - return spanInNode(enumDeclaration.getLastToken(sourceFile)); - } - - function spanInEnumMember(enumMember: EnumMember) { - return textSpan(enumMember); - } - function spanInModuleDeclaration(moduleDeclaration: ModuleDeclaration): TypeScript.TextSpan { return spanInNode(moduleDeclaration.body); } @@ -466,8 +451,13 @@ module ts.BreakpointResolver { // Tokens: function spanInOpenBraceToken(node: Node): TypeScript.TextSpan { - if (node.parent.kind === SyntaxKind.SwitchStatement) { - return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); + switch (node.parent.kind) { + case SyntaxKind.EnumDeclaration: + var enumDeclaration = node.parent; + return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile)); + + case SyntaxKind.SwitchStatement: + return spanInNodeIfStartsOnSameLine(node.parent, (node.parent).clauses[0]); } // Default to parent node diff --git a/tests/baselines/reference/bpSpan_enums.baseline b/tests/baselines/reference/bpSpan_enums.baseline index c239d421da5..1dd77f8d417 100644 --- a/tests/baselines/reference/bpSpan_enums.baseline +++ b/tests/baselines/reference/bpSpan_enums.baseline @@ -1,9 +1,13 @@ 1 >enum e { - ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":13,"length":1} - >x - >:=> (line 2, col 4) to (line 2, col 5) + ~~~~~~~~~ => Pos: (0 to 8) SpanInfo: {"start":0,"length":30} + >enum e { + > x, + > y, + > x + >} + >:=> (line 1, col 0) to (line 5, col 1) -------------------------------- 2 > x, @@ -31,9 +35,14 @@ -------------------------------- 6 >enum e2 { - ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":45,"length":6} - >x = 10 - >:=> (line 7, col 4) to (line 7, col 10) + ~~~~~~~~~~ => Pos: (31 to 40) SpanInfo: {"start":31,"length":49} + >enum e2 { + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 6, col 0) to (line 11, col 1) -------------------------------- 7 > x = 10, @@ -67,9 +76,10 @@ -------------------------------- 12 >enum e3 { - ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":91,"length":1} + ~~~~~~~~~~ => Pos: (81 to 90) SpanInfo: {"start":81,"length":11} + >enum e3 { >} - >:=> (line 13, col 0) to (line 13, col 1) + >:=> (line 12, col 0) to (line 13, col 1) -------------------------------- 13 >} @@ -98,4 +108,141 @@ ~~~~~~~ => Pos: (132 to 138) SpanInfo: undefined -------------------------------- 19 >} - ~ => Pos: (139 to 139) SpanInfo: undefined \ No newline at end of file + + ~~ => Pos: (139 to 140) SpanInfo: undefined +-------------------------------- +20 >enum e11 + + ~~~~~~~~~~ => Pos: (141 to 150) SpanInfo: {"start":141,"length":33} + >enum e11 + >{ + > x, + > y, + > x + >} + >:=> (line 20, col 0) to (line 25, col 1) +-------------------------------- +21 >{ + + ~~ => Pos: (151 to 152) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +22 > x, + + ~~~~~~~ => Pos: (153 to 159) SpanInfo: {"start":157,"length":1} + >x + >:=> (line 22, col 4) to (line 22, col 5) +-------------------------------- +23 > y, + + ~~~~~~~ => Pos: (160 to 166) SpanInfo: {"start":164,"length":1} + >y + >:=> (line 23, col 4) to (line 23, col 5) +-------------------------------- +24 > x + + ~~~~~~ => Pos: (167 to 172) SpanInfo: {"start":171,"length":1} + >x + >:=> (line 24, col 4) to (line 24, col 5) +-------------------------------- +25 >} + + ~~ => Pos: (173 to 174) SpanInfo: {"start":173,"length":1} + >} + >:=> (line 25, col 0) to (line 25, col 1) +-------------------------------- +26 >enum e12 + + ~~~~~~~~~ => Pos: (175 to 183) SpanInfo: {"start":175,"length":50} + >enum e12 + >{ + > x = 10, + > y = 10, + > z, + > x2 + >} + >:=> (line 26, col 0) to (line 32, col 1) +-------------------------------- +27 >{ + + ~~ => Pos: (184 to 185) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +28 > x = 10, + + ~~~~~~~~~~~~ => Pos: (186 to 197) SpanInfo: {"start":190,"length":6} + >x = 10 + >:=> (line 28, col 4) to (line 28, col 10) +-------------------------------- +29 > y = 10, + + ~~~~~~~~~~~~ => Pos: (198 to 209) SpanInfo: {"start":202,"length":6} + >y = 10 + >:=> (line 29, col 4) to (line 29, col 10) +-------------------------------- +30 > z, + + ~~~~~~~ => Pos: (210 to 216) SpanInfo: {"start":214,"length":1} + >z + >:=> (line 30, col 4) to (line 30, col 5) +-------------------------------- +31 > x2 + + ~~~~~~~ => Pos: (217 to 223) SpanInfo: {"start":221,"length":2} + >x2 + >:=> (line 31, col 4) to (line 31, col 6) +-------------------------------- +32 >} + + ~~ => Pos: (224 to 225) SpanInfo: {"start":224,"length":1} + >} + >:=> (line 32, col 0) to (line 32, col 1) +-------------------------------- +33 >enum e13 + + ~~~~~~~~~ => Pos: (226 to 234) SpanInfo: {"start":226,"length":12} + >enum e13 + >{ + >} + >:=> (line 33, col 0) to (line 35, col 1) +-------------------------------- +34 >{ + + ~~ => Pos: (235 to 236) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +35 >} + + ~~ => Pos: (237 to 238) SpanInfo: {"start":237,"length":1} + >} + >:=> (line 35, col 0) to (line 35, col 1) +-------------------------------- +36 >declare enum e14 + + ~~~~~~~~~~~~~~~~~ => Pos: (239 to 255) SpanInfo: undefined +-------------------------------- +37 >{ + + ~~ => Pos: (256 to 257) SpanInfo: undefined +-------------------------------- +38 > x, + + ~~~~~~~ => Pos: (258 to 264) SpanInfo: undefined +-------------------------------- +39 > y, + + ~~~~~~~ => Pos: (265 to 271) SpanInfo: undefined +-------------------------------- +40 > z, + + ~~~~~~~ => Pos: (272 to 278) SpanInfo: undefined +-------------------------------- +41 > x2 + + ~~~~~~~ => Pos: (279 to 285) SpanInfo: undefined +-------------------------------- +42 >} + ~ => Pos: (286 to 286) SpanInfo: undefined \ No newline at end of file diff --git a/tests/cases/fourslash/breakpointValidationEnums.ts b/tests/cases/fourslash/breakpointValidationEnums.ts index cd0dbbdfb23..9d45462013a 100644 --- a/tests/cases/fourslash/breakpointValidationEnums.ts +++ b/tests/cases/fourslash/breakpointValidationEnums.ts @@ -21,5 +21,28 @@ //// z, //// x2 ////} +////enum e11 +////{ +//// x, +//// y, +//// x +////} +////enum e12 +////{ +//// x = 10, +//// y = 10, +//// z, +//// x2 +////} +////enum e13 +////{ +////} +////declare enum e14 +////{ +//// x, +//// y, +//// z, +//// x2 +////} verify.baselineCurrentFileBreakpointLocations(); \ No newline at end of file