Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow merge of C_Cpp_Properties & configuration provider. #8174

Merged
5 changes: 5 additions & 0 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
"description": "The id of a VS Code extension that can provide IntelliSense configuration information for source files.",
"type": "string"
},
"mergeConfigurations": {
"markdownDescription": "Set to `true` to merge include paths, defines, and forced includes with those from a configuration provider.",
"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.",
"type": "boolean"
},
"browse": {
"type": "object",
"properties": {
Expand Down
5 changes: 5 additions & 0 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,11 @@
"markdownDescription": "%c_cpp.configuration.default.configurationProvider.markdownDescription%",
"scope": "resource"
},
"C_Cpp.default.mergeConfigurations": {
"type": "boolean",
"markdownDescription": "%c_cpp.configuration.default.mergeConfigurations.markdownDescription%",
"scope": "resource"
},
"C_Cpp.default.browse.path": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },
"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." ] },
Expand Down
39 changes: 37 additions & 2 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,9 +1797,44 @@ export class DefaultClient implements Client {
const candidate: string = response.candidates[i];
const tuUri: vscode.Uri = vscode.Uri.parse(candidate);
if (await provider.canProvideConfiguration(tuUri, tokenSource.token)) {
const configs: SourceFileConfigurationItem[] = await provider.provideConfigurations([tuUri], tokenSource.token);
const configs: util.Mutable<SourceFileConfigurationItem>[] = await provider.provideConfigurations([tuUri], tokenSource.token);
if (configs && configs.length > 0 && configs[0]) {
return configs;
const fileConfiguration: configs.Configuration | undefined = this.configuration.CurrentConfiguration;
if (fileConfiguration?.mergeConfigurations) {
configs.forEach(config => {
if (fileConfiguration.includePath) {
fileConfiguration.includePath.forEach(p => {
if (!config.configuration.includePath.includes(p)) {
config.configuration.includePath.push(p);
}
});
}

if (fileConfiguration.defines) {
fileConfiguration.defines.forEach(d => {
if (!config.configuration.defines.includes(d)) {
config.configuration.defines.push(d);
}
});
}

if (!config.configuration.forcedInclude) {
config.configuration.forcedInclude = [];
}

if (fileConfiguration.forcedInclude) {
fileConfiguration.forcedInclude.forEach(i => {
if (config.configuration.forcedInclude) {
if (!config.configuration.forcedInclude.includes(i)) {
config.configuration.forcedInclude.push(i);
}
}
});
}
});
}

return configs as SourceFileConfigurationItem[];
}
}
if (tokenSource.token.isCancellationRequested) {
Expand Down
14 changes: 14 additions & 0 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface Configuration {
compileCommands?: string;
forcedInclude?: string[];
configurationProvider?: string;
mergeConfigurations?: boolean;
browse?: Browse;
customConfigurationVariables?: {[key: string]: string};
}
Expand Down Expand Up @@ -741,6 +742,18 @@ export class CppProperties {
return util.resolveVariables(property, env);
}

private updateConfigurationBoolean(property: boolean | undefined | null, defaultValue: boolean | undefined | null): boolean | undefined {
if (property === null || property === undefined) {
property = defaultValue;
}

if (property === null) {
return undefined;
}

return property;
}

private updateConfigurationStringDictionary(property: { [key: string]: string } | undefined, defaultValue: { [key: string]: string } | undefined, env: Environment): { [key: string]: string } | undefined {
if (!property || property === {}) {
property = defaultValue;
Expand Down Expand Up @@ -780,6 +793,7 @@ export class CppProperties {
configuration.intelliSenseModeIsExplicit = configuration.intelliSenseModeIsExplicit || settings.defaultIntelliSenseMode !== "";
configuration.cStandardIsExplicit = configuration.cStandardIsExplicit || settings.defaultCStandard !== "";
configuration.cppStandardIsExplicit = configuration.cppStandardIsExplicit || settings.defaultCppStandard !== "";
configuration.mergeConfigurations = this.updateConfigurationBoolean(configuration.mergeConfigurations, settings.defaultMergeConfigurations);
if (!configuration.compileCommands) {
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
// don't set a default when compileCommands is in use.
Expand Down
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class CppSettings extends Settings {
public get defaultCStandard(): string | undefined { return super.Section.get<string>("default.cStandard"); }
public get defaultCppStandard(): string | undefined { return super.Section.get<string>("default.cppStandard"); }
public get defaultConfigurationProvider(): string | undefined { return super.Section.get<string>("default.configurationProvider"); }
public get defaultMergeConfigurations(): boolean | undefined { return super.Section.get<boolean>("default.mergeConfigurations"); }
public get defaultBrowsePath(): string[] | undefined { return super.Section.get<string[] | null>("default.browse.path") ?? undefined; }
public get defaultDatabaseFilename(): string | undefined { return super.Section.get<string>("default.browse.databaseFilename"); }
public get defaultLimitSymbolsToIncludedHeaders(): boolean | undefined { return super.Section.get<boolean>("default.browse.limitSymbolsToIncludedHeaders"); }
Expand Down
4 changes: 4 additions & 0 deletions Extension/src/LanguageServer/settingsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const elementId: { [key: string]: string } = {
windowsSdkVersion: "windowsSdkVersion",
macFrameworkPath: "macFrameworkPath",
compileCommands: "compileCommands",
mergeConfigurations: "mergeConfigurations",
configurationProvider: "configurationProvider",
forcedInclude: "forcedInclude",

Expand Down Expand Up @@ -325,6 +326,9 @@ export class SettingsPanel {
case elementId.compileCommands:
this.configValues.compileCommands = message.value;
break;
case elementId.mergeConfigurations:
this.configValues.mergeConfigurations = message.value;
break;
case elementId.configurationProvider:
this.configValues.configurationProvider = message.value;
break;
Expand Down
9 changes: 9 additions & 0 deletions Extension/ui/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,15 @@
</div>
</div>

<div class="section">
<div class="section-title" data-loc-id="merge.configurations">Merge configurations</div>
<div>
<input type="checkbox" id="mergeConfigurations" style="vertical-align: middle; transform: scale(1.5)">
<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>
</input>
</div>
</div>

<div class="section">
<div class="section-title" data-loc-id="browse.path">Browse: path</div>
<div class="section-text">
Expand Down
5 changes: 4 additions & 1 deletion Extension/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const elementId: { [key: string]: string } = {
configurationProvider: "configurationProvider",
forcedInclude: "forcedInclude",
forcedIncludeInvalid: "forcedIncludeInvalid",
mergeConfigurations: "mergeConfigurations",

// Browse properties
browsePath: "browsePath",
Expand Down Expand Up @@ -92,8 +93,9 @@ class SettingsApp {
el.addEventListener("change", this.onChanged.bind(this, el.id));
});

// Special case for checkbox element
// Special case for checkbox elements
document.getElementById(elementId.limitSymbolsToIncludedHeaders).addEventListener("change", this.onChangedCheckbox.bind(this, elementId.limitSymbolsToIncludedHeaders));
document.getElementById(elementId.mergeConfigurations).addEventListener("change", this.onChangedCheckbox.bind(this, elementId.mergeConfigurations));
}

private addEventsToConfigNameChanges(): void {
Expand Down Expand Up @@ -268,6 +270,7 @@ class SettingsApp {
(<HTMLInputElement>document.getElementById(elementId.windowsSdkVersion)).value = config.windowsSdkVersion ? config.windowsSdkVersion : "";
(<HTMLInputElement>document.getElementById(elementId.macFrameworkPath)).value = joinEntries(config.macFrameworkPath);
(<HTMLInputElement>document.getElementById(elementId.compileCommands)).value = config.compileCommands ? config.compileCommands : "";
(<HTMLInputElement>document.getElementById(elementId.mergeConfigurations)).checked = config.mergeConfigurations;
(<HTMLInputElement>document.getElementById(elementId.configurationProvider)).value = config.configurationProvider ? config.configurationProvider : "";
(<HTMLInputElement>document.getElementById(elementId.forcedInclude)).value = joinEntries(config.forcedInclude);

Expand Down