Skip to content

Commit 3526478

Browse files
committed
Address PR feedback
1 parent 025100c commit 3526478

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Extension/c_cpp_properties.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"compilerPath": {
1919
"markdownDescription": "Full path of the compiler being used, e.g. `/usr/bin/gcc`, to enable more accurate IntelliSense.",
2020
"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.",
21-
"type": "string"
21+
"type": [
22+
"string",
23+
"null"
24+
]
2225
},
2326
"compilerArgs": {
2427
"markdownDescription": "Compiler arguments to modify the includes or defines used, e.g. `-nostdinc++`, `-m32`, etc. Arguments that take additional space-delimited arguments should be entered as separate arguments in the array, e.g. for `--sysroot <arg>` use `\"--sysroot\", \"<arg>\"`.",

Extension/src/LanguageServer/configurations.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface ConfigurationJson {
6363
export interface Configuration {
6464
name: string;
6565
compilerPathInCppPropertiesJson?: string | null;
66-
compilerPath?: string;
66+
compilerPath?: string; // Can be set to null based on the schema, but it will be fixed in parsePropertiesFile.
6767
compilerPathIsExplicit?: boolean;
6868
compilerArgs?: string[];
6969
compilerArgsLegacy?: string[];
@@ -1443,10 +1443,17 @@ export class CppProperties {
14431443
}
14441444
}
14451445

1446-
// Configuration.compileCommands is allowed to be defined as a string in the schema, but we send an array to the language server.
1447-
// For having a predictable behavior, we convert it here to an array of strings.
1446+
// Special sanitization of the newly parsed configuration file happens here:
14481447
for (let i: number = 0; i < newJson.configurations.length; i++) {
1448+
// Configuration.compileCommands is allowed to be defined as a string in the schema, but we send an array to the language server.
1449+
// For having a predictable behavior, we convert it here to an array of strings.
14491450
newJson.configurations[i].compileCommands = this.forceCompileCommandsAsArray(<any>newJson.configurations[i].compileCommands);
1451+
1452+
// `compilerPath` is allowed to be set to null in the schema so that empty string is not the default value (which has another meaning).
1453+
// If we detect this, we treat it as undefined.
1454+
if (newJson.configurations[i].compilerPath === null) {
1455+
delete newJson.configurations[i].compilerPath;
1456+
}
14501457
}
14511458

14521459
this.configurationJson = newJson;
@@ -1647,7 +1654,7 @@ export class CppProperties {
16471654

16481655
const compilerPathErrors: string[] = [];
16491656
if (compilerPathMayNeedQuotes && !pathExists) {
1650-
compilerPathErrors.push(localize("path.with.spaces", 'Compiler path with spaces and arguments is missing double quotes " around the path.'));
1657+
compilerPathErrors.push(localize("path.with.spaces", 'Compiler path with spaces could not be found. If this was intended to include compiler arguments, surround the compiler path with double quotes (").'));
16511658
telemetry.CompilerPathMissingQuotes = 1;
16521659
}
16531660

Extension/test/scenarios/SimpleCppProject/tests/compilerPath.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ describe('validateCompilerPath', () => {
263263
equal(result.compilerName, 'icc', 'compilerName should be found');
264264
deepEqual(result.allCompilerArgs, ['-O2'], 'args should match');
265265
ok(result.error?.includes('Cannot find'), 'Should have an error for unknown compiler');
266-
ok(result.error?.includes('missing double quotes'), 'Should have an error for missing double quotes');
266+
ok(result.error?.includes('surround the compiler path with double quotes'), 'Should have an error for missing double quotes');
267267
equal(result.telemetry?.PathNonExistent, 1, 'Should have telemetry for relative paths');
268268
equal(result.telemetry?.PathNotAFile, undefined, 'Should not have telemetry for invalid paths');
269269
equal(result.telemetry?.CompilerPathMissingQuotes, 1, 'Should have telemetry for missing quotes');

0 commit comments

Comments
 (0)