Skip to content

Commit e6c1afb

Browse files
Style changes and cleanup
1 parent 760812f commit e6c1afb

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/services/outliningElementsCollector.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
/* @internal */
22
namespace ts.OutliningElementsCollector {
3+
const collapseText = "...";
4+
const maxDepth = 20;
5+
36
export function collectElements(sourceFile: SourceFile, cancellationToken: CancellationToken): OutliningSpan[] {
47
const elements: OutliningSpan[] = [];
5-
const collapseText = "...";
68
let depth = 0;
7-
const maxDepth = 20;
89

910
walk(sourceFile);
1011
return elements;
1112

12-
// If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks.
13+
/** If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks. */
1314
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean, useFullStart: boolean) {
1415
if (hintSpanNode && startElement && endElement) {
1516
const span: OutliningSpan = {
16-
textSpan: createTextSpanFromBounds(useFullStart ? startElement.pos : startElement.getStart(), endElement.end),
17-
hintSpan: createTextSpanFromBounds(startElement.getStart(), endElement.end),
17+
textSpan: createTextSpanFromBounds(useFullStart ? startElement.getFullStart() : startElement.getStart(), endElement.getEnd()),
18+
hintSpan: createTextSpanFromNode(hintSpanNode, sourceFile),
1819
bannerText: collapseText,
1920
autoCollapse,
2021
};
@@ -117,21 +118,21 @@ namespace ts.OutliningElementsCollector {
117118
parent.kind === SyntaxKind.WithStatement ||
118119
parent.kind === SyntaxKind.CatchClause) {
119120

120-
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /* fullStart */ true);
121+
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
121122
break;
122123
}
123124

124125
if (parent.kind === SyntaxKind.TryStatement) {
125126
// Could be the try-block, or the finally-block.
126127
const tryStatement = <TryStatement>parent;
127128
if (tryStatement.tryBlock === n) {
128-
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /* fullStart */ true);
129+
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
129130
break;
130131
}
131132
else if (tryStatement.finallyBlock === n) {
132133
const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile);
133134
if (finallyKeyword) {
134-
addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n), /* fullStart */ true);
135+
addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
135136
break;
136137
}
137138
}
@@ -155,7 +156,7 @@ namespace ts.OutliningElementsCollector {
155156
case SyntaxKind.ModuleBlock: {
156157
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
157158
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
158-
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n), /* fullStart */ true);
159+
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
159160
break;
160161
}
161162
case SyntaxKind.ClassDeclaration:
@@ -164,21 +165,21 @@ namespace ts.OutliningElementsCollector {
164165
case SyntaxKind.CaseBlock: {
165166
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
166167
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
167-
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /* fullStart */ true);
168+
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
168169
break;
169170
}
170-
// If the block has no leading keywords and is a member of an array literal,
171-
// we again want to only collapse the span of the block.
171+
// If the block has no leading keywords and is inside an array literal,
172+
// we only want to collapse the span of the block.
172173
// Otherwise, the collapsed section will include the end of the previous line.
173174
case SyntaxKind.ObjectLiteralExpression:
174175
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
175176
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
176-
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /* fullStart */ n.parent.kind !== SyntaxKind.ArrayLiteralExpression);
177+
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ !isArrayLiteralExpression(n.parent));
177178
break;
178179
case SyntaxKind.ArrayLiteralExpression:
179180
const openBracket = findChildOfKind(n, SyntaxKind.OpenBracketToken, sourceFile);
180181
const closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile);
181-
addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n), /* fullStart */ n.parent.kind !== SyntaxKind.ArrayLiteralExpression);
182+
addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n), /*useFullStart*/ !isArrayLiteralExpression(n.parent));
182183
break;
183184
}
184185
depth++;

0 commit comments

Comments
 (0)