Skip to content

Commit

Permalink
Adopt proposed CancellationError (#93686)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jan 11, 2021
1 parent 5c1543b commit 3d500eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro
// as the new request will come in right after our response, we first wait for the document activity to stop
await waitForDocumentChangesToEnd(document);

throw new Error('busy');
throw new vscode.CancellationError();
}

const tokenSpan = response.body.spans;
Expand Down
3 changes: 2 additions & 1 deletion src/vs/editor/common/services/modelServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ class ModelSemanticColoring extends Disposable {
contentChangeListener.dispose();
this._setDocumentSemanticTokens(provider, res || null, styling, pendingChanges);
}, (err) => {
if (!err || typeof err.message !== 'string' || err.message.indexOf('busy') === -1) {
const isExpectedError = err && (errors.isPromiseCanceledError(err) || (typeof err.message === 'string' && err.message.indexOf('busy') !== -1));
if (!isExpectedError) {
errors.onUnexpectedError(err);
}

Expand Down
14 changes: 9 additions & 5 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IdGenerator } from 'vs/base/common/idGenerator';
import { IExtHostApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
import { Cache } from './cache';
import { StopWatch } from 'vs/base/common/stopwatch';
import { CancellationError } from 'vs/base/common/errors';

// --- adapter

Expand Down Expand Up @@ -1403,7 +1404,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
return ExtHostLanguageFeatures._handlePool++;
}

private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A; }, callback: (adapter: A, extension: IExtensionDescription | undefined) => Promise<R>, fallbackValue: R): Promise<R> {
private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A; }, callback: (adapter: A, extension: IExtensionDescription | undefined) => Promise<R>, fallbackValue: R, allowCancellationError: boolean = false): Promise<R> {
const data = this._adapter.get(handle);
if (!data) {
return Promise.resolve(fallbackValue);
Expand All @@ -1421,8 +1422,11 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
Promise.resolve(p).then(
() => this._logService.trace(`[${extension.identifier.value}] provider DONE after ${Date.now() - t1}ms`),
err => {
this._logService.error(`[${extension.identifier.value}] provider FAILED`);
this._logService.error(err);
const isExpectedError = allowCancellationError && (err instanceof CancellationError);
if (!isExpectedError) {
this._logService.error(`[${extension.identifier.value}] provider FAILED`);
this._logService.error(err);
}
}
);
}
Expand Down Expand Up @@ -1711,7 +1715,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
}

$provideDocumentSemanticTokens(handle: number, resource: UriComponents, previousResultId: number, token: CancellationToken): Promise<VSBuffer | null> {
return this._withAdapter(handle, DocumentSemanticTokensAdapter, adapter => adapter.provideDocumentSemanticTokens(URI.revive(resource), previousResultId, token), null);
return this._withAdapter(handle, DocumentSemanticTokensAdapter, adapter => adapter.provideDocumentSemanticTokens(URI.revive(resource), previousResultId, token), null, true);
}

$releaseDocumentSemanticTokens(handle: number, semanticColoringResultId: number): void {
Expand All @@ -1725,7 +1729,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
}

$provideDocumentRangeSemanticTokens(handle: number, resource: UriComponents, range: IRange, token: CancellationToken): Promise<VSBuffer | null> {
return this._withAdapter(handle, DocumentRangeSemanticTokensAdapter, adapter => adapter.provideDocumentRangeSemanticTokens(URI.revive(resource), range, token), null);
return this._withAdapter(handle, DocumentRangeSemanticTokensAdapter, adapter => adapter.provideDocumentRangeSemanticTokens(URI.revive(resource), range, token), null, true);
}

//#endregion
Expand Down

0 comments on commit 3d500eb

Please sign in to comment.