Skip to content

Commit 69b476b

Browse files
committed
fix: can not calcu 'inheritedArgs' for extra options
1 parent 8710c33 commit 69b476b

2 files changed

Lines changed: 74 additions & 27 deletions

File tree

src/EIDEProject.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,12 +1975,12 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
19751975
return false;
19761976
}
19771977

1978-
getExtraArgsForSource(fspath: string, virtpath?: string, cfg?: SourceExtraCompilerOptionsCfg): string[] | undefined {
1978+
getExtraArgsForSource(fspath: string, virtpath?: string, cfg?: SourceExtraCompilerOptionsCfg): { [expr: string]: string | undefined } {
19791979

19801980
if (cfg == undefined)
1981-
return undefined;
1981+
return {};
19821982

1983-
const extraArgs: string[] = [];
1983+
const extraArgs: { [expr: string]: string } = {};
19841984

19851985
// for fs path
19861986
if (cfg.files) {
@@ -1992,7 +1992,11 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
19921992
if (globmatch.isMatch(searchPath, expr)) {
19931993
const val = patterns[expr]?.replace(/\r\n|\n/g, ' ').replace(/\\r|\\n|\\t/g, ' ').trim();
19941994
if (val) {
1995-
extraArgs.push(val);
1995+
if (extraArgs[expr]) {
1996+
extraArgs[expr] = extraArgs[expr] + ' ' + val;
1997+
} else {
1998+
extraArgs[expr] = val;
1999+
}
19962000
}
19972001
}
19982002
}
@@ -2005,28 +2009,40 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
20052009
if (globmatch.isMatch(searchPath, expr)) {
20062010
const val = patterns[expr]?.replace(/\r\n|\n/g, ' ').replace(/\\r|\\n|\\t/g, ' ').trim();
20072011
if (val) {
2008-
extraArgs.push(val);
2012+
if (extraArgs[expr]) {
2013+
extraArgs[expr] = extraArgs[expr] + ' ' + val;
2014+
} else {
2015+
extraArgs[expr] = val;
2016+
}
20092017
}
20102018
}
20112019
}
20122020
}
20132021

2014-
return extraArgs.length > 0 ? extraArgs : undefined;
2022+
return extraArgs;
20152023
}
20162024

