indent using list start position before first list item

This commit is contained in:
Kagami Sascha Rosylight 2017-05-30 03:16:10 +09:00
parent cd19a8910d
commit 655bf203d0

View File

@ -66,6 +66,12 @@ namespace ts.formatting {
}
}
const containerList = getListByPosition(position, precedingToken.parent);
// use list position if the preceding token is before any list items
if (containerList && !rangeContainsRange(containerList, precedingToken)) {
return getActualIndentationForListStartLine(containerList, sourceFile, options) + options.indentSize;
}
return getSmartIndent(sourceFile, position, precedingToken, lineAtPosition, assumeNewLineBeforeCloseBrace, options);
}
@ -394,6 +400,13 @@ namespace ts.formatting {
}
}
function getActualIndentationForListStartLine(list: NodeArray<Node>, sourceFile: SourceFile, options: EditorSettings): number {
if (!list) {
return Value.Unknown;
}
return findColumnForFirstNonWhitespaceCharacterInLine(sourceFile.getLineAndCharacterOfPosition(list.pos), sourceFile, options);
}
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorSettings): number {
const containingList = getContainingList(node, sourceFile);
if (containingList) {