Skip to content

Commit 775aba8

Browse files
shankaryoga21bobbrow
authored andcommitted
don't use falsy comparisons when resolving default settings. (#2592)
1 parent b3fb255 commit 775aba8

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,39 +215,43 @@ export class CppProperties {
215215
if (this.configurationIncomplete && this.defaultIncludes && this.defaultFrameworks && this.vcpkgPathReady) {
216216
let configuration: Configuration = this.CurrentConfiguration;
217217
let settings: CppSettings = new CppSettings(this.rootUri);
218+
let isUnset: (input: any) => boolean = (input: any) => {
219+
// default values for "default" config settings is null.
220+
return input === null;
221+
};
218222

219223
// Anything that has a vscode setting for it will be resolved in updateServerOnFolderSettingsChange.
220224
// So if a property is currently unset, but has a vscode setting, don't set it yet, otherwise the linkage
221225
// to the setting will be lost if this configuration is saved into a c_cpp_properties.json file.
222226

223227
// Only add settings from the default compiler if user hasn't explicitly set the corresponding VS Code setting.
224228

225-
if (!settings.defaultIncludePath) {
229+
if (isUnset(settings.defaultIncludePath)) {
226230
// We don't add system includes to the includePath anymore. The language server has this information.
227231
let abTestSettings: ABTestSettings = getABTestSettings();
228232
let rootFolder: string = abTestSettings.UseRecursiveIncludes ? "${workspaceFolder}/**" : "${workspaceFolder}";
229233
configuration.includePath = [rootFolder].concat(this.vcpkgIncludes);
230234
}
231235
// browse.path is not set by default anymore. When it is not set, the includePath will be used instead.
232-
if (!settings.defaultDefines) {
236+
if (isUnset(settings.defaultDefines)) {
233237
configuration.defines = (process.platform === 'win32') ? ["_DEBUG", "UNICODE", "_UNICODE"] : [];
234238
}
235-
if (!settings.defaultMacFrameworkPath && process.platform === 'darwin') {
239+
if (isUnset(settings.defaultMacFrameworkPath) && process.platform === 'darwin') {
236240
configuration.macFrameworkPath = this.defaultFrameworks;
237241
}
238-
if (!settings.defaultWindowsSdkVersion && this.defaultWindowsSdkVersion && process.platform === 'win32') {
242+
if (isUnset(settings.defaultWindowsSdkVersion) && this.defaultWindowsSdkVersion && process.platform === 'win32') {
239243
configuration.windowsSdkVersion = this.defaultWindowsSdkVersion;
240244
}
241-
if (!settings.defaultCompilerPath && this.defaultCompilerPath) {
245+
if (isUnset(settings.defaultCompilerPath) && this.defaultCompilerPath) {
242246
configuration.compilerPath = this.defaultCompilerPath;
243247
}
244-
if (!settings.defaultCStandard && this.defaultCStandard) {
248+
if (isUnset(settings.defaultCStandard) && this.defaultCStandard) {
245249
configuration.cStandard = this.defaultCStandard;
246250
}
247-
if (!settings.defaultCppStandard && this.defaultCppStandard) {
251+
if (isUnset(settings.defaultCppStandard) && this.defaultCppStandard) {
248252
configuration.cppStandard = this.defaultCppStandard;
249253
}
250-
if (!settings.defaultIntelliSenseMode) {
254+
if (isUnset(settings.defaultIntelliSenseMode)) {
251255
configuration.intelliSenseMode = this.defaultIntelliSenseMode;
252256
}
253257
this.configurationIncomplete = false;
@@ -431,11 +435,11 @@ export class CppProperties {
431435
private updateConfiguration(property: string, defaultValue: string, env: Environment): string;
432436
private updateConfiguration(property: string | boolean, defaultValue: boolean, env: Environment): boolean;
433437
private updateConfiguration(property, defaultValue, env): any {
434-
if (typeof property === "string" || typeof defaultValue === "string") {
438+
if (util.isString(property) || util.isString(defaultValue)) {
435439
return this.resolveVariables(property, defaultValue, env);
436-
} else if (typeof property === "boolean" || typeof defaultValue === "boolean") {
440+
} else if (util.isBoolean(property) || util.isBoolean(defaultValue)) {
437441
return this.resolveVariables(property, defaultValue, env);
438-
} else if (property instanceof Array || defaultValue instanceof Array) {
442+
} else if (util.isArrayOfString(property) || util.isArrayOfString(defaultValue)) {
439443
if (property) {
440444
return this.resolveAndSplit(property, defaultValue, env);
441445
} else if (property === undefined && defaultValue) {

Extension/src/common.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,20 @@ export function isNumber(input: any): input is number {
183183
return typeof(input) === "number";
184184
}
185185

186+
export function isBoolean(input: any): input is boolean {
187+
return typeof(input) === "boolean";
188+
}
189+
190+
export function isArray(input: any): input is any[] {
191+
return input instanceof Array;
192+
}
193+
186194
export function isOptionalString(input: any): input is string|undefined {
187195
return input === undefined || isString(input);
188196
}
189197

190198
export function isArrayOfString(input: any): input is string[] {
191-
return (input instanceof Array) && input.every(item => isString(item));
199+
return isArray(input) && input.every(item => isString(item));
192200
}
193201

194202
export function isOptionalArrayOfString(input: any): input is string[]|undefined {

0 commit comments

Comments
 (0)