Skip to content

Commit 346ee37

Browse files
authored
Seanmcm/fix2nd references (#4367)
* More fixes.
1 parent db7b8e7 commit 346ee37

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ export class DefaultClient implements Client {
613613
this.client = client;
614614
}
615615
public async provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): Promise<vscode.Location[] | undefined> {
616+
// tslint:disable-next-line: promise-must-complete
616617
return new Promise<vscode.Location[]>((resolve, reject) => {
617618
let callback: () => void = () => {
618619
let params: FindAllReferencesParams = {
@@ -631,6 +632,18 @@ export class DefaultClient implements Client {
631632
// Register a single-fire handler for the reply.
632633
let resultCallback: refs.ReferencesResultCallback = (result: refs.ReferencesResult) => {
633634
referencesRequestPending = false;
635+
let locations: vscode.Location[] = [];
636+
result.referenceInfos.forEach((referenceInfo: refs.ReferenceInfo) => {
637+
if (referenceInfo.type === refs.ReferenceType.Confirmed) {
638+
let uri: vscode.Uri = vscode.Uri.file(referenceInfo.file);
639+
let range: vscode.Range = new vscode.Range(referenceInfo.position.line, referenceInfo.position.character, referenceInfo.position.line, referenceInfo.position.character + result.text.length);
640+
locations.push(new vscode.Location(uri, range));
641+
}
642+
});
643+
if (!this.client.references.referencesCanceledIgnoreResults) {
644+
this.client.references.referencesCanceledIgnoreResults = false;
645+
resolve(locations);
646+
}
634647
if (referencesPendingCancellations.length > 0) {
635648
while (referencesPendingCancellations.length > 1) {
636649
let pendingCancel: ReferencesCancellationState = referencesPendingCancellations[0];
@@ -641,19 +654,11 @@ export class DefaultClient implements Client {
641654
referencesPendingCancellations.pop();
642655
pendingCancel.callback();
643656
}
644-
let locations: vscode.Location[] = [];
645-
result.referenceInfos.forEach((referenceInfo: refs.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);
653657
};
654658
if (this.client.references.lastResults) {
655-
resultCallback(this.client.references.lastResults);
659+
let lastResults: refs.ReferencesResult = this.client.references.lastResults;
656660
this.client.references.lastResults = null;
661+
resultCallback(lastResults);
657662
} else {
658663
this.client.languageClient.sendNotification(FindAllReferencesNotification, params);
659664
this.client.references.setResultsCallback(resultCallback);
@@ -671,6 +676,7 @@ export class DefaultClient implements Client {
671676
referencesPendingCancellations.push({ reject, callback });
672677
if (!cancelling) {
673678
renamePending = false;
679+
this.client.references.referencesCanceledIgnoreResults = true;
674680
this.client.languageClient.sendNotification(CancelReferencesNotification);
675681
this.client.references.closeRenameUI();
676682
}
@@ -754,6 +760,7 @@ export class DefaultClient implements Client {
754760
let cancelling: boolean = referencesPendingCancellations.length > 0;
755761
referencesPendingCancellations.push({ reject: () => { --renameRequestsPending; reject(); }, callback });
756762
if (!cancelling) {
763+
this.client.references.referencesCanceledIgnoreResults = true;
757764
this.client.languageClient.sendNotification(CancelReferencesNotification);
758765
this.client.references.closeRenameUI();
759766
}
@@ -2167,6 +2174,7 @@ export class DefaultClient implements Client {
21672174
let cancelling: boolean = referencesPendingCancellations.length > 0;
21682175
referencesPendingCancellations.push({ reject: () => {}, callback: () => {} });
21692176
if (!cancelling) {
2177+
this.references.referencesCanceled = true;
21702178
this.languageClient.sendNotification(CancelReferencesNotification);
21712179
this.references.closeRenameUI();
21722180
}

Extension/src/LanguageServer/references.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ export class ReferencesManager {
136136
public referencesViewFindPending: boolean = false;
137137
private referencesDelayProgress: NodeJS.Timeout;
138138
private referencesProgressOptions: vscode.ProgressOptions;
139-
private referencesCanceled: boolean;
139+
public referencesCanceled: boolean;
140+
public referencesCanceledIgnoreResults: boolean;
140141
private referencesStartedWhileTagParsing: boolean;
141142
private referencesProgressMethod: (progress: vscode.Progress<{
142143
message?: string;
@@ -275,6 +276,7 @@ export class ReferencesManager {
275276

276277
this.referencesRequestHasOccurred = false;
277278
this.referencesCanceled = false;
279+
this.referencesCanceledIgnoreResults = false;
278280
this.referencesPrevProgressIncrement = 0;
279281
this.referencesPrevProgressMessage = "";
280282
this.referencesCurrentProgressUICounter = 0;
@@ -387,8 +389,9 @@ export class ReferencesManager {
387389
} else if (currentReferenceCommandMode === ReferencesCommandMode.Find) {
388390
this.findAllRefsView.show(true);
389391
}
390-
if (referencesResult.isFinished && this.referencesRequestHasOccurred) {
392+
if (referencesResult.isFinished && this.referencesRequestHasOccurred && !this.referencesCanceledIgnoreResults) {
391393
this.lastResults = referencesResult;
394+
this.referencesViewFindPending = true;
392395
vscode.commands.executeCommand("references-view.refresh");
393396
} else {
394397
this.resultsCallback(referencesResult);

0 commit comments

Comments
 (0)