From 447361cba7c7e8dcfb1ee6cc39149a1ca8613892 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 18 Nov 2014 20:55:54 -0800 Subject: [PATCH] fix getContainingList to use rangeContainsStartEnd function --- src/services/smartIndenter.ts | 24 +++++++++++------ .../cases/fourslash/formattingNestedScopes.ts | 27 +++++++++++++++++++ .../fourslash/smartIndentInCallExpressions.ts | 12 +++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 tests/cases/fourslash/formattingNestedScopes.ts create mode 100644 tests/cases/fourslash/smartIndentInCallExpressions.ts diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index 7a56ea07be3..e593c6cfd66 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -222,7 +222,8 @@ module ts.formatting { if (node.parent) { switch (node.parent.kind) { case SyntaxKind.TypeReference: - if ((node.parent).typeArguments) { + if ((node.parent).typeArguments && + rangeContainsStartEnd((node.parent).typeArguments, node.getStart(sourceFile), node.getEnd())) { return (node.parent).typeArguments; } break; @@ -236,21 +237,28 @@ module ts.formatting { case SyntaxKind.Method: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: - if ((node.parent).typeParameters && node.end < (node.parent).typeParameters.end) { + var start = node.getStart(sourceFile); + if ((node.parent).typeParameters && + rangeContainsStartEnd((node.parent).typeParameters, start, node.getEnd())) { return (node.parent).typeParameters; } - - return (node.parent).parameters; + if (rangeContainsStartEnd((node.parent).parameters, start, node.getEnd())) { + return (node.parent).parameters; + } + break; case SyntaxKind.NewExpression: case SyntaxKind.CallExpression: - if ((node.parent).typeArguments && node.end < (node.parent).typeArguments.end) { + var start = node.getStart(sourceFile); + if ((node.parent).typeArguments && + rangeContainsStartEnd((node.parent).typeArguments, start, node.getEnd())) { return (node.parent).typeArguments; } - - return (node.parent).arguments; + if (rangeContainsStartEnd((node.parent).arguments, start, node.getEnd())) { + return (node.parent).arguments; + } + break; } } - return undefined; } diff --git a/tests/cases/fourslash/formattingNestedScopes.ts b/tests/cases/fourslash/formattingNestedScopes.ts new file mode 100644 index 00000000000..269a67dcaaf --- /dev/null +++ b/tests/cases/fourslash/formattingNestedScopes.ts @@ -0,0 +1,27 @@ +/// + +/////*1*/ module My.App { +/////*2*/export var appModule = angular.module("app", [ +/////*3*/ ]).config([() => { +/////*4*/ configureStates +/////*5*/($stateProvider); +/////*6*/}]).run(My.App.setup); +/////*7*/ } + + +format.document() + +goTo.marker("1"); +verify.currentLineContentIs("module My.App {"); +goTo.marker("2"); +verify.currentLineContentIs(" export var appModule = angular.module(\"app\", ["); +goTo.marker("3"); +verify.currentLineContentIs(" ]).config([() => {"); +goTo.marker("4"); +verify.currentLineContentIs(" configureStates"); +goTo.marker("5"); +verify.currentLineContentIs(" ($stateProvider);"); +goTo.marker("6"); +verify.currentLineContentIs(" }]).run(My.App.setup);"); +goTo.marker("7"); +verify.currentLineContentIs("}"); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentInCallExpressions.ts b/tests/cases/fourslash/smartIndentInCallExpressions.ts new file mode 100644 index 00000000000..1e28932678b --- /dev/null +++ b/tests/cases/fourslash/smartIndentInCallExpressions.ts @@ -0,0 +1,12 @@ +/// + +////module My.App { +//// export var appModule = angular.module("app", [ +//// ]).config([() => { +//// configureStates/*1*/($stateProvider); +//// }]).run(My.App.setup); +////} + +goTo.marker("1") +edit.insert("\n"); +verify.indentationIs(12); // 4 (module block) + 4 (function block) + 4 (call expression) \ No newline at end of file