From 346ee3747287800a0ac1a71361e08525cc297798 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Tue, 1 Oct 2019 16:10:44 -0700 Subject: [PATCH] Seanmcm/fix2nd references (#4367) * More fixes. --- Extension/src/LanguageServer/client.ts | 28 ++++++++++++++-------- Extension/src/LanguageServer/references.ts | 7 ++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index e934f73741..28a857a7ca 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -613,6 +613,7 @@ export class DefaultClient implements Client { this.client = client; } public async provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): Promise { + // tslint:disable-next-line: promise-must-complete return new Promise((resolve, reject) => { let callback: () => void = () => { let params: FindAllReferencesParams = { @@ -631,6 +632,18 @@ export class DefaultClient implements Client { // Register a single-fire handler for the reply. let resultCallback: refs.ReferencesResultCallback = (result: refs.ReferencesResult) => { referencesRequestPending = false; + let locations: vscode.Location[] = []; + result.referenceInfos.forEach((referenceInfo: refs.ReferenceInfo) => { + if (referenceInfo.type === refs.ReferenceType.Confirmed) { + let uri: vscode.Uri = vscode.Uri.file(referenceInfo.file); + let range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length); + locations.push(new vscode.Location(uri, range)); + } + }); + if (!this.client.references.referencesCanceledIgnoreResults) { + this.client.references.referencesCanceledIgnoreResults = false; + resolve(locations); + } if (referencesPendingCancellations.length > 0) { while (referencesPendingCancellations.length > 1) { let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0]; @@ -641,19 +654,11 @@ export class DefaultClient implements Client { referencesPendingCancellations.pop(); pendingCancel.callback(); } - let locations: vscode.Location[] = []; - result.referenceInfos.forEach((referenceInfo: refs.ReferenceInfo) => { - if (referenceInfo.type === refs.ReferenceType.Confirmed) { - let uri: vscode.Uri = vscode.Uri.file(referenceInfo.file); - let range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length); - locations.push(new vscode.Location(uri, range)); - } - }); - resolve(locations); }; if (this.client.references.lastResults) { - resultCallback(this.client.references.lastResults); + let lastResults: refs.ReferencesResult = this.client.references.lastResults; this.client.references.lastResults = null; + resultCallback(lastResults); } else { this.client.languageClient.sendNotification(FindAllReferencesNotification, params); this.client.references.setResultsCallback(resultCallback); @@ -671,6 +676,7 @@ export class DefaultClient implements Client { referencesPendingCancellations.push({ reject, callback }); if (!cancelling) { renamePending = false; + this.client.references.referencesCanceledIgnoreResults = true; this.client.languageClient.sendNotification(CancelReferencesNotification); this.client.references.closeRenameUI(); } @@ -754,6 +760,7 @@ export class DefaultClient implements Client { let cancelling: boolean = referencesPendingCancellations.length > 0; referencesPendingCancellations.push({ reject: () => { --renameRequestsPending; reject(); }, callback }); if (!cancelling) { + this.client.references.referencesCanceledIgnoreResults = true; this.client.languageClient.sendNotification(CancelReferencesNotification); this.client.references.closeRenameUI(); } @@ -2167,6 +2174,7 @@ export class DefaultClient implements Client { let cancelling: boolean = referencesPendingCancellations.length > 0; referencesPendingCancellations.push({ reject: () => {}, callback: () => {} }); if (!cancelling) { + this.references.referencesCanceled = true; this.languageClient.sendNotification(CancelReferencesNotification); this.references.closeRenameUI(); } diff --git a/Extension/src/LanguageServer/references.ts b/Extension/src/LanguageServer/references.ts index e5dd0d0974..b43655692c 100644 --- a/Extension/src/LanguageServer/references.ts +++ b/Extension/src/LanguageServer/references.ts @@ -136,7 +136,8 @@ export class ReferencesManager { public referencesViewFindPending: boolean = false; private referencesDelayProgress: NodeJS.Timeout; private referencesProgressOptions: vscode.ProgressOptions; - private referencesCanceled: boolean; + public referencesCanceled: boolean; + public referencesCanceledIgnoreResults: boolean; private referencesStartedWhileTagParsing: boolean; private referencesProgressMethod: (progress: vscode.Progress<{ message?: string; @@ -275,6 +276,7 @@ export class ReferencesManager { this.referencesRequestHasOccurred = false; this.referencesCanceled = false; + this.referencesCanceledIgnoreResults = false; this.referencesPrevProgressIncrement = 0; this.referencesPrevProgressMessage = ""; this.referencesCurrentProgressUICounter = 0; @@ -387,8 +389,9 @@ export class ReferencesManager { } else if (currentReferenceCommandMode === ReferencesCommandMode.Find) { this.findAllRefsView.show(true); } - if (referencesResult.isFinished && this.referencesRequestHasOccurred) { + if (referencesResult.isFinished && this.referencesRequestHasOccurred && !this.referencesCanceledIgnoreResults) { this.lastResults = referencesResult; + this.referencesViewFindPending = true; vscode.commands.executeCommand("references-view.refresh"); } else { this.resultsCallback(referencesResult);