src/vs/editor/common/model/pieceTreeTextBuffer/rbTreeBase.ts/recomputeTreeMetadata
export function recomputeTreeMetadata(tree: PieceTreeBase, x: TreeNode) {
	let delta = 0;
	let lf_delta = 0;
	if (x === tree.root) {
		return;
	}

	// go upwards till the node whose left subtree is changed.
	while (x !== tree.root && x === x.parent.right) {
		x = x.parent;
	}

	if (x === tree.root) {
		// well, it means we add a node to the end (inorder)
		return;
	}

	// x is the node whose right subtree is changed.
	x = x.parent;

	delta = calculateSize(x.left) - x.size_left;
	lf_delta = calculateLF(x.left) - x.lf_left;
	x.size_left += delta;
	x.lf_left += lf_delta;


	// go upwards till root. O(logN)
	while (x !== tree.root && (delta !== 0 || lf_delta !== 0)) {
		if (x.parent.left === x) {
			x.parent.size_left += delta;
			x.parent.lf_left += lf_delta;
		}

		x = x.parent;
	}
}