diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index a83ec813d06..a568667d182 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -549,7 +549,7 @@ module ts { result = []; } - result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind: kind }); + result.push({ pos: startPos, end: pos, hasTrailingNewLine, kind }); } continue; } diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 0d9895d148e..13ed3d3ea69 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -37,8 +37,7 @@ module ts { let isFirstSingleLineComment = true; let singleLineCommentCount = 0; - for (let i = 0; i < comments.length; i++) { - let currentComment = comments[i]; + for (let currentComment of comments) { // For single line comments, combine consecutive ones (2 or more) into // a single span from the start of the first till the end of the last @@ -50,9 +49,9 @@ module ts { lastSingleLineCommentEnd = currentComment.end; singleLineCommentCount++; } - else { + else if (currentComment.kind === SyntaxKind.MultiLineCommentTrivia) { combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd); - addOutliningSpanComments(currentComment, false); + addOutliningSpanComments(currentComment, /*autoCollapse*/ false); singleLineCommentCount = 0; lastSingleLineCommentEnd = -1; @@ -64,18 +63,16 @@ module ts { } } - function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) { - + function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) { // Only outline spans of two or more consecutive single line comments if (count > 1) { - let multipleSingleLineComments = { pos: start, end: end, kind: SyntaxKind.SingleLineCommentTrivia } - addOutliningSpanComments(multipleSingleLineComments, false); + addOutliningSpanComments(multipleSingleLineComments, /*autoCollapse*/ false); } } @@ -90,7 +87,10 @@ module ts { return; } - addOutliningForLeadingCommentsForNode(n); + if (isDeclaration(n)) { + addOutliningForLeadingCommentsForNode(n); + } + switch (n.kind) { case SyntaxKind.Block: if (!isFunctionBlock(n)) { diff --git a/tests/cases/fourslash/getOutliningForBlockComments.ts b/tests/cases/fourslash/getOutliningForBlockComments.ts new file mode 100644 index 00000000000..facbe741d76 --- /dev/null +++ b/tests/cases/fourslash/getOutliningForBlockComments.ts @@ -0,0 +1,104 @@ +/// + +////[|/* +//// Comment before module: +//// line one of the comment +//// line two of the comment +//// line three +//// line four +//// line five +////*/|] +////module Sayings [|{ +//// [|/* +//// Comment before class: +//// line one of the comment +//// line two of the comment +//// line three +//// line four +//// line five +//// */|] +//// export class Greeter [|{ +//// [|/* +//// Comment before a string identifier +//// line two of the comment +//// */|] +//// greeting: string; +//// [|/* +//// constructor +//// parameter message as a string +//// */|] +//// /* This is a single line block comment style. Should not be collapsed*/ +//// [|/* +//// Multiple comments should be collapsed individually +//// */|] +//// constructor(message: string /* do not collapse single lines*/) [|{ +//// this.greeting = message; +//// }|] +//// [|/* +//// method of a class +//// */|] +//// greet() [|{ +//// return "Hello, " + this.greeting; +//// }|] +//// }|] +////}|] +//// +////[|/* +//// Block comment for interface. The ending can be on the same line as the declaration. +////*/|]interface IFoo [|{ +//// [|/* +//// Multiple block comments +//// */|] +//// +//// [|/* +//// should be collapsed +//// */|] +//// +//// [|/* +//// individually +//// */|] +//// +//// [|/* +//// this comment has trailing space before /* and after *-/ signs +//// */|] +//// +//// [|/** +//// * +//// * +//// * +//// */|] +//// +//// [|/* +//// */|] +//// +//// [|/* +//// */|] +//// // single line comments in the middle should not have an effect +//// [|/* +//// */|] +//// +//// [|/* +//// */|] +//// +//// [|/* +//// this block comment ends +//// on the same line */|] [|/* where the following comment starts +//// should be collapsed separately +//// */|] +//// +//// getDist(): number; +////}|] +//// +////var x =[|{ +//// a:1, +//// b: 2, +//// [|/* +//// Over a function in an object literal +//// */|] +//// get foo() [|{ +//// return 1; +//// }|] +////}|] +verify.outliningSpansInCurrentFile(test.ranges()); + +