From 27cb5b0c18ac5ace82b35f5f9a00ec04a7bbf705 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 14 Oct 2014 18:39:51 -0700 Subject: [PATCH] temporary disable smart indentation for type literals, fix computation for end line position --- src/services/formatting/format.ts | 14 ++++++++------ src/services/formatting/smartIndenter.ts | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/services/formatting/format.ts b/src/services/formatting/format.ts index cd8167bb85b..c237cad5510 100644 --- a/src/services/formatting/format.ts +++ b/src/services/formatting/format.ts @@ -58,8 +58,8 @@ module ts.formatting { function getEndLinePosition(line: number, sourceFile: SourceFile): number { var lineStarts = sourceFile.getLineStarts(); if (line === lineStarts.length - 1) { - // last line - return EOF - - return sourceFile.text.length - lineStarts[line]; + // last line - return EOF + return sourceFile.text.length - 1; } else { // current line start @@ -351,7 +351,9 @@ module ts.formatting { processTrivia(currentTokenInfo.leadingTrivia, parent, contextNode, indentation); } - processRange(currentTokenInfo.token, parent, contextNode, indentation); + if (rangeContainsRange(originalRange, currentTokenInfo.token)) { + processRange(currentTokenInfo.token, parent, contextNode, indentation); + } if (currentTokenInfo.trailingTrivia) { processTrivia(currentTokenInfo.trailingTrivia, parent, contextNode, indentation); @@ -363,7 +365,7 @@ module ts.formatting { function processTrivia(trivia: TextRangeWithKind[], parent: Node, contextNode: Node, currentIndentation: number): void { for (var i = 0, len = trivia.length; i < len; ++i) { var triviaItem = trivia[i]; - if (isComment(triviaItem.kind)) { + if (isComment(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) { processRange(triviaItem, parent, contextNode, currentIndentation); } } @@ -371,8 +373,8 @@ module ts.formatting { function processRange(range: TextRangeWithKind, parent: Node, contextNode: Node, indentation: number) { var rangeStart = getNonAdjustedLineAndCharacterFromPosition(range.pos, sourceFile); - if (rangeContainsRange(originalRange, range)) { - var indentToken = false; + if (rangeContainsRange(originalRange, range)) { + var indentToken = true; if (!previousRange) { var originalStart = getNonAdjustedLineAndCharacterFromPosition(originalRange.pos, sourceFile); // TODO: implement diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index d7dc3f422fe..8fa1fc1928e 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -229,8 +229,8 @@ module ts.formatting { break; case SyntaxKind.ObjectLiteral: return getActualIndentationFromList((node.parent).properties); - case SyntaxKind.TypeLiteral: - return getActualIndentationFromList((node.parent).members); + //case SyntaxKind.TypeLiteral: + // return getActualIndentationFromList((node.parent).members); case SyntaxKind.ArrayLiteral: return getActualIndentationFromList((node.parent).elements); case SyntaxKind.FunctionDeclaration: