Skip to content

Commit

Permalink
allow to race against cancellation when invoking _withAdapter, neve…
Browse files Browse the repository at this point in the history
…r log cancellation errors, #140557
  • Loading branch information
jrieken committed Jan 12, 2022
1 parent 603274e commit e5703c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as typeh from 'vs/workbench/contrib/typeHierarchy/common/typeHierarchy'
import { mixin } from 'vs/base/common/objects';
import { decodeSemanticTokensDto } from 'vs/editor/common/services/semanticTokensDto';
import { revive } from 'vs/base/common/marshalling';
import { canceled } from 'vs/base/common/errors';
import { CancellationError } from 'vs/base/common/errors';

@extHostNamedCustomer(MainContext.MainThreadLanguageFeatures)
export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesShape {
Expand Down Expand Up @@ -451,7 +451,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha

// --- suggest

private static _inflateSuggestDto(defaultRange: IRange | { insert: IRange, replace: IRange }, data: ISuggestDataDto): modes.CompletionItem {
private static _inflateSuggestDto(defaultRange: IRange | { insert: IRange, replace: IRange; }, data: ISuggestDataDto): modes.CompletionItem {

const label = data[ISuggestDataDtoField.label];

Expand Down Expand Up @@ -576,7 +576,7 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
}
const result = await this._proxy.$resolveInlayHint(handle, dto.cacheId, token);
if (token.isCancellationRequested) {
throw canceled();
throw new CancellationError();
}
if (!result) {
return hint;
Expand Down
26 changes: 13 additions & 13 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ 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';
import { isCancellationError } from 'vs/base/common/errors';
import { Emitter } from 'vs/base/common/event';
import { raceCancellationError } from 'vs/base/common/async';

// --- adapter

Expand Down Expand Up @@ -1218,9 +1219,6 @@ class InlayHintsAdapter {
if (!hint) {
return undefined;
}
if (token.isCancellationRequested) {
return undefined;
}
if (!this._isValidInlayHint(hint)) {
return undefined;
}
Expand Down Expand Up @@ -1668,7 +1666,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
ctor: { new(...args: any[]): A; },
callback: (adapter: A, extension: IExtensionDescription) => Promise<R>,
fallbackValue: R,
allowCancellationError: boolean = false
tokenToRaceAgainst?: CancellationToken
): Promise<R> {
const data = this._adapter.get(handle);
if (!data || !(data.adapter instanceof ctor)) {
Expand All @@ -1682,15 +1680,17 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF

// logging,tracing
Promise.resolve(result).catch(err => {
const isExpectedError = allowCancellationError && (err instanceof CancellationError);
if (!isExpectedError) {
if (!isCancellationError(err)) {
this._logService.error(`[${data.extension.identifier.value}] provider FAILED`);
this._logService.error(err);
}
}).finally(() => {
this._logService.trace(`[${data.extension.identifier.value}] provider DONE after ${Date.now() - t1}ms`);
});

if (CancellationToken.isCancellationToken(tokenToRaceAgainst)) {
return raceCancellationError(result, tokenToRaceAgainst);
}
return result;
}

Expand Down Expand Up @@ -1993,7 +1993,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, true);
return this._withAdapter(handle, DocumentSemanticTokensAdapter, adapter => adapter.provideDocumentSemanticTokens(URI.revive(resource), previousResultId, token), null);
}

$releaseDocumentSemanticTokens(handle: number, semanticColoringResultId: number): void {
Expand All @@ -2007,7 +2007,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, true);
return this._withAdapter(handle, DocumentRangeSemanticTokensAdapter, adapter => adapter.provideDocumentRangeSemanticTokens(URI.revive(resource), range, token), null);
}

//#endregion
Expand All @@ -2021,11 +2021,11 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
}

$provideCompletionItems(handle: number, resource: UriComponents, position: IPosition, context: modes.CompletionContext, token: CancellationToken): Promise<extHostProtocol.ISuggestResultDto | undefined> {
return this._withAdapter(handle, SuggestAdapter, adapter => adapter.provideCompletionItems(URI.revive(resource), position, context, token), undefined);
return this._withAdapter(handle, SuggestAdapter, adapter => adapter.provideCompletionItems(URI.revive(resource), position, context, token), undefined, token);
}

$resolveCompletionItem(handle: number, id: extHostProtocol.ChainedCacheId, token: CancellationToken): Promise<extHostProtocol.ISuggestDataDto | undefined> {
return this._withAdapter(handle, SuggestAdapter, adapter => adapter.resolveCompletionItem(id, token), undefined);
return this._withAdapter(handle, SuggestAdapter, adapter => adapter.resolveCompletionItem(id, token), undefined, token);
}

$releaseCompletionItems(handle: number, id: number): void {
Expand Down Expand Up @@ -2092,11 +2092,11 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
}

$provideInlayHints(handle: number, resource: UriComponents, range: IRange, token: CancellationToken): Promise<extHostProtocol.IInlayHintsDto | undefined> {
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.provideInlayHints(URI.revive(resource), range, token), undefined);
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.provideInlayHints(URI.revive(resource), range, token), undefined, token);
}

$resolveInlayHint(handle: number, id: extHostProtocol.ChainedCacheId, token: CancellationToken): Promise<extHostProtocol.IInlayHintDto | undefined> {
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.resolveInlayHint(id, token), undefined);
return this._withAdapter(handle, InlayHintsAdapter, adapter => adapter.resolveInlayHint(id, token), undefined, token);
}

$releaseInlayHints(handle: number, id: number): void {
Expand Down

0 comments on commit e5703c8

Please sign in to comment.