Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-LIFE-039

Typing renders the new text after a short pause, without writing files

When the text of a document changes, saved or not, the extension SHALL queue a render of the new text in every preview that shows that document, start it after a pause of 40 ms or of twice the last render time when that is longer (at most 1 s), or at once after a block edit is committed, let a running render finish first unless it has run more than 1 s and more than twice the wall-clock time of the last render when the newer render is due (then abort it), without writing to the shown file or to any build output folder of the workspace; a preview whose panel is hidden SHALL not render until the panel is shown, and previews of the same document, revision and render options SHALL share one render.

Step 1 of path 1 in StRS-MDOKFSTUDIO-LIFE-005: from “A preview shows a document” to “A new render is done”.

Scenarios 8

The situations the tests check; open one to read it.

nominalUnsaved edit
Givena side preview of preview.md and an edit applied to the buffer without saving
Whenthe change event fires
Thenthe preview renders the edited text and shows the new marker
refusalSource gone
Giventhe previewed file no longer exists on disk when the change event fires
Whenthe change is handled
Thenthe preview shows Preview source missing instead of rendering
boundaryCollecting edits for 40 ms
InputOutcome
five changes within 40 mswhen the 40 ms elapse one render starts and the page receives the last text once
a pending edit that the preview cancels before the delay endswhen the delay elapses the builder is never invoked
the last render took 300 msthe next render starts 600 ms after the last change, not 40 ms
the last render took under 10 msthe next render starts 40 ms after the last change
the last render took 3 sthe next render starts 1 s after the last change (the upper bound)
the last render took 300 ms and the writer commits a block edit (the editor closes on an applied edit)the render starts at once, without the 600 ms pause; a running render still finishes first
boundaryEdits during a render
InputOutcome
a render of 500 ms running and two newer edits queuedwhen the running render ends its result is shown and the render of the newest edit starts at once; the older queued edit is superseded
a render whose buffer already changedwhen the render ends its result is still shown, so the preview keeps moving while the writer types, and the newer render follows
the first render (no render time known yet) and a newer editthe first render always finishes
the last render took 600 ms of wall-clock time, the running one has run 1.25 s when the newer edit's pause elapsesthe running render is aborted (its worker thread stops, see SwRS-MDOKFSTUDIO-LIFE-004), the newest edit renders at once, a late result of the aborted render is dropped, and the time the aborted render ran becomes the estimate of the pause and of the overrun limit until a render completes
a small document: the MyST render takes 2 ms, the whole render 60 ms of wall-clock time, and a newer edit's 40 ms pause elapses during itthe running render finishes and the newer edit renders right after; no render is aborted before it has run 1 s
boundaryHidden panels and shared renders
InputOutcome
a preview whose panel is hidden and a change, a refresh or a document switchno render starts; the preview is marked dirty
the dirty panel is shownone render starts, and the mark is cleared
two previews of the same document at the same revision, workspace root, trust state, restricted-reads state and PlantUML engineone render serves both; each receives its own stage with its own request id
a file the render may have read changes, a setting changes, files are renamed or a refresh is requestedthe next request renders again instead of joining a finished render
nominalRendering writes nothing
Givena dirty buffer, or a render that throws, and a hash of the file and of the _build folder
Whenthe preview renders the buffer, switches document, renders edits, or shows the failure
Thenthe file hash and the _build tree hash are unchanged
refusalSave of a buffer the preview already shows
InputOutcome
a ready render of revision 7 and a save of the buffer at revision 7, the file watcher reports the saved fileno render starts (the activePathChanges probe counts the event, the requestId is unchanged)
the buffer is at revision 8 while the page shows revision 7, or the page shows an error, the watcher reports the filea render starts
boundaryThe previewReady message
InputOutcome
a previewReady with the envelope (documentId, revision, requestId) and the optional state fields of a page-state message (line, endLine, sourceLine and selectionLine of at least 1, anchorLine of at least 1, scrollTop of at least 0, previewThemeMode, anchorToEditor, editMode, request) and blockEditOpen as a booleanaccepted as a message (see SwRS-MDOKFSTUDIO-TRUST-052); the host records the reported reading state and the render the page listens for
a previewReady that reports blockEditOpen false, or names another render than the one the host holdsthe host releases an edit lock that waited for a page editor, so the lock cannot block every later edit
blockEditOpen on any type other than previewReady, or an invalid optional fieldnot a message, ignored (see SwRS-MDOKFSTUDIO-TRUST-052)
a previewReady that names an older render than the host holdshandled by the gate of its type (see SwRS-MDOKFSTUDIO-TRUST-065)

Implemented in 8

Tested by 9