8000 fix getContainingList to use rangeContainsStartEnd function · rbuckton/TypeScript@447361c · GitHub
[go: up one dir, main page]

Skip to content

Commit 447361c

Browse files
committed
fix getContainingList to use rangeContainsStartEnd function
1 parent a9cf216 commit 447361c

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

src/services/smartIndenter.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ module ts.formatting {
222222
if (node.parent) {
223223
switch (node.parent.kind) {
224224
case SyntaxKind.TypeReference:
225-
if ((<TypeReferenceNode>node.parent).typeArguments) {
225+
if ((<TypeReferenceNode>node.parent).typeArguments &&
226+
rangeContainsStartEnd((<TypeReferenceNode>node.parent).typeArguments, node.getStart(sourceFile), node.getEnd())) {
226227
return (<TypeReferenceNode>node.parent).typeArguments;
227228
}
228229
break;
@@ -236,21 +237,28 @@ module ts.formatting {
236237
case SyntaxKind.Method:
237238
case SyntaxKind.CallSignature:
238239
case SyntaxKind.ConstructSignature:
239-
if ((<SignatureDeclaration>node.parent).typeParameters && node.end < (<SignatureDeclaration>node.parent).typeParameters.end) {
240+
var start = node.getStart(sourceFile);
241+
if ((<SignatureDeclaration>node.parent).typeParameters &&
242+
rangeContainsStartEnd((<SignatureDeclaration>node.parent).typeParameters, start, node.getEnd())) {
240243
return (<SignatureDeclaration>node.parent).typeParameters;
241244
}
242-
243-
return (<SignatureDeclaration>node.parent).parameters;
245+
if (rangeContainsStartEnd((<SignatureDeclaration>node.parent).parameters, start, node.getEnd())) {
246+
return (<SignatureDeclaration>node.parent).parameters;
247+
}
248+
break;
244249
case SyntaxKind.NewExpression:
245250
case SyntaxKind.CallExpression:
246-
if ((<CallExpression>node.parent).typeArguments && node.end < (<CallExpression>node.parent).typeArguments.end) {
251+
var start = node.getStart(sourceFile);
252+
if ((<CallExpression>node.parent).typeArguments &&
253+
rangeContainsStartEnd((<CallExpression>node.parent).typeArguments, start, node.getEnd())) {
247254
return (<CallExpression>node.parent).typeArguments;
248255 }
249-
250-
return (<CallExpression>node.parent).arguments;
256+
if (rangeContainsStartEnd((<CallExpression>node.parent).arguments, start, node.getEnd())) {
257+
return (<CallExpression>node.parent).arguments;
258+
}
259+
break;
251260
}
252261
}
253-
254262
return undefined;
255263
}
256264

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
/////*1*/ module My.App {
4+
/////*2*/export var appModule = angular.module("app", [
5+
/////*3*/ ]).config([() => {
6+
/////*4*/ configureStates
7+
/////*5*/($stateProvider);
8+
/////*6*/}]).run(My.App.setup);
9+
/////*7*/ }
10+
11+
12+
format.document()
13+
14+
goTo.marker("1");
15+
verify.currentLineContentIs("module My.App {");
16+
goTo.marker("2");
17+
verify.currentLineContentIs(" export var appModule = angular.module(\"app\", [");
18+
goTo.marker("3");
19+
verify.currentLineContentIs(" ]).config([() => {");
20+
goTo.marker("4");
21+
verify.currentLineContentIs(" configureStates");
22+
goTo.marker("5");
23+
verify.currentLineContentIs(" ($stateProvider);");
24+
goTo.marker("6");
25+
verify.currentLineContentIs(" }]).run(My.App.setup);");
26+
goTo.marker("7");
27+
verify.currentLineContentIs("}");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////module My.App {
4+
//// export var appModule = angular.module("app", [
5+
//// ]).config([() => {
6+
//// configureStates/*1*/($stateProvider);
7+
//// }]).run(My.App.setup);
8+
////}
9+
10+
goTo.marker("1")
11+
edit.insert("\n");
12+
verify.indentationIs(12); // 4 (module block) + 4 (function block) + 4 (call expression)

0 commit comments

Comments
 (0)
0