Skip to content

Commit f857bc4

Browse files
authored
deal with error cases in configurations (#1687)
1 parent 1177ab5 commit f857bc4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ export class CppProperties {
424424

425425
// Try to use the same configuration as before the change.
426426
let newJson: ConfigurationJson = JSON.parse(readResults);
427+
if (newJson.configurations.length === 0) {
428+
throw { message: "Invalid configuration file. There must be at least one configuration present in the array." };
429+
}
427430
if (!this.configurationIncomplete && newJson.configurations && this.configurationJson) {
428431
for (let i: number = 0; i < newJson.configurations.length; i++) {
429432
if (newJson.configurations[i].name === this.configurationJson.configurations[this.CurrentConfiguration].name) {
@@ -433,6 +436,9 @@ export class CppProperties {
433436
}
434437
}
435438
this.configurationJson = newJson;
439+
if (this.CurrentConfiguration >= newJson.configurations.length) {
440+
this.currentConfigurationIndex.Value = this.getConfigIndexForPlatform(newJson);
441+
}
436442

437443
// Warning: There is a chance that this is incorrect in the event that the c_cpp_properties.json file was created before
438444
// the system includes were available.

0 commit comments

Comments
 (0)