mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-04-01 01:20:31 -04: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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user