Skip to content

Commit f21d402

Browse files
committed
optimize 'ToRelativePath' api
1 parent 9146a9e commit f21d402

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

lib/node-utility

src/CodeBuilder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export abstract class CodeBuilder {
133133
for (const source of group.files) {
134134
if (source.disabled) continue; // skip disabled file
135135
if (!filter.some((reg) => reg.test(source.file.path))) continue; // skip non-source
136-
const rePath = this.project.ToRelativePath(source.file.path, false);
136+
const rePath = this.project.ToRelativePath(source.file.path);
137137
const fInfo: any = { path: rePath || source.file.path }
138138
if (AbstractProject.isVirtualSourceGroup(group)) {
139139
fInfo.virtualPath = `${group.name}/${source.file.name}`.replace(`${VirtualSource.rootName}/`, '');
@@ -403,8 +403,8 @@ export abstract class CodeBuilder {
403403
outDir: File.ToLocalPath(outDir),
404404
ram: memMaxSize?.ram,
405405
rom: memMaxSize?.rom,
406-
incDirs: this.getIncludeDirs().map((incPath) => { return this.project.ToRelativePath(incPath, false) || incPath; }),
407-
libDirs: this.getLibDirs().map((libPath) => { return this.project.ToRelativePath(libPath, false) || libPath; }),
406+
incDirs: this.getIncludeDirs().map((incPath) => { return this.project.ToRelativePath(incPath) || incPath; }),
407+
libDirs: this.getLibDirs().map((libPath) => { return this.project.ToRelativePath(libPath) || libPath; }),
408408
defines: this.getDefineList(),
409409
sourceList: sourceInfo.sources.sort(),
410410
sourceParams: sourceInfo.params,

src/EIDEProject.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class SourceRootList implements SourceProvider {
553553
}
554554

555555
private getRelativePath(abspath: string): string {
556-
return this.project.ToRelativePath(abspath, false) || abspath;
556+
return this.project.ToRelativePath(abspath) || abspath;
557557
}
558558

559559
private newSourceInfo(displayName: string, watcher: FileWatcher): SourceRootInfo {
@@ -599,7 +599,7 @@ class SourceRootList implements SourceProvider {
599599

600600
// exclude some root folder when add files to custom include paths
601601
const disableInclude: boolean = AbstractProject.excludeIncSearchList.includes(
602-
this.project.ToRelativePath(rootFolder.path, false) || rootFolder.path
602+
this.project.ToRelativePath(rootFolder.path) || rootFolder.path
603603
);
604604

605605
const sourceFilter = this.isAutoSearchObjFile ?
@@ -1089,9 +1089,9 @@ export abstract class AbstractProject implements CustomConfigurationProvider {
10891089
* Relative path root folder: `<Project_Root_Folder>`
10901090
*
10911091
* @param path absolute path
1092-
* @param hasPrefix Whether add a './' prefix before relative path, default is 'true'
1092+
*
10931093
*/
1094-
ToRelativePath(path: string, hasPrefix: boolean = true): string | undefined {
1094+
ToRelativePath(path: string): string | undefined {
10951095
return this.GetRootDir().ToRelativePath(path.trim());
10961096
}
10971097

@@ -2073,7 +2073,7 @@ class EIDEProject extends AbstractProject {
20732073

20742074
// filesystem files
20752075
if (typeof this.srcExtraCompilerConfig?.files == 'object') {
2076-
matcher(this.srcExtraCompilerConfig?.files, this.ToRelativePath(srcPath, false) || srcPath);
2076+
matcher(this.srcExtraCompilerConfig?.files, this.ToRelativePath(srcPath) || srcPath);
20772077
}
20782078

20792079
// virtual files
@@ -2279,7 +2279,7 @@ class EIDEProject extends AbstractProject {
22792279
// is filesystem source
22802280
if (!AbstractProject.isVirtualSourceGroup(_group)) {
22812281
const group = <ProjectFileGroup>_group;
2282-
const rePath = this.ToRelativePath(group.dir.path, false);
2282+
const rePath = this.ToRelativePath(group.dir.path);
22832283
// combine HAL folder
22842284
if (rePath && rePath.startsWith(DependenceManager.DEPENDENCE_DIR)) {
22852285
halFiles = halFiles.concat(group.files);

src/EIDEProjectExplorer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
14591459
nPrjConfig.outDir = 'build';
14601460
nPrjConfig.srcDirs = File.NotMatchFilter(ePrjRoot.GetList(File.EMPTY_FILTER), File.EMPTY_FILTER,
14611461
[/^\./, /^(build|dist|out|bin|obj|exe|debug|release|log[s]?|ipch|docs|doc|img|image[s]?)$/i])
1462-
.map(d => ePrjRoot.ToRelativePath(d.path, false) || d.path);
1462+
.map(d => ePrjRoot.ToRelativePath(d.path) || d.path);
14631463

14641464
// init all target
14651465
for (const eTarget of ePrjInfo.targets) {
@@ -1835,7 +1835,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
18351835
if (!srcFile.IsFile()) { continue; }
18361836
if (dep.category == 'source' && !vFolder) { continue; }
18371837

1838-
let srcRePath: string | undefined = baseInfo.rootFolder.ToRelativePath(srcFile.path, false);
1838+
let srcRePath: string | undefined = baseInfo.rootFolder.ToRelativePath(srcFile.path);
18391839

18401840
/* if it's not in workspace, copy it */
18411841
if (srcRePath == undefined) {
@@ -1887,7 +1887,7 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem> {
18871887
let locate = dep.packPath;
18881888
if (dep.instance) {
18891889
locate = baseInfo.rootFolder
1890-
.ToRelativePath(dep.instance[0], false) || dep.instance[0]
1890+
.ToRelativePath(dep.instance[0]) || dep.instance[0]
18911891
}
18921892

18931893
const nLine: string[] = [
@@ -3328,7 +3328,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
33283328
for (const folderUri of folderList) {
33293329

33303330
const folderPath = folderUri.fsPath;
3331-
const rePath = prj.ToRelativePath(folderPath, false);
3331+
const rePath = prj.ToRelativePath(folderPath);
33323332

33333333
// if can't calculate repath, skip
33343334
if (rePath === undefined || rePath.trim() === '') {
@@ -3841,7 +3841,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
38413841
if (source.disabled) continue;
38423842
// skip non-source and asm file
38433843
if (!srcFilter.test(source.file.path)) continue;
3844-
const rePath = confRootDir.ToRelativePath(source.file.path, false);
3844+
const rePath = confRootDir.ToRelativePath(source.file.path);
38453845
srcList.push(rePath || source.file.path);
38463846
}
38473847
}
@@ -4388,7 +4388,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
43884388
if (uris && uris.length > 0) {
43894389
const dupLi = prj
43904390
.addIncludePaths(uris.map(uri => { return uri.fsPath; }))
4391-
.map(path => prj.ToRelativePath(path, false) || path);
4391+
.map(path => prj.ToRelativePath(path) || path);
43924392
if (dupLi.length > 0) {
43934393
const msg = `${dupLi.length} redundant include paths (ignored): ${JSON.stringify(dupLi)}`;
43944394
GlobalEvent.emit('msg', newMessage('Warning', msg));
@@ -4445,14 +4445,14 @@ export class ProjectExplorer implements CustomConfigurationProvider {
44454445
prj.GetConfiguration().getAllDepGroup().forEach((group) => {
44464446
for (const dep of group.depList) {
44474447
for (const incPath of dep.incList) {
4448-
includesMap.set(prj.ToRelativePath(incPath, false) || incPath, group.groupName);
4448+
includesMap.set(prj.ToRelativePath(incPath) || incPath, group.groupName);
44494449
}
44504450
}
44514451
});
44524452

44534453
// add source include paths
44544454
prj.getSourceIncludeList().forEach((incPath) => {
4455-
includesMap.set(prj.ToRelativePath(incPath, false) || incPath, 'source');
4455+
includesMap.set(prj.ToRelativePath(incPath) || incPath, 'source');
44564456
});
44574457

44584458
for (const keyVal of includesMap) {
@@ -4489,7 +4489,7 @@ export class ProjectExplorer implements CustomConfigurationProvider {
44894489
prj.GetConfiguration().getAllDepGroup().forEach((group) => {
44904490
for (const dep of group.depList) {
44914491
for (const libPath of dep.libList) {
4492-
libMaps.set(prj.ToRelativePath(libPath, false) || libPath, group.groupName);
4492+
libMaps.set(prj.ToRelativePath(libPath) || libPath, group.groupName);
44934493
}
44944494
}
44954495
});

src/EIDETypeDefine.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ export class ProjectConfiguration<T extends BuilderConfigData>
13411341
let defCfg = <any>this.GetDefault(this.config.type);
13421342
let curCfg = <any>this.config;
13431343
for (const key in defCfg) {
1344-
if (curCfg[key] == undefined &&
1344+
if (curCfg[key] == undefined &&
13451345
this.excludeKeysInFile.includes(key) == false) {
13461346
curCfg[key] = defCfg[key];
13471347
}
@@ -1409,7 +1409,7 @@ export class ProjectConfiguration<T extends BuilderConfigData>
14091409
}
14101410
}
14111411

1412-
return utility.ToJsonStringExclude(eidePrjObj, excludeKeysInFile, 2);
1412+
return utility.ToJsonStringExclude(eidePrjObj, this.excludeKeysInFile, 2);
14131413
}
14141414

14151415
Save(force?: boolean) {
@@ -3602,7 +3602,7 @@ class OpenOCDUploadModel extends UploadConfigModel<OpenOCDFlashOptions> {
36023602
const cfgFolder = File.fromArray([wsFolder.path, path]);
36033603
if (cfgFolder.IsDir()) {
36043604
cfgFolder.GetList([/\.cfg$/i], File.EMPTY_FILTER).forEach((file) => {
3605-
const rePath = (wsFolder.ToRelativePath(file.path, false) || file.name);
3605+
const rePath = (wsFolder.ToRelativePath(file.path) || file.name);
36063606
resultList.push({
36073607
name: File.ToUnixPath(rePath).replace('.cfg', ''),
36083608
isInWorkspace: true
@@ -3617,7 +3617,7 @@ class OpenOCDUploadModel extends UploadConfigModel<OpenOCDFlashOptions> {
36173617
const cfgFolder = new File(NodePath.normalize(`${NodePath.dirname(openocdExe.dir)}/${path}/${configClass}`));
36183618
if (cfgFolder.IsDir()) {
36193619
cfgFolder.GetAll([/\.cfg$/i], File.EMPTY_FILTER).forEach((file) => {
3620-
const rePath = (cfgFolder.ToRelativePath(file.path, false) || file.name);
3620+
const rePath = (cfgFolder.ToRelativePath(file.path) || file.name);
36213621
resultList.push({
36223622
name: File.ToUnixPath(rePath).replace('.cfg', '')
36233623
});

0 commit comments

Comments
 (0)