Skip to content

Commit

Permalink
Restore fix to a race condition that arises when a new FAR request in…
Browse files Browse the repository at this point in the history
…terrupts a previously previewed request (#4405)
  • Loading branch information
Colengms authored Oct 9, 2019
1 parent 4777a7d commit ed6b46e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 12 additions & 4 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
19 changes: 11 additions & 8 deletions Extension/src/LanguageServer/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit ed6b46e

Please sign in to comment.