Skip to content

Commit 00f70ae

Browse files
authored
add support for force includes in c_cpp_properties.json (#1630)
1 parent bea033e commit 00f70ae

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

Extension/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Support additional multiline comment patterns. [#1100](https://github.com/Microsoft/vscode-cpptools/issues/1100),[#1539](https://github.com/Microsoft/vscode-cpptools/issues/1539)
66
* Added new setting: `C_Cpp.commentContinuationPatterns`
77
* Add a setting to disable inactive region highlighting. [#1592](https://github.com/Microsoft/vscode-cpptools/issues/1592)
8+
* Add support for forced includes. [#852](https://github.com/Microsoft/vscode-cpptools/issues/852)
89

910
## Version 0.15.0: February 15, 2018
1011
* Add colorization for inactive regions. [#1466](https://github.com/Microsoft/vscode-cpptools/issues/1466)

Extension/c_cpp_properties.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
],
4848
"description": "If set, it overrides the default mode used by the IntelliSense engine. Windows defaults to msvc-x64 and Linux/Mac default to clang-x64."
4949
},
50+
"forcedInclude": {
51+
"description": "A list of files that should be included before any include file in a translation unit.",
52+
"type": "array",
53+
"items": {
54+
"type": "string"
55+
}
56+
},
5057
"browse": {
5158
"type": "object",
5259
"properties": {

Extension/src/LanguageServer/configurations.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface Configuration {
9494
defines?: string[];
9595
intelliSenseMode?: string;
9696
compileCommands?: string;
97+
forcedInclude?: string[];
9798
browse?: Browse;
9899
}
99100

@@ -275,28 +276,33 @@ export class CppProperties {
275276
this.onSelectionChanged();
276277
}
277278

278-
private resolveAndSplit(paths: string[]): string[] {
279+
private resolveAndSplit(paths: string[] | undefined): string[] {
279280
let result: string[] = [];
280-
paths.forEach(entry => {
281-
let entries: string[] = util.resolveVariables(entry).split(";").filter(e => e);
282-
result = result.concat(entries);
283-
});
281+
if (paths) {
282+
paths.forEach(entry => {
283+
let entries: string[] = util.resolveVariables(entry).split(";").filter(e => e);
284+
result = result.concat(entries);
285+
});
286+
}
284287
return result;
285288
}
286289

287290
private updateServerOnFolderSettingsChange(): void {
288291
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
289292
let configuration: Configuration = this.configurationJson.configurations[i];
290-
if (configuration.includePath !== undefined) {
293+
if (configuration.includePath) {
291294
configuration.includePath = this.resolveAndSplit(configuration.includePath);
292295
}
293-
if (configuration.browse !== undefined && configuration.browse.path !== undefined) {
296+
if (configuration.browse) {
294297
configuration.browse.path = this.resolveAndSplit(configuration.browse.path);
295298
}
296-
if (configuration.macFrameworkPath !== undefined) {
299+
if (configuration.macFrameworkPath) {
297300
configuration.macFrameworkPath = this.resolveAndSplit(configuration.macFrameworkPath);
298301
}
299-
if (configuration.compileCommands !== undefined) {
302+
if (configuration.forcedInclude) {
303+
configuration.forcedInclude = this.resolveAndSplit(configuration.forcedInclude);
304+
}
305+
if (configuration.compileCommands) {
300306
configuration.compileCommands = util.resolveVariables(configuration.compileCommands);
301307
}
302308
}

Extension/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function showReleaseNotes(): void {
120120
}
121121

122122
export function resolveVariables(input: string): string {
123-
if (input === null) {
123+
if (!input) {
124124
return "";
125125
}
126126

0 commit comments

Comments
 (0)