Skip to content

Commit

Permalink
Re #157844. Update for onWillSaveNotebookDocument.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Mar 29, 2023
1 parent 4e05fbb commit b4c3343
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 57 deletions.
1 change: 0 additions & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
NotebookCellStatusBarItem: extHostTypes.NotebookCellStatusBarItem,
NotebookControllerAffinity: extHostTypes.NotebookControllerAffinity,
NotebookControllerAffinity2: extHostTypes.NotebookControllerAffinity2,
NotebookDocumentSaveReason: extHostTypes.NotebookDocumentSaveReason,
NotebookEdit: extHostTypes.NotebookEdit,
NotebookKernelSourceAction: extHostTypes.NotebookKernelSourceAction,
PortAttributes: extHostTypes.PortAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostNotebookDocumentSaveParticipantShape, IWorkspaceEditDto, MainThreadBulkEditsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { NotebookDocumentSaveReason, WorkspaceEdit as WorksapceEditConverter } from 'vs/workbench/api/common/extHostTypeConverters';
import { TextDocumentSaveReason, WorkspaceEdit as WorksapceEditConverter } from 'vs/workbench/api/common/extHostTypeConverters';
import { WorkspaceEdit } from 'vs/workbench/api/common/extHostTypes';
import { SaveReason } from 'vs/workbench/common/editor';
import { NotebookDocumentWillSaveEvent } from 'vscode';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class ExtHostNotebookDocumentSaveParticipant implements ExtHostNotebookDo

const edits: WorkspaceEdit[] = [];

await this._onWillSaveNotebookDocumentEvent.fireAsync({ document: document.apiNotebook, reason: NotebookDocumentSaveReason.to(reason) }, token, async (thenable: Promise<unknown>, listener) => {
await this._onWillSaveNotebookDocumentEvent.fireAsync({ document: document.apiNotebook, reason: TextDocumentSaveReason.to(reason) }, token, async (thenable: Promise<unknown>, listener) => {
const now = Date.now();
const data = await await Promise.resolve(thenable);
if (Date.now() - now > this._thresholds.timeout) {
Expand All @@ -64,15 +64,12 @@ export class ExtHostNotebookDocumentSaveParticipant implements ExtHostNotebookDo
return;
}

if (data && Array.isArray(data)) {
// data can be an array of WorkspaceEdit
for (const edit of data) {
if (edit instanceof WorkspaceEdit) {
edits.push(edit);
} else {
// ignore invalid data
this._logService.warn('onWillSaveNotebookDocument-listener from extension', (<IExtensionListener<NotebookDocumentWillSaveEvent>>listener).extension.identifier, 'ignored due to invalid data');
}
if (data) {
if (data instanceof WorkspaceEdit) {
edits.push(data);
} else {
// ignore invalid data
this._logService.warn('onWillSaveNotebookDocument-listener from extension', (<IExtensionListener<NotebookDocumentWillSaveEvent>>listener).extension.identifier, 'ignored due to invalid data');
}
}

Expand Down
15 changes: 0 additions & 15 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,21 +1528,6 @@ export namespace LanguageSelector {
}
}

export namespace NotebookDocumentSaveReason {

export function to(reason: SaveReason): vscode.NotebookDocumentSaveReason {
switch (reason) {
case SaveReason.AUTO:
return types.NotebookDocumentSaveReason.AfterDelay;
case SaveReason.EXPLICIT:
return types.NotebookDocumentSaveReason.Manual;
case SaveReason.FOCUS_CHANGE:
case SaveReason.WINDOW_CHANGE:
return types.NotebookDocumentSaveReason.FocusOut;
}
}
}

export namespace NotebookRange {

export function from(range: vscode.NotebookRange): ICellRange {
Expand Down
6 changes: 0 additions & 6 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,6 @@ export class TextEdit {
}
}

export enum NotebookDocumentSaveReason {
Manual = 1,
AfterDelay = 2,
FocusOut = 3
}

@es5ClassCompat
export class NotebookEdit implements vscode.NotebookEdit {

Expand Down
26 changes: 2 additions & 24 deletions src/vscode-dts/vscode.proposed.notebookDocumentWillSave.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,6 @@
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {
/**
* Represents reasons why a notebook document is saved.
*/
export enum NotebookDocumentSaveReason {

/**
* Manually triggered, e.g. by the user pressing save, by starting debugging,
* or by an API call.
*/
Manual = 1,

/**
* Automatic after a delay.
*/
AfterDelay = 2,

/**
* When the editor lost focus.
*/
FocusOut = 3
}

/**
* An event that is fired when a {@link NotebookDocument document} will be saved.
*
Expand All @@ -47,9 +25,9 @@ declare module 'vscode' {
/**
* The reason why save was triggered.
*/
readonly reason: NotebookDocumentSaveReason;
readonly reason: TextDocumentSaveReason;

waitUntil(thenable: Thenable<readonly WorkspaceEdit[]>): void;
waitUntil(thenable: Thenable<WorkspaceEdit>): void;

waitUntil(thenable: Thenable<any>): void;
}
Expand Down

0 comments on commit b4c3343

Please sign in to comment.