diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 1ac0aace4f..8a87f3b667 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -632,7 +632,7 @@ export class DefaultClient implements Client { } referencesRequestPending = true; // Register a single-fire handler for the reply. - let resultCallback: refs.ReferencesResultCallback = (result: refs.ReferencesResult) => { + let resultCallback: refs.ReferencesResultCallback = (result: refs.ReferencesResult, doResolve: boolean) => { referencesRequestPending = false; let locations: vscode.Location[] = []; if (result) { @@ -645,7 +645,9 @@ export class DefaultClient implements Client { }); } // If references were canceled while in a preview state, there is not an outstanding promise. - resolve(locations); + if (doResolve) { + resolve(locations); + } if (referencesPendingCancellations.length > 0) { while (referencesPendingCancellations.length > 1) { let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0]; @@ -667,7 +669,7 @@ export class DefaultClient implements Client { // This is a final result let lastResults: refs.ReferencesResult = this.client.references.lastResults; this.client.references.lastResults = null; - resultCallback(lastResults); + resultCallback(lastResults, true); } else { // This is a preview (2nd or later preview) this.client.references.referencesRequestPending = true; @@ -693,6 +695,9 @@ export class DefaultClient implements Client { if (!cancelling) { renamePending = false; this.client.references.referencesCanceled = true; + if (!referencesRequestPending) { + this.client.references.referencesCanceledWhilePreviewing = true; + } this.client.languageClient.sendNotification(CancelReferencesNotification); this.client.references.closeRenameUI(); } @@ -740,7 +745,7 @@ export class DefaultClient implements Client { return; } referencesRequestPending = true; - this.client.references.setResultsCallback((referencesResult: refs.ReferencesResult) => { + this.client.references.setResultsCallback((referencesResult: refs.ReferencesResult, doResolve: boolean) => { referencesRequestPending = false; --renameRequestsPending; let workspaceEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit(); @@ -785,6 +790,9 @@ export class DefaultClient implements Client { }, callback }); if (!cancelling) { this.client.references.referencesCanceled = true; + if (!referencesRequestPending) { + this.client.references.referencesCanceledWhilePreviewing = true; + } this.client.languageClient.sendNotification(CancelReferencesNotification); this.client.references.closeRenameUI(); } diff --git a/Extension/src/LanguageServer/references.ts b/Extension/src/LanguageServer/references.ts index 364e402583..1cd0470fc5 100644 --- a/Extension/src/LanguageServer/references.ts +++ b/Extension/src/LanguageServer/references.ts @@ -38,7 +38,7 @@ export interface ReferencesResult { isFinished: boolean; } -export type ReferencesResultCallback = (result: ReferencesResult) => void; +export type ReferencesResultCallback = (result: ReferencesResult, doResolve: boolean) => void; export interface ReferencesResultMessage { referencesResult: ReferencesResult; @@ -141,6 +141,7 @@ export class ReferencesManager { private referencesDelayProgress: NodeJS.Timeout; private referencesProgressOptions: vscode.ProgressOptions; public referencesCanceled: boolean = false; + public referencesCanceledWhilePreviewing: boolean; private referencesStartedWhileTagParsing: boolean; private referencesProgressMethod: (progress: vscode.Progress<{ message?: string; @@ -341,9 +342,10 @@ export class ReferencesManager { this.referencesFinished = false; this.referencesRequestHasOccurred = false; this.referencesRequestPending = false; + this.referencesCanceledWhilePreviewing = false; if (this.referencesCanceled) { this.referencesCanceled = false; - this.resultsCallback(null); + this.resultsCallback(null, true); } else { this.client.sendRenameNofication(params); } @@ -354,9 +356,10 @@ export class ReferencesManager { this.referencesFinished = false; this.referencesRequestHasOccurred = false; this.referencesRequestPending = false; + this.referencesCanceledWhilePreviewing = false; if (this.referencesCanceled) { this.referencesCanceled = false; - this.resultsCallback(null); + this.resultsCallback(null, true); } else { this.client.sendFindAllReferencesNotification(params); } @@ -415,17 +418,17 @@ export class ReferencesManager { // If there are only Confirmed results, complete the rename immediately. let foundUnconfirmed: ReferenceInfo = referencesResult.referenceInfos.find(e => e.type !== ReferenceType.Confirmed); if (!foundUnconfirmed) { - this.resultsCallback(referencesResult); + this.resultsCallback(referencesResult, true); } else { this.renameView.setData(referencesResult, this.groupByFile.Value, (result: ReferencesResult) => { this.referencesCanceled = false; - this.resultsCallback(result); + this.resultsCallback(result, true); }); this.renameView.show(true); } } else { // Do nothing when rename is canceled while searching for references was in progress. - this.resultsCallback(null); + this.resultsCallback(null, true); } } else { this.findAllRefsView.setData(referencesResult, referencesCanceled, this.groupByFile.Value); @@ -446,11 +449,11 @@ export class ReferencesManager { this.referencesFinished = true; } if (!this.referencesRefreshPending) { - if (referencesResult.isFinished && this.referencesRequestHasOccurred && !referencesRequestPending) { + if (referencesResult.isFinished && this.referencesRequestHasOccurred && !referencesRequestPending && !this.referencesCanceledWhilePreviewing) { this.referencesRefreshPending = true; vscode.commands.executeCommand("references-view.refresh"); } else { - this.resultsCallback(referencesResult); + this.resultsCallback(referencesResult, !this.referencesCanceledWhilePreviewing); } } }