From ad362089bea798b2ebc204d23b8534367e1d5e5c Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 16 Dec 2020 16:15:32 +0100 Subject: [PATCH] add proposal of CancellationError, https://github.com/microsoft/vscode/issues/93686 --- src/vs/base/common/errors.ts | 9 +++++++++ src/vs/vscode.proposed.d.ts | 19 +++++++++++++++++++ .../workbench/api/common/extHost.api.impl.ts | 3 +++ 3 files changed, 31 insertions(+) diff --git a/src/vs/base/common/errors.ts b/src/vs/base/common/errors.ts index f6d4f5cf893..8c8e874e853 100644 --- a/src/vs/base/common/errors.ts +++ b/src/vs/base/common/errors.ts @@ -142,6 +142,15 @@ export function isPromiseCanceledError(error: any): boolean { return error instanceof Error && error.name === canceledName && error.message === canceledName; } +// !!!IMPORTANT!!! +// Do NOT change this class because it is also used as an API-type. +export class CancellationError extends Error { + constructor() { + super(canceledName); + this.name = this.message; + } +} + /** * Returns an error that signals cancellation. */ diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index f40d195d03b..71ebc8f4990 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -18,6 +18,25 @@ import { Command } from 'vscode'; declare module 'vscode' { + //#region https://github.com/microsoft/vscode/issues/93686 + + /** + * An error type should be used to signal cancellation of an operation. + * + * This type can be used in response to a cancellation token or when an + * operation is being cancelled by the executor of that operation. + */ + export class CancellationError extends Error { + + /** + * Creates a new cancellation error. + */ + constructor(); + } + + + //#endregion + // #region auth provider: https://github.com/microsoft/vscode/issues/88309 /** diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 00564b6db78..6d6bdd4bd2d 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1212,6 +1212,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I ViewColumn: extHostTypes.ViewColumn, WorkspaceEdit: extHostTypes.WorkspaceEdit, // proposed api types + get CancellationError() { + return errors.CancellationError; + }, get RemoteAuthorityResolverError() { // checkProposedApiEnabled(extension); return extHostTypes.RemoteAuthorityResolverError;