Skip to content

Commit 2bff033

Browse files
authored
Handle multiple compile commands on client side (needs native server side support) (#12960)
1 parent 0aaae1f commit 2bff033

File tree

8 files changed

+150
-59
lines changed

8 files changed

+150
-59
lines changed

Extension/c_cpp_properties.schema.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,20 @@
7070
]
7171
},
7272
"compileCommands": {
73-
"markdownDescription": "Full path to `compile_commands.json` file for the workspace.",
74-
"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.",
75-
"type": "string"
73+
"oneOf": [
74+
{
75+
"type": "string"
76+
},
77+
{
78+
"type": "array",
79+
"items": {
80+
"type": "string"
81+
},
82+
"uniqueItems": true
83+
}
84+
],
85+
"markdownDescription": "Full path or a list of full paths to `compile_commands.json` files for the workspace.",
86+
"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."
7687
},
7788
"includePath": {
7889
"markdownDescription": "A list of paths for the IntelliSense engine to use while searching for included headers. Searching on these paths is not recursive. Specify `**` to indicate recursive search. For example, `${workspaceFolder}/**` will search through all subdirectories while `${workspaceFolder}` will not. Usually, this should not include system includes; instead, set `C_Cpp.default.compilerPath`.",
@@ -239,7 +250,6 @@
239250
},
240251
"enableConfigurationSquiggles": {
241252
"type": "boolean",
242-
"default": true,
243253
"markdownDescription": "Controls whether the extension will report errors detected in `c_cpp_properties.json`.",
244254
"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."
245255
}

Extension/package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,23 @@
693693
"scope": "machine-overridable"
694694
},
695695
"C_Cpp.default.compileCommands": {
696-
"type": "string",
696+
"oneOf": [
697+
{
698+
"type": "string",
699+
"default": ""
700+
},
701+
{
702+
"type": "array",
703+
"items": {
704+
"type": "string"
705+
},
706+
"uniqueItems": true,
707+
"default": []
708+
}
709+
],
710+
"default": [
711+
""
712+
],
697713
"markdownDescription": "%c_cpp.configuration.default.compileCommands.markdownDescription%",
698714
"scope": "machine-overridable"
699715
},

Extension/src/LanguageServer/configurations.ts

Lines changed: 95 additions & 46 deletions
Large diffs are not rendered by default.

