Skip to content

Commit a62acdb

Browse files
authored
Allow merge of C_Cpp_Properties & configuration provider. (#8174)
* Allow merge of C_Cpp_Properties & configuration provider.
1 parent cd949b9 commit a62acdb

File tree

9 files changed

+80
-3
lines changed

9 files changed

+80
-3
lines changed

Extension/c_cpp_properties.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
"description": "The id of a VS Code extension that can provide IntelliSense configuration information for source files.",
156156
"type": "string"
157157
},
158+
"mergeConfigurations": {
159+
"markdownDescription": "Set to `true` to merge include paths, defines, and forced includes with those from a configuration provider.",
160+
"descriptionHint": "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered.",
161+
"type": "boolean"
162+
},
158163
"browse": {
159164
"type": "object",
160165
"properties": {

Extension/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,11 @@
11461146
"markdownDescription": "%c_cpp.configuration.default.configurationProvider.markdownDescription%",
11471147
"scope": "resource"
11481148
},
1149+
"C_Cpp.default.mergeConfigurations": {
1150+
"type": "boolean",
1151+
"markdownDescription": "%c_cpp.configuration.default.mergeConfigurations.markdownDescription%",
1152+
"scope": "resource"
1153+
},
11491154
"C_Cpp.default.browse.path": {
11501155
"type": "array",
11511156
"items": {

Extension/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
"c_cpp.configuration.default.cStandard.markdownDescription": { "message": "The value to use in a configuration if `cStandard` is either not specified or set to `${default}`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
160160
"c_cpp.configuration.default.cppStandard.markdownDescription": { "message": "The value to use in a configuration if `cppStandard` is either not specified or set to `${default}`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
161161
"c_cpp.configuration.default.configurationProvider.markdownDescription": { "message": "The value to use in a configuration if `configurationProvider` is either not specified or set to `${default}`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
162+
"c_cpp.configuration.default.mergeConfigurations.markdownDescription": { "message": "Set to `true` to merge include paths, defines, and forced includes with those from a configuration provider.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
162163
"c_cpp.configuration.default.browse.path.markdownDescription": { "message": "The value to use in a configuration if `browse.path` is not specified, or the values to insert if `${default}` is present in `browse.path`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
163164
"c_cpp.configuration.default.browse.databaseFilename.markdownDescription": { "message": "The value to use in a configuration if `browse.databaseFilename` is either not specified or set to `${default}`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
164165
"c_cpp.configuration.default.browse.limitSymbolsToIncludedHeaders.markdownDescription": { "message": "The value to use in a configuration if `browse.limitSymbolsToIncludedHeaders` is either not specified or set to `${default}`.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },

Extension/src/LanguageServer/client.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,9 +1797,44 @@ export class DefaultClient implements Client {
17971797
const candidate: string = response.candidates[i];
17981798
const tuUri: vscode.Uri = vscode.Uri.parse(candidate);
17991799
if (await provider.canProvideConfiguration(tuUri, tokenSource.token)) {
1800-
const configs: SourceFileConfigurationItem[] = await provider.provideConfigurations([tuUri], tokenSource.token);
1800+
const configs: util.Mutable<SourceFileConfigurationItem>[] = await provider.provideConfigurations([tuUri], tokenSource.token);
18011801
if (configs && configs.length > 0 && configs[0]) {
1802-
return configs;
1802+
const fileConfiguration: configs.Configuration | undefined = this.configuration.CurrentConfiguration;
1803+
if (fileConfiguration?.mergeConfigurations) {
1804+
configs.forEach(config => {
1805+
if (fileConfiguration.includePath) {
1806+
fileConfiguration.includePath.forEach(p => {
1807+
if (!config.configuration.includePath.includes(p)) {
1808+
config.configuration.includePath.push(p);
1809+
}
1810+
});
1811+
}
1812+
1813+
if (fileConfiguration.defines) {
1814+
fileConfiguration.defines.forEach(d => {
1815+
if (!config.configuration.defines.includes(d)) {
1816+
config.configuration.defines.push(d);
1817+
}
1818+
});
1819+
}
1820+
1821+
if (!config.configuration.forcedInclude) {
1822+
config.configuration.forcedInclude = [];
1823+
}
1824+
1825+
if (fileConfiguration.forcedInclude) {
1826+
fileConfiguration.forcedInclude.forEach(i => {
1827+
if (config.configuration.forcedInclude) {
1828+
if (!config.configuration.forcedInclude.includes(i)) {
1829+
config.configuration.forcedInclude.push(i);
1830+
}
1831+
}
1832+
});
1833+
}
1834+
});
1835+
}
1836+
1837+
return configs as SourceFileConfigurationItem[];
18031838
}
18041839
}
18051840
if (tokenSource.token.isCancellationRequested) {

Extension/src/LanguageServer/configurations.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface Configuration {
7373
compileCommands?: string;
7474
forcedInclude?: string[];
7575
configurationProvider?: string;
76+
mergeConfigurations?: boolean;
7677
browse?: Browse;
7778
customConfigurationVariables?: {[key: string]: string};
7879
}
@@ -741,6 +742,18 @@ export class CppProperties {
741742
return util.resolveVariables(property, env);
742743
}
743744

745+
private updateConfigurationBoolean(property: boolean | undefined | null, defaultValue: boolean | undefined | null): boolean | undefined {
746+
if (property === null || property === undefined) {
747+
property = defaultValue;
748+
}
749+
750+
if (property === null) {
751+
return undefined;
752+
}
753+
754+
return property;
755+
}
756+
744757
private updateConfigurationStringDictionary(property: { [key: string]: string } | undefined, defaultValue: { [key: string]: string } | undefined, env: Environment): { [key: string]: string } | undefined {
745758
if (!property || property === {}) {
746759
property = defaultValue;
@@ -780,6 +793,7 @@ export class CppProperties {
780793
configuration.intelliSenseModeIsExplicit = configuration.intelliSenseModeIsExplicit || settings.defaultIntelliSenseMode !== "";
781794
configuration.cStandardIsExplicit = configuration.cStandardIsExplicit || settings.defaultCStandard !== "";
782795
configuration.cppStandardIsExplicit = configuration.cppStandardIsExplicit || settings.defaultCppStandard !== "";
796+
configuration.mergeConfigurations = this.updateConfigurationBoolean(configuration.mergeConfigurations, settings.defaultMergeConfigurations);
783797
if (!configuration.compileCommands) {
784798
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
785799
// don't set a default when compileCommands is in use.

Extension/src/LanguageServer/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export class CppSettings extends Settings {
160160
public get defaultCStandard(): string | undefined { return super.Section.get<string>("default.cStandard"); }
161161
public get defaultCppStandard(): string | undefined { return super.Section.get<string>("default.cppStandard"); }
162162
public get defaultConfigurationProvider(): string | undefined { return super.Section.get<string>("default.configurationProvider"); }
163+
public get defaultMergeConfigurations(): boolean | undefined { return super.Section.get<boolean>("default.mergeConfigurations"); }
163164
public get defaultBrowsePath(): string[] | undefined { return super.Section.get<string[] | null>("default.browse.path") ?? undefined; }
164165
public get defaultDatabaseFilename(): string | undefined { return super.Section.get<string>("default.browse.databaseFilename"); }
165166
public get defaultLimitSymbolsToIncludedHeaders(): boolean | undefined { return super.Section.get<boolean>("default.browse.limitSymbolsToIncludedHeaders"); }

Extension/src/LanguageServer/settingsPanel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const elementId: { [key: string]: string } = {
3939
windowsSdkVersion: "windowsSdkVersion",
4040
macFrameworkPath: "macFrameworkPath",
4141
compileCommands: "compileCommands",
42+
mergeConfigurations: "mergeConfigurations",
4243
configurationProvider: "configurationProvider",
4344
forcedInclude: "forcedInclude",
4445

@@ -325,6 +326,9 @@ export class SettingsPanel {
325326
case elementId.compileCommands:
326327
this.configValues.compileCommands = message.value;
327328
break;
329+
case elementId.mergeConfigurations:
330+
this.configValues.mergeConfigurations = message.value;
331+
break;
328332
case elementId.configurationProvider:
329333
this.configValues.configurationProvider = message.value;
330334
break;

Extension/ui/settings.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@
667667
</div>
668668
</div>
669669

670+
<div class="section">
671+
<div class="section-title" data-loc-id="merge.configurations">Merge configurations</div>
672+
<div>
673+
<input type="checkbox" id="mergeConfigurations" style="vertical-align: middle; transform: scale(1.5)">
674+
<span data-loc-id="merge.configurations.description">When true (or checked), merge include paths, defines, and forced includes with those from a configuration provider.</span>
675+
</input>
676+
</div>
677+
</div>
678+
670679
<div class="section">
671680
<div class="section-title" data-loc-id="browse.path">Browse: path</div>
672681
<div class="section-text">

Extension/ui/settings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const elementId: { [key: string]: string } = {
3939
configurationProvider: "configurationProvider",
4040
forcedInclude: "forcedInclude",
4141
forcedIncludeInvalid: "forcedIncludeInvalid",
42+
mergeConfigurations: "mergeConfigurations",
4243

4344
// Browse properties
4445
browsePath: "browsePath",
@@ -92,8 +93,9 @@ class SettingsApp {
9293
el.addEventListener("change", this.onChanged.bind(this, el.id));
9394
});
9495

95-
// Special case for checkbox element
96+
// Special case for checkbox elements
9697
document.getElementById(elementId.limitSymbolsToIncludedHeaders).addEventListener("change", this.onChangedCheckbox.bind(this, elementId.limitSymbolsToIncludedHeaders));
98+
document.getElementById(elementId.mergeConfigurations).addEventListener("change", this.onChangedCheckbox.bind(this, elementId.mergeConfigurations));
9799
}
98100

99101
private addEventsToConfigNameChanges(): void {
@@ -268,6 +270,7 @@ class SettingsApp {
268270
(<HTMLInputElement>document.getElementById(elementId.windowsSdkVersion)).value = config.windowsSdkVersion ? config.windowsSdkVersion : "";
269271
(<HTMLInputElement>document.getElementById(elementId.macFrameworkPath)).value = joinEntries(config.macFrameworkPath);
270272
(<HTMLInputElement>document.getElementById(elementId.compileCommands)).value = config.compileCommands ? config.compileCommands : "";
273+
(<HTMLInputElement>document.getElementById(elementId.mergeConfigurations)).checked = config.mergeConfigurations;
271274
(<HTMLInputElement>document.getElementById(elementId.configurationProvider)).value = config.configurationProvider ? config.configurationProvider : "";
272275
(<HTMLInputElement>document.getElementById(elementId.forcedInclude)).value = joinEntries(config.forcedInclude);
273276

0 commit comments

Comments
 (0)