Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
tweak group-by logic, microsoft/vscode#97881
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed May 15, 2020
1 parent 090548b commit 721ad3d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ export class ReferencesModel {

static create(uri: vscode.Uri, position: vscode.Position, source: ItemSource): ReferencesModel {
const locations = Promise.resolve(vscode.commands.executeCommand<vscode.Location[]>(source, uri, position)).then(loc => {
if (!loc) {
return [];
} else {
return loc.sort(ReferencesModel._compareLocations);
}
return loc?.sort(ReferencesModel._compareLocations) ?? [];
});
return new ReferencesModel(source, uri, position, locations);
}
Expand All @@ -116,7 +112,7 @@ export class ReferencesModel {
let last: FileItem | undefined;
locations.sort(ReferencesModel._compareLocations);
for (const loc of locations) {
if (!last || last.uri.toString() !== loc.uri.toString()) {
if (!last || ReferencesModel._compareUriIgnoreFragment(last.uri, loc.uri) !== 0) {
last = new FileItem(loc.uri, [], this);
items.push(last);
}
Expand Down Expand Up @@ -267,12 +263,23 @@ export class ReferencesModel {
}
}

private static _compareLocations(a: vscode.Location, b: vscode.Location): number {
if (a.uri.toString() < b.uri.toString()) {
private static _compareUriIgnoreFragment(a: vscode.Uri, b: vscode.Uri): number {
let aStr = a.with({ fragment: '' }).toString();
let bStr = b.with({ fragment: '' }).toString();
if (aStr < bStr) {
return -1;
} else if (a.uri.toString() > b.uri.toString()) {
} else if (aStr < bStr) {
return 1;
} else if (a.range.start.isBefore(b.range.start)) {
}
return 0;
}

private static _compareLocations(a: vscode.Location, b: vscode.Location): number {
let ret = ReferencesModel._compareUriIgnoreFragment(a.uri, b.uri);
if (ret !== 0) {
return ret;
}
if (a.range.start.isBefore(b.range.start)) {
return -1;
} else if (a.range.start.isAfter(b.range.start)) {
return 1;
Expand Down

0 comments on commit 721ad3d

Please sign in to comment.