mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge branch 'SaschaNaz-blockFormParameterIndentation'
This commit is contained in:
@@ -26,7 +26,7 @@ namespace ts.formatting {
|
||||
precedingToken.kind === SyntaxKind.TemplateHead ||
|
||||
precedingToken.kind === SyntaxKind.TemplateMiddle ||
|
||||
precedingToken.kind === SyntaxKind.TemplateTail;
|
||||
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
|
||||
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ namespace ts.formatting {
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation;
|
||||
}
|
||||
actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation + options.IndentSize;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
current = current.parent;
|
||||
@@ -122,6 +126,10 @@ namespace ts.formatting {
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation + indentationDelta;
|
||||
}
|
||||
actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options);
|
||||
if (actualIndentation !== Value.Unknown) {
|
||||
return actualIndentation + indentationDelta;
|
||||
}
|
||||
}
|
||||
|
||||
// increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line
|
||||
@@ -287,6 +295,55 @@ namespace ts.formatting {
|
||||
}
|
||||
}
|
||||
|
||||
function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
// actual indentation should not be used when:
|
||||
// - node is close parenthesis - this is the end of the expression
|
||||
if (node.kind === SyntaxKind.CloseParenToken) {
|
||||
return Value.Unknown;
|
||||
}
|
||||
|
||||
if (node.parent && (
|
||||
node.parent.kind === SyntaxKind.CallExpression ||
|
||||
node.parent.kind === SyntaxKind.NewExpression) &&
|
||||
(<CallExpression>node.parent).expression !== node) {
|
||||
|
||||
let fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
|
||||
let startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>fullCallOrNewExpression);
|
||||
|
||||
if (fullCallOrNewExpression === startingExpression) {
|
||||
return Value.Unknown;
|
||||
}
|
||||
|
||||
let fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end);
|
||||
let startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end);
|
||||
|
||||
if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) {
|
||||
return Value.Unknown;
|
||||
}
|
||||
|
||||
return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options);
|
||||
}
|
||||
|
||||
return Value.Unknown;
|
||||
|
||||
function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
|
||||
while (true) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
|
||||
node = <PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression>node.expression;
|
||||
break;
|
||||
default:
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
function deriveActualIndentationFromList(list: Node[], index: number, sourceFile: SourceFile, options: EditorOptions): number {
|
||||
Debug.assert(index >= 0 && index < list.length);
|
||||
let node = list[index];
|
||||
|
||||
Reference in New Issue
Block a user