Editor

class Editor(val file: KtFile)

One editing context — a connection, a pane, whatever owns a caret.

Its file is created once and rewritten per query, never replaced. A new file means a new dangling file module, and every module analyze touches outlives close (see there). So a file per keystroke retains a PSI tree per keystroke; one file per editor retains one, for as long as the editor lives — which is why an editor is worth holding onto rather than making one per request.

Constructors

Link copied to clipboard
internal constructor(file: KtFile)

Properties

Link copied to clipboard
private val file: KtFile

Functions

Link copied to clipboard
fun close()

Hands this editor's module back. An editor is finished with after this.

Link copied to clipboard

code with a caret at offset, ready to analyze. A placeholder identifier is spliced in at the caret first, because completion runs on source that does not parse: foo. has no selector, so the parser yields no dotted expression and the receiver cannot be reached. IntelliJ splices one in for the same reason, and reusing its name means anything that special-cases it still behaves.

Link copied to clipboard
private fun release(file: KtFile)

Gives file's module back to the analysis caches. Only that module goes — a module-level removal evicts the module's own session and any dangling session contextual to it, and leaves library sessions, and with them the classpath index, alone.

Link copied to clipboard
private fun rewrite(text: String)

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