in Extension/src/LanguageServer/configurations.ts [1365:1459]
private getErrorsForConfigUI(configIndex: number): ConfigurationErrors {
const errors: ConfigurationErrors = {};
if (!this.configurationJson) {
return errors;
}
const isWindows: boolean = os.platform() === 'win32';
const config: Configuration = this.configurationJson.configurations[configIndex];
// Check if config name is unique.
errors.name = this.isConfigNameUnique(config.name);
// Validate compilerPath
let resolvedCompilerPath: string | undefined = this.resolvePath(config.compilerPath, isWindows);
const compilerPathAndArgs: util.CompilerPathAndArgs = util.extractCompilerPathAndArgs(resolvedCompilerPath);
if (resolvedCompilerPath
// Don't error cl.exe paths because it could be for an older preview build.
&& compilerPathAndArgs.compilerName.toLowerCase() !== "cl.exe"
&& compilerPathAndArgs.compilerName.toLowerCase() !== "cl") {
resolvedCompilerPath = resolvedCompilerPath.trim();
// Error when the compiler's path has spaces without quotes but args are used.
// Except, exclude cl.exe paths because it could be for an older preview build.
const compilerPathNeedsQuotes: boolean =
(compilerPathAndArgs.additionalArgs && compilerPathAndArgs.additionalArgs.length > 0) &&
!resolvedCompilerPath.startsWith('"') &&
compilerPathAndArgs.compilerPath !== undefined &&
compilerPathAndArgs.compilerPath.includes(" ");
const compilerPathErrors: string[] = [];
if (compilerPathNeedsQuotes) {
compilerPathErrors.push(localize("path.with.spaces", 'Compiler path with spaces and arguments is missing double quotes " around the path.'));
}
// Get compiler path without arguments before checking if it exists
resolvedCompilerPath = compilerPathAndArgs.compilerPath;
if (resolvedCompilerPath) {
let pathExists: boolean = true;
const existsWithExeAdded: (path: string) => boolean = (path: string) => isWindows && !path.startsWith("/") && fs.existsSync(path + ".exe");
if (!fs.existsSync(resolvedCompilerPath)) {
if (existsWithExeAdded(resolvedCompilerPath)) {
resolvedCompilerPath += ".exe";
} else if (!this.rootUri) {
pathExists = false;
} else {
// Check again for a relative path.
const relativePath: string = this.rootUri.fsPath + path.sep + resolvedCompilerPath;
if (!fs.existsSync(relativePath)) {
if (existsWithExeAdded(resolvedCompilerPath)) {
resolvedCompilerPath += ".exe";
} else {
pathExists = false;
}
} else {
resolvedCompilerPath = relativePath;
}
}
}
if (!pathExists) {
const message: string = localize('cannot.find', "Cannot find: {0}", resolvedCompilerPath);
compilerPathErrors.push(message);
} else if (compilerPathAndArgs.compilerPath === "") {
const message: string = localize("cannot.resolve.compiler.path", "Invalid input, cannot resolve compiler path");
compilerPathErrors.push(message);
} else if (!util.checkFileExistsSync(resolvedCompilerPath)) {
const message: string = localize("path.is.not.a.file", "Path is not a file: {0}", resolvedCompilerPath);
compilerPathErrors.push(message);
}
if (compilerPathErrors.length > 0) {
errors.compilerPath = compilerPathErrors.join('\n');
}
}
}
// Validate paths (directories)
errors.includePath = this.validatePath(config.includePath);
errors.macFrameworkPath = this.validatePath(config.macFrameworkPath);
errors.browsePath = this.validatePath(config.browse ? config.browse.path : undefined);
// Validate files
errors.forcedInclude = this.validatePath(config.forcedInclude, false, true);
errors.compileCommands = this.validatePath(config.compileCommands, false);
errors.databaseFilename = this.validatePath((config.browse ? config.browse.databaseFilename : undefined), false);
// Validate intelliSenseMode
if (isWindows) {
const intelliSenesModeError: string = this.validateIntelliSenseMode(config);
if (intelliSenesModeError.length > 0) {
errors.intelliSenseMode = intelliSenesModeError;
}
}
return errors;
}