mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge branch 'SaschaNaz-blockFormParameterIndentation'
This commit is contained in:
commit
01f6366c95
@ -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];
|
||||
|
||||
@ -18,4 +18,4 @@ goTo.marker("1");
|
||||
edit.insert("\r\n");
|
||||
goTo.marker("0");
|
||||
// Won't-fixed: Smart indent during chained function calls
|
||||
verify.indentationIs(4);
|
||||
verify.indentationIs(8);
|
||||
@ -13,10 +13,20 @@
|
||||
//// })/*b*/
|
||||
////}
|
||||
|
||||
////Promise
|
||||
//// .then(
|
||||
//// /*n1*/
|
||||
//// )
|
||||
//// /*n2*/
|
||||
//// .then();
|
||||
|
||||
|
||||
goTo.marker('1');
|
||||
edit.insertLine('');
|
||||
goTo.marker('2');
|
||||
verify.currentLineContentIs(' ""');
|
||||
edit.insertLine('');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('4');
|
||||
edit.insertLine('');
|
||||
goTo.marker('3');
|
||||
@ -34,4 +44,9 @@ edit.insert(';');
|
||||
verify.currentLineContentIs(' "";');
|
||||
goTo.marker('b');
|
||||
edit.insert(';');
|
||||
verify.currentLineContentIs(' });');
|
||||
verify.currentLineContentIs(' });');
|
||||
|
||||
goTo.marker('n1');
|
||||
verify.indentationIs(8);
|
||||
goTo.marker('n2');
|
||||
verify.indentationIs(4);
|
||||
Loading…
x
Reference in New Issue
Block a user