Skip to content

Commit

Permalink
Handle multiple compile commands on client side (needs native server …
Browse files Browse the repository at this point in the history
…side support) (#12960)
  • Loading branch information
yiftahw authored Dec 30, 2024
1 parent 0aaae1f commit 2bff033
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 59 deletions.
18 changes: 14 additions & 4 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,20 @@
]
},
"compileCommands": {
"markdownDescription": "Full path to `compile_commands.json` file for the workspace.",
"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": "string"
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
],
"markdownDescription": "Full path or a list of full paths to `compile_commands.json` files for the workspace.",
"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."
},
"includePath": {
"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`.",
Expand Down Expand Up @@ -239,7 +250,6 @@
},
"enableConfigurationSquiggles": {
"type": "boolean",
"default": true,
"markdownDescription": "Controls whether the extension will report errors detected in `c_cpp_properties.json`.",
"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."
}
Expand Down
18 changes: 17 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,23 @@
"scope": "machine-overridable"
},
"C_Cpp.default.compileCommands": {
"type": "string",
"oneOf": [
{
"type": "string",
"default": ""
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
],
"default": [
""
],
"markdownDescription": "%c_cpp.configuration.default.compileCommands.markdownDescription%",
"scope": "machine-overridable"
},
Expand Down
141 changes: 95 additions & 46 deletions Extension/src/LanguageServer/configurations.ts

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,17 @@ export class CppSettings extends Settings {
public get defaultDotconfig(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.dotConfig")); }
public get defaultMacFrameworkPath(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.macFrameworkPath"); }
public get defaultWindowsSdkVersion(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.windowsSdkVersion")); }
public get defaultCompileCommands(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.compileCommands")); }
public get defaultCompileCommands(): string[] | undefined {
const value: any = super.Section.get<any>("default.compileCommands");
if (isString(value)) {
return value.length > 0 ? [value] : undefined;
}
if (isArrayOfString(value)) {
const result = value.filter(x => x.length > 0);
return result.length > 0 ? result : undefined;
}
return undefined;
}
public get defaultForcedInclude(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.forcedInclude"); }
public get defaultIntelliSenseMode(): string | undefined { return this.getAsStringOrUndefined("default.intelliSenseMode"); }
public get defaultCompilerPath(): string | null { return this.getAsString("default.compilerPath", true); }
Expand Down Expand Up @@ -652,7 +662,7 @@ export class CppSettings extends Settings {
}

if (isArrayOfString(value)) {
if (setting.items.enum && !allowUndefinedEnums) {
if (setting.items?.enum !== undefined && !allowUndefinedEnums) {
if (!value.every(x => this.isValidEnum(setting.items.enum, x))) {
return setting.default;
}
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/LanguageServer/settingsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class SettingsPanel {
this.configValues.macFrameworkPath = splitEntries(message.value);
break;
case elementId.compileCommands:
this.configValues.compileCommands = message.value || undefined;
this.configValues.compileCommands = splitEntries(message.value);
break;
case elementId.dotConfig:
this.configValues.dotConfig = message.value || undefined;
Expand Down
7 changes: 6 additions & 1 deletion Extension/src/LanguageServer/settingsTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ export class SettingsTracker {
return "<invalid>";
}
return val;
} else if (curSetting["oneOf"]) {
// Currently only C_Cpp.default.compileCommands uses this case.
if (curSetting["oneOf"].some((x: any) => this.typeMatch(val, x.type))) {
return val;
}
} else if (val === curSetting["default"]) {
// C_Cpp.default.browse.path is a special case where the default value is null and doesn't match the type definition.
return val;
Expand Down Expand Up @@ -206,7 +211,7 @@ export class SettingsTracker {
if (value && value.length > maxSettingLengthForTelemetry) {
value = value.substring(0, maxSettingLengthForTelemetry) + "...";
}
return {key: key, value: value};
return { key: key, value: value };
}
return undefined;
}
Expand Down
7 changes: 4 additions & 3 deletions Extension/ui/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,12 @@
<div class="section">
<div class="section-title" data-loc-id="compile.commands">Compile commands</div>
<div class="section-text">
<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>
<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>
</div>
<div>
<input name="inputValue" id="compileCommands" style="width: 798px"></input>
<div id="compileCommandsInvalid" class="error" style="width: 800px"></div>
<div class="section-note" data-loc-id="one.compile.commands.path.per.line">One compile commands path per line.</div>
<textarea name="inputValue" id="compileCommands" rows="4" cols="93" style="width: 800px"></textarea>
<div id="compileCommandsInvalid" class="error" style="margin-top: -4px; width: 794px"></div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion Extension/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class SettingsApp {
// Advanced settings
(<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.compileCommands)).value = joinEntries(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

0 comments on commit 2bff033

Please sign in to comment.