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

Handle multiple compile commands on client side (needs native server side support) #12960

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,22 @@
]
},
"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",
"default": ""
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
],
"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
15 changes: 14 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,20 @@
"scope": "machine-overridable"
},
"C_Cpp.default.compileCommands": {
"type": "string",
"oneOf": [
{
"type": "string",
"default": ""
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
],
"markdownDescription": "%c_cpp.configuration.default.compileCommands.markdownDescription%",
"scope": "machine-overridable"
},
Expand Down
138 changes: 94 additions & 44 deletions Extension/src/LanguageServer/configurations.ts

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,26 @@ 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 defaultForcedInclude(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.forcedInclude"); }
public get defaultIntelliSenseMode(): string | undefined { return this.getAsStringOrUndefined("default.intelliSenseMode"); }
public get defaultCompileCommands(): string[] | undefined {
// Try to get the value as a string.
const value: string | undefined = this.getAsStringOrUndefined("default.compileCommands");
if (value !== undefined) {
if (changeBlankStringToUndefined(value) === undefined) {
return undefined;
}
return [value];
}

// value is not a string, try to get it as an array of strings instead.
let valueArray: string[] | undefined = this.getAsArrayOfStringsOrUndefined("default.compileCommands");
valueArray = valueArray?.filter((value: string) => value.length > 0);
if (valueArray?.length === 0) {
return undefined;
}
return valueArray;
}
public get defaultCompilerPath(): string | null { return this.getAsString("default.compilerPath", true); }

public set defaultCompilerPath(value: string) {
Expand Down Expand Up @@ -638,7 +655,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: 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