Skip to content

Commit e2fabf9

Browse files
sean-mcmanusColengms
authored andcommitted
Fix cancel references. (#4341)
1 parent 01340bb commit e2fabf9

File tree

5 files changed

+49
-58
lines changed

5 files changed

+49
-58
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -629,32 +629,27 @@ export class DefaultClient implements Client {
629629
referencesRequestPending = true;
630630
this.client.languageClient.sendNotification(FindAllReferencesNotification, params);
631631
// Register a single-fire handler for the reply.
632-
this.client.references.setResultsCallback((final, result) => {
632+
this.client.references.setResultsCallback((result) => {
633633
referencesRequestPending = false;
634-
let cancelling: boolean = referencesPendingCancellations.length > 0;
635-
if (cancelling) {
636-
if (final) {
637-
reject();
638-
while (referencesPendingCancellations.length > 1) {
639-
let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0];
640-
referencesPendingCancellations.pop();
641-
pendingCancel.reject();
642-
}
634+
if (referencesPendingCancellations.length > 0) {
635+
while (referencesPendingCancellations.length > 1) {
643636
let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0];
644637
referencesPendingCancellations.pop();
645-
pendingCancel.callback();
638+
pendingCancel.reject();
646639
}
647-
} else {
648-
let locations: vscode.Location[] = [];
649-
result.referenceInfos.forEach(referenceInfo => {
650-
if (referenceInfo.type === refs.ReferenceType.Confirmed) {
651-
let uri: vscode.Uri = vscode.Uri.file(referenceInfo.file);
652-
let range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length);
653-
locations.push(new vscode.Location(uri, range));
654-
}
655-
});
656-
resolve(locations);
640+
let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0];
641+
referencesPendingCancellations.pop();
642+
pendingCancel.callback();
657643
}
644+
let locations: vscode.Location[] = [];
645+
result.referenceInfos.forEach(referenceInfo => {
646+
if (referenceInfo.type === refs.ReferenceType.Confirmed) {
647+
let uri: vscode.Uri = vscode.Uri.file(referenceInfo.file);
648+
let range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length);
649+
locations.push(new vscode.Location(uri, range));
650+
}
651+
});
652+
resolve(locations);
658653
});
659654
});
660655
token.onCancellationRequested(e => {
@@ -710,7 +705,7 @@ export class DefaultClient implements Client {
710705
}
711706
referencesRequestPending = true;
712707
this.client.languageClient.sendNotification(RenameNotification, params);
713-
this.client.references.setResultsCallback((final, referencesResult) => {
708+
this.client.references.setResultsCallback((referencesResult) => {
714709
referencesRequestPending = false;
715710
let workspaceEdit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
716711
let cancelling: boolean = referencesPendingCancellations.length > 0;

Extension/src/LanguageServer/references.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export interface ReferenceInfo {
3131
}
3232

3333
export interface ReferencesResult {
34-
text: string;
3534
referenceInfos: ReferenceInfo[];
35+
text: string;
36+
isFinished: boolean;
3637
}
3738

3839
export interface ReferencesResultMessage {
@@ -43,8 +44,7 @@ enum ReferencesProgress {
4344
Started,
4445
StartedRename,
4546
ProcessingSource,
46-
ProcessingTargets,
47-
Finished
47+
ProcessingTargets
4848
}
4949

5050
enum TargetReferencesProgress {
@@ -114,7 +114,7 @@ function getReferenceCanceledString(upperCase?: boolean): string {
114114
}
115115

116116
export function getReferenceTagString(referenceType: ReferenceType, referenceCanceled: boolean, upperCase?: boolean): string {
117-
return referenceCanceled ? getReferenceCanceledString(upperCase) : convertReferenceTypeToString(referenceType, upperCase);
117+
return referenceCanceled && referenceType === ReferenceType.ConfirmationInProgress ? getReferenceCanceledString(upperCase) : convertReferenceTypeToString(referenceType, upperCase);
118118
}
119119

120120
export class ReferencesManager {
@@ -148,10 +148,9 @@ export class ReferencesManager {
148148
private visibleRangesDecreasedTicks: number = 0;
149149
private readonly ticksForDetectingPeek: number = 1000; // TODO: Might need tweeking?
150150

151-
private resultsCallback: (final: boolean, results: ReferencesResult) => void;
151+
private resultsCallback: (results: ReferencesResult) => void;
152152
private currentUpdateProgressTimer: NodeJS.Timeout;
153153
private currentUpdateProgressResolve: () => void;
154-
private lastResult: ReferencesResult;
155154

156155
constructor(client: DefaultClient) {
157156
this.client = client;
@@ -295,7 +294,7 @@ export class ReferencesManager {
295294
this.client.cancelReferences();
296295
this.referencesCanceled = true;
297296
}
298-
if (this.referencesCurrentProgress.referencesProgress === ReferencesProgress.Finished || this.referencesCurrentProgressUICounter !== referencePreviousProgressUICounter) {
297+
if (this.referencesCurrentProgressUICounter !== referencePreviousProgressUICounter) {
299298
clearInterval(this.currentUpdateProgressTimer);
300299
this.currentUpdateProgressTimer = null;
301300
if (this.referencesCurrentProgressUICounter !== referencePreviousProgressUICounter) {
@@ -325,22 +324,6 @@ export class ReferencesManager {
325324
}
326325
this.handleProgressStarted(notificationBody.referencesProgress);
327326
break;
328-
case ReferencesProgress.Finished:
329-
this.referencesCurrentProgress = notificationBody;
330-
clearInterval(this.referencesDelayProgress);
331-
if (this.currentUpdateProgressTimer) {
332-
clearInterval(this.currentUpdateProgressTimer);
333-
this.currentUpdateProgressResolve();
334-
this.currentUpdateProgressResolve = null;
335-
}
336-
if (this.client.ReferencesCommandMode !== ReferencesCommandMode.Rename) {
337-
let callback: (final: boolean, result: ReferencesResult) => void = this.resultsCallback;
338-
this.resultsCallback = null;
339-
callback(true, this.lastResult);
340-
this.lastResult = null;
341-
}
342-
this.client.setReferencesCommandMode(ReferencesCommandMode.None);
343-
break;
344327
default:
345328
this.referencesCurrentProgress = notificationBody;
346329
break;
@@ -365,7 +348,7 @@ export class ReferencesManager {
365348
// If there are only Confirmed results, complete the rename immediately.
366349
let foundUnconfirmed: ReferenceInfo = referencesResult.referenceInfos.find(e => e.type !== ReferenceType.Confirmed);
367350
if (!foundUnconfirmed) {
368-
this.resultsCallback(true, referencesResult);
351+
this.resultsCallback(referencesResult);
369352
} else {
370353
this.renameView.show(true);
371354
this.renameView.setData(referencesResult, this.resultsCallback);
@@ -386,12 +369,24 @@ export class ReferencesManager {
386369
} else if (this.client.ReferencesCommandMode === ReferencesCommandMode.Find) {
387370
this.findAllRefsView.show(true);
388371
}
389-
this.lastResult = referencesResult;
390-
this.resultsCallback(false, referencesResult);
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);
391386
}
392387
}
393388

394-
public setResultsCallback(callback: (final: boolean, results: ReferencesResult) => void): void {
389+
public setResultsCallback(callback: (results: ReferencesResult) => void): void {
395390
this.resultsCallback = callback;
396391
}
397392

Extension/src/LanguageServer/referencesProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getReferenceCanceledIconPath(): { light: string; dark: string } {
4444
}
4545

4646
function getReferenceItemIconPath(type: ReferenceType, isCanceled: boolean): { light: string; dark: string } {
47-
return isCanceled ? getReferenceCanceledIconPath() : getReferenceTypeIconPath(type);
47+
return (isCanceled && type === ReferenceType.ConfirmationInProgress) ? getReferenceCanceledIconPath() : getReferenceTypeIconPath(type);
4848
}
4949

5050
type TreeObject = FileItem | ReferenceItem | ReferenceTypeItem;

Extension/src/LanguageServer/renameModel.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ let currentRenameModel: RenameModel;
237237
export class RenameModel {
238238
private pendingGroup: RenamePendingFilesGroupItem;
239239
private candidatesGroup: RenameCandidateReferenceTypeGroupItem;
240-
private renameResultsCallback: (final: boolean, results: ReferencesResult) => void;
240+
private renameResultsCallback: (results: ReferencesResult) => void;
241241
private originalText: string;
242242

243-
constructor(resultsInput: ReferencesResult, readonly pendingProvider: RenameDataProvider, readonly candidateProvider: RenameDataProvider, resultsCallback: (final: boolean, results: ReferencesResult) => void) {
243+
constructor(resultsInput: ReferencesResult, readonly pendingProvider: RenameDataProvider, readonly candidateProvider: RenameDataProvider, resultsCallback: (results: ReferencesResult) => void) {
244244
currentRenameModel = this;
245245
this.originalText = resultsInput.text;
246246
this.renameResultsCallback = resultsCallback;
@@ -284,9 +284,9 @@ export class RenameModel {
284284

285285
cancel(): void {
286286
if (this.renameResultsCallback) {
287-
let callback: (final: boolean, results: ReferencesResult) => void = this.renameResultsCallback;
287+
let callback: (results: ReferencesResult) => void = this.renameResultsCallback;
288288
this.renameResultsCallback = null;
289-
callback(true, null);
289+
callback(null);
290290
}
291291
}
292292

@@ -304,12 +304,13 @@ export class RenameModel {
304304
});
305305
});
306306
let results: ReferencesResult = {
307+
referenceInfos: referenceInfos,
307308
text: this.originalText,
308-
referenceInfos: referenceInfos
309+
isFinished: true
309310
};
310-
let callback: (final: boolean, results: ReferencesResult) => void = this.renameResultsCallback;
311+
let callback: (results: ReferencesResult) => void = this.renameResultsCallback;
311312
this.renameResultsCallback = null;
312-
callback(true, results);
313+
callback(results);
313314
}
314315
}
315316

Extension/src/LanguageServer/renameView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class RenameView {
3939
}
4040
}
4141

42-
setData(results: ReferencesResult, resultsCallback: (final: boolean, results: ReferencesResult) => void): void {
42+
setData(results: ReferencesResult, resultsCallback: (results: ReferencesResult) => void): void {
4343
this.model = new RenameModel(results, this.renamePendingDataProvider, this.renameCandidatesDataProvider, resultsCallback);
4444
this.renamePendingDataProvider.setModel(this.model);
4545
this.renameCandidatesDataProvider.setModel(this.model);

0 commit comments

Comments
 (0)