Extension/src/LanguageServer/settings.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,17 @@ export class CppSettings extends Settings {
402402
public get defaultDotconfig(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.dotConfig")); }
403403
public get defaultMacFrameworkPath(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.macFrameworkPath"); }
404404
public get defaultWindowsSdkVersion(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.windowsSdkVersion")); }
405-
public get defaultCompileCommands(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.compileCommands")); }
405+
public get defaultCompileCommands(): string[] | undefined {
406+
const value: any = super.Section.get<any>("default.compileCommands");
407+
if (isString(value)) {
408+
return value.length > 0 ? [value] : undefined;
409+
}
410+
if (isArrayOfString(value)) {
411+
const result = value.filter(x => x.length > 0);
412+
return result.length > 0 ? result : undefined;
413+
}
414+
return undefined;
415+
}
406416
public get defaultForcedInclude(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.forcedInclude"); }
407417
public get defaultIntelliSenseMode(): string | undefined { return this.getAsStringOrUndefined("default.intelliSenseMode"); }
408418
public get defaultCompilerPath(): string | null { return this.getAsString("default.compilerPath", true); }
@@ -652,7 +662,7 @@ export class CppSettings extends Settings {
652662
}
653663

654664
if (isArrayOfString(value)) {
655-
if (setting.items.enum && !allowUndefinedEnums) {
665+
if (setting.items?.enum !== undefined && !allowUndefinedEnums) {
656666
if (!value.every(x => this.isValidEnum(setting.items.enum, x))) {
657667
return setting.default;
658668
}

Extension/src/LanguageServer/settingsPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class SettingsPanel {
337337
this.configValues.macFrameworkPath = splitEntries(message.value);
338338
break;
339339
case elementId.compileCommands:
340-
this.configValues.compileCommands = message.value || undefined;
340+
this.configValues.compileCommands = splitEntries(message.value);
341341
break;
342342
case elementId.dotConfig:
343343
this.configValues.dotConfig = message.value || undefined;

Extension/src/LanguageServer/settingsTracker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ export class SettingsTracker {
108108
return "<invalid>";
109109
}
110110
return val;
111+
} else if (curSetting["oneOf"]) {
112+
// Currently only C_Cpp.default.compileCommands uses this case.
113+
if (curSetting["oneOf"].some((x: any) => this.typeMatch(val, x.type))) {
114+
return val;
115+
}
111116
} else if (val === curSetting["default"]) {
112117
// C_Cpp.default.browse.path is a special case where the default value is null and doesn't match the type definition.
113118
return val;
@@ -206,7 +211,7 @@ export class SettingsTracker {
206211
if (value && value.length > maxSettingLengthForTelemetry) {
207212
value = value.substring(0, maxSettingLengthForTelemetry) + "...";
208213
}
209-
return {key: key, value: value};
214+
return { key: key, value: value };
210215
}
211216
return undefined;
212217
}

Extension/ui/settings.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,12 @@
672672
<div class="section">
673673
<div class="section-title" data-loc-id="compile.commands">Compile commands</div>
674674
<div class="section-text">
675-
<span data-loc-id="compile.commands.description">The full path to the <code>compile_commands.json</code> file for the workspace. The include paths and defines discovered in this file will be used instead of the values set for <code>includePath</code> and <code>defines</code> settings. If the compile commands database does not contain an entry for the translation unit that corresponds to the file you opened in the editor, then a warning message will appear and the extension will use the <code>includePath</code> and <code>defines</code> settings instead.</span>
675+
<span data-loc-id="compile.commands.description">A list of paths to <code>compile_commands.json</code> files for the workspace. The include paths and defines discovered in these files will be used instead of the values set for <code>includePath</code> and <code>defines</code> settings. If the compile commands database does not contain an entry for the translation unit that corresponds to the file you opened in the editor, then a warning message will appear and the extension will use the <code>includePath</code> and <code>defines</code> settings instead.</span>
676676
</div>
677677
<div>
678-
<input name="inputValue" id="compileCommands" style="width: 798px"></input>
679-
<div id="compileCommandsInvalid" class="error" style="width: 800px"></div>
678+
<div class="section-note" data-loc-id="one.compile.commands.path.per.line">One compile commands path per line.</div>
679+
<textarea name="inputValue" id="compileCommands" rows="4" cols="93" style="width: 800px"></textarea>
680+
<div id="compileCommandsInvalid" class="error" style="margin-top: -4px; width: 794px"></div>
680681
</div>
681682
</div>
682683

Extension/ui/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class SettingsApp {
295295
// Advanced settings
296296
(<HTMLInputElement>document.getElementById(elementId.windowsSdkVersion)).value = config.windowsSdkVersion ? config.windowsSdkVersion : "";
297297
(<HTMLInputElement>document.getElementById(elementId.macFrameworkPath)).value = joinEntries(config.macFrameworkPath);
298-
(<HTMLInputElement>document.getElementById(elementId.compileCommands)).value = config.compileCommands ? config.compileCommands : "";
298+
(<HTMLInputElement>document.getElementById(elementId.compileCommands)).value = joinEntries(config.compileCommands);
299299
(<HTMLInputElement>document.getElementById(elementId.mergeConfigurations)).checked = config.mergeConfigurations;
300300
(<HTMLInputElement>document.getElementById(elementId.configurationProvider)).value = config.configurationProvider ? config.configurationProvider : "";
301301
(<HTMLInputElement>document.getElementById(elementId.forcedInclude)).value = joinEntries(config.forcedInclude);

0 commit comments

Comments
 (0)