Prepares the TextDocument. This method may be called by the background thread writing to the output. Once the document is prepared, it can no longer be written to.
Calling this method on the background thread ensures the TextDocument's line tokenization runs in the background and does not block the GUI.