src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/concat23Trees.ts/prepend
function prepend(list: ListAstNode, nodeToAppend: AstNode): AstNode {
	list = list.toMutable() as ListAstNode;
	let curNode: AstNode = list;
	const parents: ListAstNode[] = [];
	// assert nodeToInsert.listHeight <= curNode.listHeight
	while (nodeToAppend.listHeight !== curNode.listHeight) {
		// assert 0 <= nodeToInsert.listHeight < curNode.listHeight
		if (curNode.kind !== AstNodeKind.List) {
			throw new Error('unexpected');
		}
		parents.push(curNode);
		// assert 2 <= curNode.childrenFast.length <= 3
		curNode = curNode.makeFirstElementMutable()!;
	}
	let nodeToPrependOfCorrectHeight: AstNode | undefined = nodeToAppend;
	// assert nodeToAppendOfCorrectHeight!.listHeight === curNode.listHeight
	for (let i = parents.length - 1; i >= 0; i--) {
		const parent = parents[i];
		if (nodeToPrependOfCorrectHeight) {
			// Can we take the element?
			if (parent.childrenLength >= 3) {
				// assert parent.childrenLength === 3 && parent.listHeight === nodeToAppendOfCorrectHeight.listHeight + 1

				// we need to split to maintain (2,3)-tree property.
				// Send the third element + the new element to the parent.
				nodeToPrependOfCorrectHeight = ListAstNode.create23(nodeToPrependOfCorrectHeight, parent.unprependChild()!, null, false);
			} else {
				parent.prependChildOfSameHeight(nodeToPrependOfCorrectHeight);
				nodeToPrependOfCorrectHeight = undefined;
			}
		} else {
			parent.handleChildrenChanged();
		}
	}
	if (nodeToPrependOfCorrectHeight) {
		return ListAstNode.create23(nodeToPrependOfCorrectHeight, list, null, false);
	} else {
		return list;
	}
}