Skip to content

Commit 5de35ce

Browse files
committed
[optimize] sort include directories when show it
1 parent 1ca5211 commit 5de35ce

2 files changed

Lines changed: 53 additions & 21 deletions

File tree

src/EIDEProjectExplorer.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ import {
8787
runShellCommand, redirectHost, readGithubRepoFolder, FileCache,
8888
genGithubHash, md5, toArray, newMarkdownString, newFileTooltipString, FileTooltipInfo, escapeXml,
8989
readGithubRepoTxtFile, downloadFile, notifyReloadWindow, formatPath, execInternalCommand,
90-
copyAndMakeObjectKeysToLowerCase
90+
copyAndMakeObjectKeysToLowerCase,
91+
sortPaths
9192
} from './utility';
9293
import { concatSystemEnvPath, DeleteDir, exeSuffix, kill, osType, DeleteAllChildren } from './Platform';
9394
import { KeilARMOption, KeilC51Option, KeilParser, KeilRteDependence } from './KeilXmlParser';
@@ -1164,7 +1165,13 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
11641165
const keyList = config.CustomDep_GetEnabledKeys();
11651166

11661167
for (const key of keyList) {
1167-
const depValues: string[] = (<any>customDep)[key];
1168+
1169+
let depValues: string[] = (<any>customDep)[key];
1170+
1171+
if (key == 'incList' || key == 'libList') { // is path list ?
1172+
depValues = sortPaths(depValues.map((val) => project.toRelativePath(val)), '/');
1173+
}
1174+
11681175
if (Array.isArray(depValues)) {
11691176
iList.push(new ProjTreeItem(TreeItemType.DEPENDENCE_GROUP_ARRAY_FIELD, {
11701177
value: config.GetDepKeyDesc(key),
@@ -1173,9 +1180,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
11731180
`- **Count:** \`${depValues.length}\``]),
11741181
obj: new ModifiableDepInfo('None', key),
11751182
childKey: key,
1176-
child: depValues
1177-
.map((val) => { return project.toRelativePath(val); })
1178-
.sort((val_1, val_2) => { return val_1.length - val_2.length; }),
1183+
child: depValues,
11791184
projectIndex: element.val.projectIndex
11801185
}));
11811186
}
@@ -5621,31 +5626,39 @@ export class ProjectExplorer implements CustomConfigurationProvider {
56215626
async showIncludeDir(prjIndex: number) {
56225627

56235628
const prj = this.dataProvider.GetProjectByIndex(prjIndex);
5624-
let pickItems: vscode.QuickPickItem[] = [];
5629+
const pickItems: vscode.QuickPickItem[] = [];
56255630
const includesMap: Map<string, string> = new Map();
56265631

5632+
let includes: string[] = [];
5633+
56275634
// add dependence include paths
56285635
prj.GetConfiguration().getAllDepGroup().forEach((group) => {
56295636
for (const dep of group.depList) {
56305637
for (const incPath of dep.incList) {
5631-
includesMap.set(prj.toRelativePath(incPath), group.groupName);
5638+
const repath = prj.toRelativePath(incPath);
5639+
includes.push(repath);
5640+
includesMap.set(repath, group.groupName);
56325641
}
56335642
}
56345643
});
56355644

56365645
// add source include paths
56375646
prj.getSourceIncludeList().forEach((incPath) => {
5638-
includesMap.set(prj.toRelativePath(incPath), 'source');
5647+
const repath = prj.toRelativePath(incPath);
5648+
includes.push(repath);
5649+
includesMap.set(repath, 'source');
56395650
});
56405651

5641-
for (const keyVal of includesMap) {
5652+
includes = sortPaths(includes, '/');
56425653

5643-
const incPath = keyVal[0];
5644-
const grpName = keyVal[1];
5654+
for (const repath of includes) {
5655+
5656+
const incPath = repath;
5657+
const grpName = includesMap.get(repath);
56455658

56465659
let descpLi: string[] = [];
56475660

5648-
if (grpName != ProjectConfiguration.CUSTOM_GROUP_NAME) {
5661+
if (grpName && grpName != ProjectConfiguration.CUSTOM_GROUP_NAME) {
56495662
descpLi.push(grpName);
56505663
}
56515664

@@ -5659,15 +5672,6 @@ export class ProjectExplorer implements CustomConfigurationProvider {
56595672
});
56605673
}
56615674

5662-
// sort result
5663-
pickItems = pickItems.sort((i1, i2) => {
5664-
if (i1.description && i2.description && i1.description != i2.description) {
5665-
return i1.description.localeCompare(i2.description);
5666-
} else {
5667-
return i1.label.length - i2.label.length;
5668-
}
5669-
});
5670-
56715675
const item = await vscode.window.showQuickPick(pickItems, {
56725676
placeHolder: `${pickItems.length} results, click one copy to clipboard`
56735677
});

src/utility.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ import { ExeCmd } from '../lib/node-utility/Executable';
4242
import { GlobalEvent } from './GlobalEvents';
4343
import { SettingManager } from './SettingManager';
4444

45+
export function sortPaths(pathList: string[], sep?: string): string[] {
46+
47+
let plist: string[][] = pathList.map(p => p.split(/\\|\//));
48+
49+
plist = plist.sort((p1, p2) => {
50+
51+
const minLen = Math.min(p1.length, p2.length);
52+
53+
for (let i = 0; i < minLen; i++) {
54+
55+
const e1 = p1[i];
56+
const e2 = p2[i];
57+
58+
if (e1.length != e2.length)
59+
return e1.length - e2.length;
60+
61+
if (e1 == e2)
62+
continue;
63+
64+
return e1.localeCompare(e2);
65+
}
66+
67+
return p1.length - p2.length;
68+
});
69+
70+
return plist.map(pl => pl.join(sep || File.sep));
71+
}
72+
4573
export function mergeEnv(old_kv: any, new_kv: any, prependPath?: boolean): any {
4674

4775
const pnam = platform.osType() == 'win32' ? 'Path' : 'PATH';

0 commit comments

Comments
 (0)