Skip to content

Commit 3b8ad5c

Browse files
committed
Add outlining spans for call expression or arrow body
1 parent 7611579 commit 3b8ad5c

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,31 @@ namespace ts.OutliningElementsCollector {
227227
return spanForTemplateLiteral(<TemplateExpression | NoSubstitutionTemplateLiteral>n);
228228
case SyntaxKind.ArrayBindingPattern:
229229
return spanForNode(n, /*autoCollapse*/ false, /*useFullStart*/ !isBindingElement(n.parent), SyntaxKind.OpenBracketToken);
230+
case SyntaxKind.ArrowFunction:
231+
return spanForArrowFunction(<ArrowFunction>n);
232+
case SyntaxKind.CallExpression:
233+
return spanForCallExpression(<CallExpression>n);
234+
}
235+
236+
function spanForCallExpression(node: CallExpression): OutliningSpan | undefined {
237+
if (!node.arguments.length) {
238+
return undefined;
239+
}
240+
const openToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
241+
const closeToken = findChildOfKind(node, SyntaxKind.CloseParenToken, sourceFile);
242+
if (!openToken || !closeToken || positionsAreOnSameLine(openToken.pos, closeToken.pos, sourceFile)) {
243+
return undefined;
244+
}
245+
246+
return spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ false, /*useFullStart*/ true);
247+
}
248+
249+
function spanForArrowFunction(node: ArrowFunction): OutliningSpan | undefined {
250+
if (isBlock(node.body) || positionsAreOnSameLine(node.body.getFullStart(), node.body.getEnd(), sourceFile)) {
251+
return undefined;
252+
}
253+
const textSpan = createTextSpanFromBounds(node.body.getFullStart(), node.body.getEnd());
254+
return createOutliningSpan(textSpan, OutliningSpanKind.Code, createTextSpanFromNode(node));
230255
}
231256

232257
function spanForJSXElement(node: JsxElement): OutliningSpan | undefined {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// console.log(123, 456)l;
4+
//// console.log(
5+
//// );
6+
//// console.log[|(
7+
//// 123, 456
8+
//// )|];
9+
//// console.log[|(
10+
//// 123,
11+
//// 456
12+
//// )|];
13+
//// () =>[| console.log[|(
14+
//// 123,
15+
//// 456
16+
//// )|]|];
17+
18+
verify.outliningSpansInCurrentFile(test.ranges());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
//// () => 42;
4+
//// () => ( 42 );
5+
//// () =>[| {
6+
//// 42
7+
//// }|];
8+
//// () =>[| (
9+
//// 42
10+
//// )|];
11+
//// () =>[| "foo" +
12+
//// "bar" +
13+
//// "baz"|];
14+
15+
verify.outliningSpansInCurrentFile(test.ranges());

0 commit comments

Comments
 (0)