From 593fb327dccef8d864a57d31a6c662a0cd59ecbf Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 29 Oct 2014 12:25:57 -0700 Subject: [PATCH] indentation for export assignments --- src/services/formatting/format.ts | 49 +++++++++++++++--------- src/services/formatting/smartIndenter.ts | 1 + 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/services/formatting/format.ts b/src/services/formatting/format.ts index cec141bd875..d13c6ff62b9 100644 --- a/src/services/formatting/format.ts +++ b/src/services/formatting/format.ts @@ -285,29 +285,40 @@ module ts.formatting { var isChildInRange = rangeOverlapsWithStartEnd(originalRange, start, child.getEnd()); var childIndentationValue: number; - if (containingList && !isChildInRange) { - // child is a list item that is not in span being formatted - // fetch actual indentation for the child item to push it downstream - // TODO: ensure that indentation is picked correctly - var actualIndentation = getListItemIndentation(containingList, listElementIndex, nodeStartLine, options); - if (actualIndentation !== -1) { - inheritedIndentation = actualIndentation; - } - var childIndentationValue = increaseIndentation || indentation; - } - else { - if (inheritedIndentation !== undefined) { - var childIndentationValue = inheritedIndentation; + if (containingList) { + if (isChildInRange) { + if (inheritedIndentation !== undefined) { + // use indentation inherited from preceding list items + childIndentationValue = inheritedIndentation; + } + else { + var increaseIndentation = + node.kind !== SyntaxKind.SourceFile && + node.pos !== child.pos && + formattingScanner.lastTrailingTriviaWasNewLine(); + + var childIndentationValue = increaseIndentation ? indentation + options.IndentSize : indentation; + } } else { - var shareLine = nodeStartLine === childStart.line; - var increaseIndentation = - !shareLine && - !SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(node, child, childStart.line, sourceFile) && - SmartIndenter.shouldIndentChildNode(node, child); - var childIndentationValue = increaseIndentation ? indentation + options.IndentSize : indentation; + // child is a list item that is not in span being formatted + // fetch actual indentation for the child item to push it downstream + // TODO: ensure that indentation is picked correctly + var actualIndentation = getListItemIndentation(containingList, listElementIndex, nodeStartLine, options); + if (actualIndentation !== -1) { + inheritedIndentation = actualIndentation; + } + var childIndentationValue = inheritedIndentation || indentation; } } + else { + var shareLine = nodeStartLine === childStart.line; + var increaseIndentation = + !shareLine && + !SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(node, child, childStart.line, sourceFile) && + SmartIndenter.shouldIndentChildNode(node, child); + var childIndentationValue = increaseIndentation ? indentation + options.IndentSize : indentation; + } var childIndentation: DynamicIndentation = { getIndentation: () => childIndentationValue, diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index f50c8faaa09..b83230047e8 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -318,6 +318,7 @@ module ts.formatting { case SyntaxKind.NewExpression: case SyntaxKind.VariableStatement: case SyntaxKind.VariableDeclaration: + case SyntaxKind.ExportAssignment: return true; default: return false;