@@ -7167,6 +7167,22 @@ export module '@theia/plugin' {
7167
7167
*/
7168
7168
export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>;
7169
7169
7170
+ /**
7171
+ * An event that is emitted when a {@link NotebookDocument notebook document} will be saved to disk.
7172
+ *
7173
+ * *Note 1:* Subscribers can delay saving by registering asynchronous work. For the sake of data integrity the editor
7174
+ * might save without firing this event. For instance when shutting down with dirty files.
7175
+ *
7176
+ * *Note 2:* Subscribers are called sequentially and they can {@link NotebookDocumentWillSaveEvent.waitUntil delay} saving
7177
+ * by registering asynchronous work. Protection against misbehaving listeners is implemented as such:
7178
+ * * there is an overall time budget that all listeners share and if that is exhausted no further listener is called
7179
+ * * listeners that take a long time or produce errors frequently will not be called anymore
7180
+ *
7181
+ * The current thresholds are 1.5 seconds as overall time budget and a listener can misbehave 3 times before being ignored.
7182
+ * @stubbed
7183
+ */
7184
+ export const onWillSaveNotebookDocument: Event<NotebookDocumentWillSaveEvent>;
7185
+
7170
7186
/**
7171
7187
* An event that is emitted when files are being created.
7172
7188
*
@@ -14714,6 +14730,66 @@ export module '@theia/plugin' {
14714
14730
readonly cellChanges: readonly NotebookDocumentCellChange[];
14715
14731
}
14716
14732
14733
+ /**
14734
+ * An event that is fired when a {@link NotebookDocument notebook document} will be saved.
14735
+ *
14736
+ * To make modifications to the document before it is being saved, call the
14737
+ * {@linkcode NotebookDocumentWillSaveEvent.waitUntil waitUntil}-function with a thenable
14738
+ * that resolves to a {@link WorkspaceEdit workspace edit}.
14739
+ */
14740
+ export interface NotebookDocumentWillSaveEvent {
14741
+ /**
14742
+ * A cancellation token.
14743
+ * @stubbed
14744
+ */
14745
+ readonly token: CancellationToken;
14746
+
14747
+ /**
14748
+ * The {@link NotebookDocument notebook document} that will be saved.
14749
+ * @stubbed
14750
+ */
14751
+ readonly notebook: NotebookDocument;
14752
+
14753
+ /**
14754
+ * The reason why save was triggered.
14755
+ * @stubbed
14756
+ */
14757
+ readonly reason: TextDocumentSaveReason;
14758
+
14759
+ /**
14760
+ * Allows to pause the event loop and to apply {@link WorkspaceEdit workspace edit}.
14761
+ * Edits of subsequent calls to this function will be applied in order. The
14762
+ * edits will be *ignored* if concurrent modifications of the notebook document happened.
14763
+ *
14764
+ * *Note:* This function can only be called during event dispatch and not
14765
+ * in an asynchronous manner:
14766
+ *
14767
+ * ```ts
14768
+ * workspace.onWillSaveNotebookDocument(event => {
14769
+ * // async, will *throw* an error
14770
+ * setTimeout(() => event.waitUntil(promise));
14771
+ *
14772
+ * // sync, OK
14773
+ * event.waitUntil(promise);
14774
+ * })
14775
+ * ```
14776
+ *
14777
+ * @param thenable A thenable that resolves to {@link WorkspaceEdit workspace edit}.
14778
+ * @stubbed
14779
+ */
14780
+ waitUntil(thenable: Thenable<WorkspaceEdit>): void;
14781
+
14782
+ /**
14783
+ * Allows to pause the event loop until the provided thenable resolved.
14784
+ *
14785
+ * *Note:* This function can only be called during event dispatch.
14786
+ *
14787
+ * @param thenable A thenable that delays saving.
14788
+ * @stubbed
14789
+ */
14790
+ waitUntil(thenable: Thenable<any>): void;
14791
+ }
14792
+
14717
14793
/**
14718
14794
* The summary of a notebook cell execution.
14719
14795
*/
0 commit comments