Skip to content

Commit

Permalink
Seanmcm/fix2nd references (#4367)
Browse files Browse the repository at this point in the history
* More fixes.
  • Loading branch information
sean-mcmanus authored Oct 1, 2019
1 parent db7b8e7 commit 346ee37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
28 changes: 18 additions & 10 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Location[] | undefined> {
// tslint:disable-next-line: promise-must-complete
return new Promise<vscode.Location[]>((resolve, reject) => {
let callback: () => void = () => {
let params: FindAllReferencesParams = {
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 5 additions & 2 deletions Extension/src/LanguageServer/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -275,6 +276,7 @@ export class ReferencesManager {

this.referencesRequestHasOccurred = false;
this.referencesCanceled = false;
this.referencesCanceledIgnoreResults = false;
this.referencesPrevProgressIncrement = 0;
this.referencesPrevProgressMessage = "";
this.referencesCurrentProgressUICounter = 0;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 346ee37

Please sign in to comment.