Skip to content

Commit 0153390

Browse files
Outlining spans for a standalone block shouldn't have the span of their parent.
1 parent a8579af commit 0153390

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Jakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ var servicesSources = [
5858
"shims.ts",
5959
"signatureHelp.ts",
6060
"utilities.ts",
61-
"navigationBar.ts"
61+
"navigationBar.ts",
62+
"outliningElementsCollector.ts"
6263
].map(function (f) {
6364
return path.join(servicesDirectory, f);
6465
}));

src/services/outliningElementsCollector.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ module ts {
3333
export module OutliningElementsCollector {
3434
export function collectElements(sourceFile: SourceFile): OutliningSpan[] {
3535
var elements: OutliningSpan[] = [];
36+
var collapseText = "...";
3637

3738
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) {
3839
if (hintSpanNode && startElement && endElement) {
3940
var span: OutliningSpan = {
4041
textSpan: TypeScript.TextSpan.fromBounds(startElement.pos, endElement.end),
4142
hintSpan: TypeScript.TextSpan.fromBounds(hintSpanNode.getStart(), hintSpanNode.end),
42-
bannerText: "...",
43+
bannerText: collapseText,
4344
autoCollapse: autoCollapse
4445
};
4546
elements.push(span);
@@ -66,10 +67,39 @@ module ts {
6667
}
6768
switch (n.kind) {
6869
case SyntaxKind.Block:
70+
var parent = n.parent;
71+
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
72+
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
73+
74+
// Check if the block is standalone, or 'attached' to some parent statement.
75+
// If the latter, we want to collaps the block, but consider its hint span
76+
// to be the entire span of the parent.
77+
if (parent.kind === SyntaxKind.DoStatement ||
78+
parent.kind === SyntaxKind.ForInStatement ||
79+
parent.kind === SyntaxKind.ForStatement ||
80+
parent.kind === SyntaxKind.IfStatement ||
81+
parent.kind === SyntaxKind.WhileStatement ||
82+
parent.kind === SyntaxKind.WithStatement) {
83+
84+
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
85+
}
86+
else {
87+
// Block was a standalone block. In this case we want to only collapse
88+
// the span of the block, independent of any parent span.
89+
var span = TypeScript.TextSpan.fromBounds(n.getStart(), n.end);
90+
elements.push({
91+
textSpan: span,
92+
hintSpan: span,
93+
bannerText: collapseText,
94+
autoCollapse: autoCollapse(n)
95+
});
96+
}
97+
break;
98+
99+
69100
case SyntaxKind.FunctionBlock:
70101
case SyntaxKind.ModuleBlock:
71102
case SyntaxKind.TryBlock:
72-
case SyntaxKind.TryBlock:
73103
case SyntaxKind.CatchBlock:
74104
case SyntaxKind.FinallyBlock:
75105
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);

0 commit comments

Comments
 (0)