Skip to content

Commit 6c0eaea

Browse files
authored
Ensure renamePending gets reset when operation is complete (#4344)
1 parent c44c50b commit 6c0eaea

File tree

4 files changed

+42
-27
lines changed

4 files changed

+42
-27
lines changed

Extension/assets/minus-dark.svg

Lines changed: 1 addition & 1 deletion
Loading

Extension/assets/minus-light.svg

Lines changed: 1 addition & 1 deletion
Loading

Extension/src/LanguageServer/client.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ let failureMessageShown: boolean = false;
286286

287287
let referencesRequestPending: boolean = false;
288288
let renamePending: boolean = false;
289+
let renameRequestsPending: number = 0;
289290
let referencesParams: RenameParams | FindAllReferencesParams;
290291

291292
interface ReferencesCancellationState {
@@ -659,7 +660,7 @@ export class DefaultClient implements Client {
659660
});
660661
};
661662

662-
if (referencesRequestPending) {
663+
if (referencesRequestPending || (this.client.references.symbolSearchInProgress && !this.client.references.referencesViewFindPending)) {
663664
let cancelling: boolean = referencesPendingCancellations.length > 0;
664665
referencesPendingCancellations.push({ reject, callback });
665666
if (!cancelling) {
@@ -688,6 +689,7 @@ export class DefaultClient implements Client {
688689
// VS Code will attempt to issue new rename requests while another is still active.
689690
// When we receive another rename request, cancel the one that is in progress.
690691
renamePending = true;
692+
++renameRequestsPending;
691693
return new Promise<vscode.WorkspaceEdit>((resolve, reject) => {
692694
let callback: () => void = () => {
693695
let params: RenameParams = {
@@ -700,13 +702,17 @@ export class DefaultClient implements Client {
700702
// The current request is represented by referencesParams. If a request detects
701703
// referencesParams does not match the object used when creating the request, abort it.
702704
if (params !== referencesParams) {
705+
if (--renameRequestsPending === 0) {
706+
renamePending = false;
707+
}
703708
reject();
704709
return;
705710
}
706711
referencesRequestPending = true;
707712
this.client.languageClient.sendNotification(RenameNotification, params);
708713
this.client.references.setResultsCallback((referencesResult) => {
709714
referencesRequestPending = false;
715+
--renameRequestsPending;
710716
let workspaceEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
711717
let cancelling: boolean = referencesPendingCancellations.length > 0;
712718
if (cancelling) {
@@ -719,6 +725,9 @@ export class DefaultClient implements Client {
719725
referencesPendingCancellations.pop();
720726
pendingCancel.callback();
721727
} else {
728+
if (renameRequestsPending === 0) {
729+
renamePending = false;
730+
}
722731
// If rename UI Was cancelled, we will get a null result
723732
// If null, return an empty list to avoid Rename failure dialog
724733
if (referencesResult !== null) {
@@ -735,9 +744,9 @@ export class DefaultClient implements Client {
735744
});
736745
};
737746

738-
if (referencesRequestPending) {
747+
if (referencesRequestPending || this.client.references.symbolSearchInProgress) {
739748
let cancelling: boolean = referencesPendingCancellations.length > 0;
740-
referencesPendingCancellations.push({ reject, callback });
749+
referencesPendingCancellations.push({ reject: () => { --renameRequestsPending; reject(); }, callback });
741750
if (!cancelling) {
742751
this.client.languageClient.sendNotification(CancelReferencesNotification);
743752
this.client.references.closeRenameUI();
@@ -2148,11 +2157,13 @@ export class DefaultClient implements Client {
21482157
public cancelReferences(): void {
21492158
referencesParams = null;
21502159
renamePending = false;
2151-
let cancelling: boolean = referencesPendingCancellations.length > 0;
2152-
if (!cancelling) {
2160+
if (referencesRequestPending || this.references.symbolSearchInProgress) {
2161+
let cancelling: boolean = referencesPendingCancellations.length > 0;
21532162
referencesPendingCancellations.push({ reject: () => {}, callback: () => {} });
2154-
this.languageClient.sendNotification(CancelReferencesNotification);
2155-
this.references.closeRenameUI();
2163+
if (!cancelling) {
2164+
this.languageClient.sendNotification(CancelReferencesNotification);
2165+
this.references.closeRenameUI();
2166+
}
21562167
}
21572168
}
21582169

Extension/src/LanguageServer/references.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class ReferencesManager {
126126
private renameView: RenameView;
127127
private viewsInitialized: boolean = false;
128128

129+
public symbolSearchInProgress: boolean = false;
129130
private referencesCurrentProgress: ReportReferencesProgressNotification;
130131
private referencesPrevProgressIncrement: number;
131132
private referencesPrevProgressMessage: string;
@@ -343,7 +344,20 @@ export class ReferencesManager {
343344
this.referencesChannel.show(true);
344345
}
345346

346-
if (this.client.ReferencesCommandMode === ReferencesCommandMode.Rename) {
347+
let currentReferenceCommandMode: ReferencesCommandMode = this.client.ReferencesCommandMode;
348+
if (referencesResult.isFinished) {
349+
this.symbolSearchInProgress = false;
350+
clearInterval(this.referencesDelayProgress);
351+
if (this.currentUpdateProgressTimer) {
352+
clearInterval(this.currentUpdateProgressTimer);
353+
this.currentUpdateProgressResolve();
354+
this.currentUpdateProgressResolve = null;
355+
this.currentUpdateProgressTimer = null;
356+
}
357+
this.client.setReferencesCommandMode(ReferencesCommandMode.None);
358+
}
359+
360+
if (currentReferenceCommandMode === ReferencesCommandMode.Rename) {
347361
if (!this.referencesCanceled) {
348362
// If there are only Confirmed results, complete the rename immediately.
349363
let foundUnconfirmed: ReferenceInfo = referencesResult.referenceInfos.find(e => e.type !== ReferenceType.Confirmed);
@@ -353,40 +367,30 @@ export class ReferencesManager {
353367
this.renameView.show(true);
354368
this.renameView.setData(referencesResult, this.resultsCallback);
355369
}
370+
} else {
371+
// Do nothing when rename is canceled while searching for references was in progress.
372+
this.resultsCallback(null);
356373
}
357374
} else {
358-
// Put results in data model
359375
this.findAllRefsView.setData(referencesResult, this.referencesCanceled);
360376

361377
// Display data based on command mode: peek references OR find all references
362-
if (this.client.ReferencesCommandMode === ReferencesCommandMode.Peek) {
378+
if (currentReferenceCommandMode === ReferencesCommandMode.Peek) {
363379
let showConfirmedReferences: boolean = this.referencesCanceled;
364380
let peekReferencesResults: string = this.findAllRefsView.getResultsAsText(showConfirmedReferences);
365381
if (peekReferencesResults) {
366382
this.referencesChannel.appendLine(peekReferencesResults);
367383
this.referencesChannel.show(true);
368384
}
369-
} else if (this.client.ReferencesCommandMode === ReferencesCommandMode.Find) {
385+
} else if (currentReferenceCommandMode === ReferencesCommandMode.Find) {
370386
this.findAllRefsView.show(true);
371387
}
372-
}
373-
374-
if (referencesResult.isFinished) {
375-
clearInterval(this.referencesDelayProgress);
376-
if (this.currentUpdateProgressTimer) {
377-
clearInterval(this.currentUpdateProgressTimer);
378-
this.currentUpdateProgressResolve();
379-
this.currentUpdateProgressResolve = null;
380-
this.currentUpdateProgressTimer = null;
381-
}
382-
if (this.client.ReferencesCommandMode !== ReferencesCommandMode.Rename) {
383-
this.resultsCallback(referencesResult);
384-
}
385-
this.client.setReferencesCommandMode(ReferencesCommandMode.None);
388+
this.resultsCallback(referencesResult);
386389
}
387390
}
388391

389392
public setResultsCallback(callback: (results: ReferencesResult) => void): void {
393+
this.symbolSearchInProgress = true;
390394
this.resultsCallback = callback;
391395
}
392396

0 commit comments

Comments
 (0)