2017-
getExtraArgsForFolder(folderpath: string, isVirtpath?: boolean, cfg?: SourceExtraCompilerOptionsCfg): string[] | undefined {
2025+
getExtraArgsForFolder(folderpath: string, isVirtpath?: boolean, cfg?: SourceExtraCompilerOptionsCfg): { [expr: string]: string | undefined } {
20182026

20192027
if (cfg == undefined)
2020-
return undefined;
2028+
return {};
20212029

2022-
const extraArgs: string[] = [];
2030+
const extraArgs: { [expr: string]: string | undefined } = {};
2031+
2032+
this._matchExtraArgsForFolder(folderpath, isVirtpath, cfg, (expr, path, val) => {
2033+
2034+
if (val) {
2035+
if (extraArgs[expr]) {
2036+
extraArgs[expr] = extraArgs[expr] + ' ' + val;
2037+
} else {
2038+
extraArgs[expr] = val;
2039+
}
2040+
}
20232041

2024-
this._matchExtraArgsForFolder(folderpath, isVirtpath, cfg, (expr, path, args) => {
2025-
extraArgs.push(args);
20262042
return false;
20272043
});
20282044

2029-
return extraArgs.length > 0 ? extraArgs : undefined;
2045+
return extraArgs;
20302046
}
20312047

20322048
private _matchExtraArgsForFolder(
@@ -2611,7 +2627,18 @@ class EIDEProject extends AbstractProject {
26112627
}
26122628

26132629
private getExtraCompilerOptionsBySrcFile(srcPath: string, vPath?: string): string[] | undefined {
2614-
return this.getExtraArgsForSource(srcPath, vPath, this.getSourceExtraArgsCfg());
2630+
2631+
const allArgs = this.getExtraArgsForSource(srcPath, vPath, this.getSourceExtraArgsCfg());
2632+
if (!allArgs)
2633+
return undefined;
2634+
2635+
const argsList: string[] = [];
2636+
2637+
for (const expr in allArgs) {
2638+
argsList.push(allArgs[expr] || '');
2639+
}
2640+
2641+
return argsList;
26152642
}
26162643

26172644
//////////////////////////////// source refs ///////////////////////////////////

src/EIDEProjectExplorer.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,23 +4788,33 @@ export class ProjectExplorer implements CustomConfigurationProvider {
47884788
if (!extraArgs)
47894789
return;
47904790

4791-
const ccArgs = project.getExtraArgsForSource(fspath, virtpath, extraArgs)?.join(' ').trim() || '';
4791+
const argsMap = project.getExtraArgsForSource(fspath, virtpath, extraArgs);
47924792
const absPattern = project.getExtraArgsAbsPatternForSource(fspath, virtpath, extraArgs);
4793-
const isInherited = ccArgs && !absPattern;
4793+
const ccOptions = absPattern ? (argsMap[absPattern] || '') : '';
4794+
4795+
// merge all inherited args
4796+
let inheritedArgs: string = '';
4797+
for (const key in argsMap) {
4798+
const val = argsMap[key]?.trim();
4799+
if (key != absPattern && val) {
4800+
inheritedArgs = `${inheritedArgs} ${val}`;
4801+
}
4802+
}
4803+
inheritedArgs = inheritedArgs.trim();
47944804

47954805
const ui_cfg: SimpleUIConfig = {
47964806
title: 'Extra Compiler Options',
47974807
items: {},
47984808
};
47994809

4800-
if (isInherited) { // 继承于其他匹配模式
4810+
if (inheritedArgs) { // 继承于其他匹配模式
48014811
ui_cfg.items['inherit'] = {
48024812
type: 'input',
48034813
attrs: { readonly: true },
48044814
name: `Inherited Options (from other pattern, check your '*.files.options.yml' file for details !)`,
48054815
data: <SimpleUIConfigData_input>{
4806-
value: ccArgs,
4807-
default: ccArgs
4816+
value: inheritedArgs,
4817+
default: inheritedArgs
48084818
}
48094819
};
48104820
}
@@ -4815,8 +4825,8 @@ export class ProjectExplorer implements CustomConfigurationProvider {
48154825
name: 'Compiler Options',
48164826
data: <SimpleUIConfigData_input>{
48174827
placeHolder: `compiler options, like: '-O1', '-Os', '-flto' ...`,
4818-
value: isInherited ? '' : ccArgs,
4819-
default: isInherited ? '' : ccArgs,
4828+
value: ccOptions,
4829+
default: ccOptions,
48204830
},
48214831
};
48224832

@@ -4884,23 +4894,33 @@ export class ProjectExplorer implements CustomConfigurationProvider {
48844894
if (!extraArgs)
48854895
return;
48864896

4887-
const ccArgs = project.getExtraArgsForFolder(folderpath, isVirtpath, extraArgs)?.join(' ').trim() || '';
4897+
const argsMap = project.getExtraArgsForFolder(folderpath, isVirtpath, extraArgs);
48884898
const absPattern = project.getExtraArgsAbsPatternForFolder(folderpath, isVirtpath, extraArgs);
4889-
const isInherited = ccArgs && !absPattern;
4899+
const ccOptions = absPattern ? (argsMap[absPattern] || '') : '';
4900+
4901+
// merge all inherited args
4902+
let inheritedOptions: string = '';
4903+
for (const key in argsMap) {
4904+
const val = argsMap[key]?.trim();
4905+
if (key != absPattern && val) {
4906+
inheritedOptions = `${inheritedOptions} ${val}`;
4907+
}
4908+
}
4909+
inheritedOptions = inheritedOptions.trim();
48904910

48914911
const ui_cfg: SimpleUIConfig = {
48924912
title: 'Extra Compiler Options',
48934913
items: {},
48944914
};
48954915

4896-
if (isInherited) { // 继承于其他匹配模式
4916+
if (inheritedOptions) { // 继承于其他匹配模式
48974917
ui_cfg.items['inherit'] = {
48984918
type: 'input',
48994919
attrs: { readonly: true },
49004920
name: `Inherited Options (from other args pattern, check your '*.files.options.yml' file for details !)`,
49014921
data: <SimpleUIConfigData_input>{
4902-
value: ccArgs,
4903-
default: ccArgs
4922+
value: inheritedOptions,
4923+
default: inheritedOptions
49044924
}
49054925
};
49064926
}
@@ -4911,8 +4931,8 @@ export class ProjectExplorer implements CustomConfigurationProvider {
49114931
name: 'Compiler Options',
49124932
data: <SimpleUIConfigData_input>{
49134933
placeHolder: `compiler options, like: '-O1', '-Os', '-flto' ...`,
4914-
value: isInherited ? '' : ccArgs,
4915-
default: isInherited ? '' : ccArgs,
4934+
value: ccOptions,
4935+
default: ccOptions,
49164936
},
49174937
};
49184938

0 commit comments

Comments
 (0)