Skip to content

Commit 0660fb0

Browse files
authored
vscode: stub onWillSaveNotebookDocument (eclipse-theia#12614)
Contributed on behalf of STMicroelectronics Signed-off-by: Remi Schnekenburger <[email protected]>
1 parent 6d8affb commit 0660fb0

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

packages/plugin-ext/src/plugin/plugin-context.ts

+3
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ export function createAPIFactory(
633633
onDidChangeNotebookDocument(listener, thisArg?, disposables?) {
634634
return Disposable.NULL;
635635
},
636+
onWillSaveNotebookDocument(listener, thisArg?, disposables?) {
637+
return Disposable.NULL;
638+
},
636639
onDidSaveNotebookDocument(listener, thisArg?, disposables?) {
637640
return Disposable.NULL;
638641
},

packages/plugin/src/theia.d.ts

+76
Original file line numberDiff line numberDiff line change
@@ -7167,6 +7167,22 @@ export module '@theia/plugin' {
71677167
*/
71687168
export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>;
71697169

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+
71707186
/**
71717187
* An event that is emitted when files are being created.
71727188
*
@@ -14714,6 +14730,66 @@ export module '@theia/plugin' {
1471414730
readonly cellChanges: readonly NotebookDocumentCellChange[];
1471514731
}
1471614732

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+
1471714793
/**
1471814794
* The summary of a notebook cell execution.
1471914795
*/

0 commit comments

Comments
 (0)