Skip to content

Commit dc8813f

Browse files
authored
Fix undefined access if there's no includePath. (#3572)
* Fix undefined access if there's no includePath.
1 parent e0543a6 commit dc8813f

1 file changed

Lines changed: 32 additions & 27 deletions

File tree

Extension/src/LanguageServer/configurations.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -940,39 +940,41 @@ export class CppProperties {
940940

941941
// Validate includePath
942942
let includePathErrors: string[] = [];
943-
for (let includePath of this.CurrentConfiguration.includePath) {
944-
let pathExists: boolean = true;
945-
let resolvedIncludePath: string = this.resolvePath(includePath, isWindows);
946-
if (!resolvedIncludePath) {
947-
continue;
948-
}
943+
if (this.CurrentConfiguration.includePath) {
944+
for (let includePath of this.CurrentConfiguration.includePath) {
945+
let pathExists: boolean = true;
946+
let resolvedIncludePath: string = this.resolvePath(includePath, isWindows);
947+
if (!resolvedIncludePath) {
948+
continue;
949+
}
949950

950-
// Check if resolved path exists
951-
if (!fs.existsSync(resolvedIncludePath)) {
952-
// Check for relative path if resolved path does not exists
953-
const relativePath: string = this.rootUri.fsPath + path.sep + resolvedIncludePath;
954-
if (!fs.existsSync(relativePath)) {
955-
pathExists = false;
956-
} else {
957-
resolvedIncludePath = relativePath;
951+
// Check if resolved path exists
952+
if (!fs.existsSync(resolvedIncludePath)) {
953+
// Check for relative path if resolved path does not exists
954+
const relativePath: string = this.rootUri.fsPath + path.sep + resolvedIncludePath;
955+
if (!fs.existsSync(relativePath)) {
956+
pathExists = false;
957+
} else {
958+
resolvedIncludePath = relativePath;
959+
}
958960
}
959-
}
960961

961-
if (!pathExists) {
962-
let message: string = `Cannot find: ${resolvedIncludePath}`;
963-
includePathErrors.push(message);
964-
continue;
965-
}
962+
if (!pathExists) {
963+
let message: string = `Cannot find: ${resolvedIncludePath}`;
964+
includePathErrors.push(message);
965+
continue;
966+
}
966967

967-
// Check if path is a directory
968-
if (!util.checkDirectoryExistsSync(resolvedIncludePath)) {
969-
let message: string = `Path is not a directory: ${resolvedIncludePath}`;
970-
includePathErrors.push(message);
968+
// Check if path is a directory
969+
if (!util.checkDirectoryExistsSync(resolvedIncludePath)) {
970+
let message: string = `Path is not a directory: ${resolvedIncludePath}`;
971+
includePathErrors.push(message);
972+
}
971973
}
972-
}
973974

974-
if (includePathErrors.length > 0) {
975-
errors.includePath = includePathErrors.join('\n');
975+
if (includePathErrors.length > 0) {
976+
errors.includePath = includePathErrors.join('\n');
977+
}
976978
}
977979

978980
// Validate intelliSenseMode
@@ -1005,6 +1007,9 @@ export class CppProperties {
10051007
// Get the text of the current configuration.
10061008
let curText: string = document.getText();
10071009
let curTextStartOffset: number = 0;
1010+
if (!this.CurrentConfiguration.name) {
1011+
return;
1012+
}
10081013
const configStart: number = curText.search(new RegExp(`{\\s*"name"\\s*:\\s*"${escapeStringRegExp(this.CurrentConfiguration.name)}"`));
10091014
if (configStart === -1) {
10101015
telemetry.logLanguageServerEvent("ConfigSquiggles", { "error": "config name not first" });

0 commit comments

Comments
 (0)