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