Skip to content

Commit 1c82d8c

Browse files
committed
Refactor vendordep sorting
1 parent 4ade903 commit 1c82d8c

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

vscode-wpilib/src/dependencyView.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export interface IJSMessage {
3030
url?: string;
3131
}
3232

33+
const collator = Intl.Collator('en', { sensitivity: 'base' });
34+
const sort = (a: { name: string }, b: { name: string }) => collator.compare(a.name, b.name);
35+
3336
export class DependencyViewProvider implements vscode.WebviewViewProvider {
3437
public static readonly viewType = 'wpilib.dependencyView';
3538
private projectInfo: ProjectInfoGatherer;
@@ -560,39 +563,15 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
560563
}
561564

562565
private sortInstalled() {
563-
this.installedList.sort((a, b) => {
564-
if (a.name.toLowerCase() > b.name.toLowerCase()) {
565-
return 1;
566-
} else if (a.name.toLowerCase() === b.name.toLowerCase()) {
567-
return 0;
568-
} else {
569-
return -1;
570-
}
571-
});
566+
this.installedList.sort(sort);
572567
}
573568

574569
private sortInstalledDeps() {
575-
this.installedDeps.sort((a, b) => {
576-
if (a.name.toLowerCase() > b.name.toLowerCase()) {
577-
return 1;
578-
} else if (a.name.toLowerCase() === b.name.toLowerCase()) {
579-
return 0;
580-
} else {
581-
return -1;
582-
}
583-
});
570+
this.installedDeps.sort(sort);
584571
}
585572

586573
private sortAvailable() {
587-
this.availableDepsList.sort((a, b) => {
588-
if (a.name.toLowerCase() > b.name.toLowerCase()) {
589-
return 1;
590-
} else if (a.name.toLowerCase() === b.name.toLowerCase()) {
591-
return 0;
592-
} else {
593-
return -1;
594-
}
595-
});
574+
this.availableDepsList.sort(sort);
596575
}
597576

598577
public async getAvailableDependencies(): Promise<IJsonList[]> {

0 commit comments

Comments
 (0)