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:
Kevin Cunnane
2018-09-05 14:01:09 -07:00
committed by GitHub
parent ac96919caf
commit b7f4f6af3a
6 changed files with 27 additions and 34 deletions

View File

@@ -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();
}
}