mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Handle Promise errors caused by cancellation (#2420)
- Port of 34ca4c78b2
- This fixes issues where opening an editor send unhandled errors to the debug console, making it hard to debug issues.
This commit is contained in:
@@ -27,6 +27,7 @@ import { CodeActionAutoApply, CodeActionFilter, CodeActionKind } from './codeAct
|
||||
import { CodeActionContextMenu } from './codeActionWidget';
|
||||
import { LightBulbWidget } from './lightBulbWidget';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
function contextKeyForSupportedActions(kind: CodeActionKind) {
|
||||
return ContextKeyExpr.regex(
|
||||
@@ -98,7 +99,7 @@ export class QuickFixController implements IEditorContribution {
|
||||
} else {
|
||||
this._codeActionContextMenu.show(e.actions, e.position);
|
||||
}
|
||||
});
|
||||
}).catch(onUnexpectedError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import { getColors, IColorData } from 'vs/editor/contrib/colorPicker/color';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
|
||||
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
const MAX_DECORATORS = 500;
|
||||
|
||||
@@ -28,7 +29,7 @@ export class ColorDetector implements IEditorContribution {
|
||||
|
||||
private _globalToDispose: IDisposable[] = [];
|
||||
private _localToDispose: IDisposable[] = [];
|
||||
private _computePromise: CancelablePromise<void>;
|
||||
private _computePromise: CancelablePromise<IColorData[]>;
|
||||
private _timeoutTimer: TimeoutTimer;
|
||||
|
||||
private _decorationsIds: string[] = [];
|
||||
@@ -127,13 +128,12 @@ export class ColorDetector implements IEditorContribution {
|
||||
}
|
||||
|
||||
private beginCompute(): void {
|
||||
this._computePromise = createCancelablePromise(token => {
|
||||
return getColors(this._editor.getModel(), token).then(colorInfos => {
|
||||
this.updateDecorations(colorInfos);
|
||||
this.updateColorDecorators(colorInfos);
|
||||
this._computePromise = null;
|
||||
});
|
||||
});
|
||||
this._computePromise = createCancelablePromise(token => getColors(this._editor.getModel(), token));
|
||||
this._computePromise.then((colorInfos) => {
|
||||
this.updateDecorations(colorInfos);
|
||||
this.updateColorDecorators(colorInfos);
|
||||
this._computePromise = null;
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
|
||||
private stop(): void {
|
||||
|
||||
@@ -33,6 +33,7 @@ import { SyntaxRangeProvider, ID_SYNTAX_PROVIDER } from './syntaxRangeProvider';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { InitializingRangeProvider, ID_INIT_PROVIDER } from 'vs/editor/contrib/folding/intializingRangeProvider';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
export const ID = 'editor.contrib.folding';
|
||||
|
||||
@@ -166,7 +167,7 @@ export class FoldingController implements IEditorContribution {
|
||||
if (foldingModel) {
|
||||
foldingModel.applyMemento(state.collapsedRegions);
|
||||
}
|
||||
});
|
||||
}).done(undefined, onUnexpectedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +313,7 @@ export class FoldingController implements IEditorContribution {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}).done(undefined, onUnexpectedError);
|
||||
|
||||
}
|
||||
|
||||
@@ -404,7 +405,7 @@ export class FoldingController implements IEditorContribution {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}).done(undefined, onUnexpectedError);
|
||||
}
|
||||
|
||||
public reveal(position: IPosition): void {
|
||||
|
||||
@@ -57,7 +57,7 @@ export class HoverOperation<Result> {
|
||||
private _firstWaitScheduler: RunOnceScheduler;
|
||||
private _secondWaitScheduler: RunOnceScheduler;
|
||||
private _loadingMessageScheduler: RunOnceScheduler;
|
||||
private _asyncComputationPromise: CancelablePromise<void>;
|
||||
private _asyncComputationPromise: CancelablePromise<Result>;
|
||||
private _asyncComputationPromiseDone: boolean;
|
||||
|
||||
private _completeCallback: (r: Result) => void;
|
||||
@@ -103,12 +103,11 @@ export class HoverOperation<Result> {
|
||||
|
||||
if (this._computer.computeAsync) {
|
||||
this._asyncComputationPromiseDone = false;
|
||||
this._asyncComputationPromise = createCancelablePromise(token => {
|
||||
return this._computer.computeAsync(token).then((asyncResult: Result) => {
|
||||
this._asyncComputationPromiseDone = true;
|
||||
this._withAsyncResult(asyncResult);
|
||||
}, (e) => this._onError(e));
|
||||
});
|
||||
this._asyncComputationPromise = createCancelablePromise(token => this._computer.computeAsync(token));
|
||||
this._asyncComputationPromise.then((asyncResult: Result) => {
|
||||
this._asyncComputationPromiseDone = true;
|
||||
this._withAsyncResult(asyncResult);
|
||||
}, (e) => this._onError(e));
|
||||
|
||||
} else {
|
||||
this._asyncComputationPromiseDone = true;
|
||||
|
||||
@@ -149,7 +149,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
private editor: ICodeEditor;
|
||||
private enabled: boolean;
|
||||
private listenersToRemove: IDisposable[];
|
||||
private timeoutPromise: async.CancelablePromise<void>;
|
||||
private timeout: async.TimeoutTimer;
|
||||
private computePromise: async.CancelablePromise<Link[]>;
|
||||
private activeLinkDecorationId: string;
|
||||
private openerService: IOpenerService;
|
||||
@@ -201,7 +201,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
this.listenersToRemove.push(editor.onDidChangeModelLanguage((e) => this.onModelModeChanged()));
|
||||
this.listenersToRemove.push(LinkProviderRegistry.onDidChange((e) => this.onModelModeChanged()));
|
||||
|
||||
this.timeoutPromise = null;
|
||||
this.timeout = new async.TimeoutTimer();
|
||||
this.computePromise = null;
|
||||
this.currentOccurrences = {};
|
||||
this.activeLinkDecorationId = null;
|
||||
@@ -225,13 +225,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
}
|
||||
|
||||
private onChange(): void {
|
||||
if (!this.timeoutPromise) {
|
||||
this.timeoutPromise = async.timeout(LinkDetector.RECOMPUTE_TIME);
|
||||
this.timeoutPromise.then(() => {
|
||||
this.timeoutPromise = null;
|
||||
this.beginCompute();
|
||||
});
|
||||
}
|
||||
this.timeout.setIfNotSet(() => this.beginCompute(), LinkDetector.RECOMPUTE_TIME);
|
||||
}
|
||||
|
||||
private async beginCompute(): Promise<void> {
|
||||
@@ -374,10 +368,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
}
|
||||
|
||||
private stop(): void {
|
||||
if (this.timeoutPromise) {
|
||||
this.timeoutPromise.cancel();
|
||||
this.timeoutPromise = null;
|
||||
}
|
||||
this.timeout.cancel();
|
||||
if (this.computePromise) {
|
||||
this.computePromise.cancel();
|
||||
this.computePromise = null;
|
||||
@@ -387,6 +378,7 @@ class LinkDetector implements editorCommon.IEditorContribution {
|
||||
public dispose(): void {
|
||||
this.listenersToRemove = dispose(this.listenersToRemove);
|
||||
this.stop();
|
||||
this.timeout.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as nls from 'vs/nls';
|
||||
|
||||
import { first2, createCancelablePromise, CancelablePromise } from 'vs/base/common/async';
|
||||
import { onUnexpectedExternalError } from 'vs/base/common/errors';
|
||||
import { onUnexpectedExternalError, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { registerEditorContribution, EditorAction, IActionOptions, registerEditorAction, registerDefaultLanguageCommand } from 'vs/editor/browser/editorExtensions';
|
||||
@@ -300,7 +300,7 @@ class WordHighlighter {
|
||||
this.workerRequestValue = data || [];
|
||||
this._beginRenderDecorations();
|
||||
}
|
||||
});
|
||||
}, onUnexpectedError);
|
||||
}
|
||||
|
||||
this._lastWordRange = currentWordRange;
|
||||
|
||||
Reference in New Issue
Block a user