rewrite

private fun rewrite(file: KtFile, text: String)

Swaps file's whole tree for SnippetParser.parsePsi's parse of text. The file object survives, so its module — and with it the analysis cache key — stays the one it already had. The modification stamp moves, which is what tells the session on that key to be rebuilt instead of reused stale.

The parse is moved into a throwaway file first: the swap asks the tree it takes children from for its PSI, and the parser's own root has none. The throwaway is never analyzed, so it never becomes a module of its own.