Skip to content

Commit

Permalink
Allow merge of C_Cpp_Properties & configuration provider.
Browse files Browse the repository at this point in the history
Adds a configuration that enables the include paths, defines, and forced
includes from `c_cpp_properties.json` to be merged with those provided
by a configuration provider.

This is especially helpful for projects that use unsupported compilers
as defines/includePaths/forcedIncludes can be provided as shims for
intellisense.
  • Loading branch information
willson556 committed Sep 19, 2021
1 parent 0e3dd7a commit c6f97a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
"description": "The id of a VS Code extension that can provide IntelliSense configuration information for source files.",
"type": "string"
},
"mergeConfigurations": {
"description": "Set to `true` to merge include paths, defines, and forced includes with those from a configuration provider.",
"type": "boolean"
},
"browse": {
"type": "object",
"properties": {
Expand Down
31 changes: 29 additions & 2 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1797,9 +1797,36 @@ 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 ?? false) {
configs.forEach(config => {
fileConfiguration?.includePath?.forEach(p => {
if (!config.configuration.includePath.includes(p)) {
config.configuration.includePath.push(p);
}
});

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

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

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

return configs as SourceFileConfigurationItem[];
}
}
if (tokenSource.token.isCancellationRequested) {
Expand Down
1 change: 1 addition & 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

0 comments on commit c6f97a0

Please sign in to comment.