Skip to content

Commit dcf4809

Browse files
authored
Merge branch 'master' into taraj/box-sample
2 parents 7e5f22f + 02a3152 commit dcf4809

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,9 @@ export class CppProperties {
767767
const compilerPathEnd: number = compilerPathStart === -1 ? -1 : curText.indexOf('"', curText.indexOf('"', curText.indexOf(":", compilerPathStart)) + 1) + 1;
768768

769769
if (this.prevSquiggleMetrics[this.CurrentConfiguration.name] === undefined) {
770-
this.prevSquiggleMetrics[this.CurrentConfiguration.name] = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0 };
770+
this.prevSquiggleMetrics[this.CurrentConfiguration.name] = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0, CompilerPathMissingQuotes: 0 };
771771
}
772-
let newSquiggleMetrics: { [key: string]: number } = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0 };
772+
let newSquiggleMetrics: { [key: string]: number } = { PathNonExistent: 0, PathNotAFile: 0, PathNotADirectory: 0, CompilerPathMissingQuotes: 0 };
773773
const isWindows: boolean = os.platform() === 'win32';
774774

775775
for (let curPath of paths) {
@@ -809,11 +809,15 @@ export class CppProperties {
809809
}
810810
}
811811

812+
let compilerPathNeedsQuotes: boolean = false;
812813
if (isCompilerPath) {
814+
resolvedPath = resolvedPath.trim();
813815
let compilerPathAndArgs: util.CompilerPathAndArgs = util.extractCompilerPathAndArgs(resolvedPath);
814816
if (isWindows && compilerPathAndArgs.compilerPath.endsWith("cl.exe")) {
815817
continue; // Don't squiggle invalid cl.exe paths because it could be for an older preview build.
816818
}
819+
// Squiggle when the compiler's path has spaces without quotes but args are used.
820+
compilerPathNeedsQuotes = compilerPathAndArgs.additionalArgs && !resolvedPath.startsWith('"') && compilerPathAndArgs.compilerPath.includes(" ");
817821
resolvedPath = compilerPathAndArgs.compilerPath;
818822
curPath = curPath.replace(/\"/g, `\\"`);
819823
}
@@ -858,11 +862,16 @@ export class CppProperties {
858862
if ((curOffset >= forcedIncludeStart && curOffset <= forcedeIncludeEnd) ||
859863
(curOffset >= compileCommandsStart && curOffset <= compileCommandsEnd) ||
860864
(curOffset >= compilerPathStart && curOffset <= compilerPathEnd)) {
861-
if (util.checkFileExistsSync(resolvedPath)) {
862-
continue;
865+
if (compilerPathNeedsQuotes) {
866+
message = `Compiler path with spaces and arguments is missing \\" around the path.`;
867+
newSquiggleMetrics.CompilerPathMissingQuotes++;
868+
} else {
869+
if (util.checkFileExistsSync(resolvedPath)) {
870+
continue;
871+
}
872+
message = `Path is not a file: "${resolvedPath}".`;
873+
newSquiggleMetrics.PathNotAFile++;
863874
}
864-
message = `Path is not a file: "${resolvedPath}".`;
865-
newSquiggleMetrics.PathNotAFile++;
866875
} else {
867876
if (util.checkDirectoryExistsSync(resolvedPath)) {
868877
continue;
@@ -895,6 +904,9 @@ export class CppProperties {
895904
if (newSquiggleMetrics.PathNotADirectory !== this.prevSquiggleMetrics[this.CurrentConfiguration.name].PathNotADirectory) {
896905
changedSquiggleMetrics.PathNotADirectory = newSquiggleMetrics.PathNotADirectory;
897906
}
907+
if (newSquiggleMetrics.CompilerPathMissingQuotes !== this.prevSquiggleMetrics[this.CurrentConfiguration.name].CompilerPathMissingQuotes) {
908+
changedSquiggleMetrics.CompilerPathMissingQuotes = newSquiggleMetrics.CompilerPathMissingQuotes;
909+
}
898910
if (Object.keys(changedSquiggleMetrics).length > 0) {
899911
telemetry.logLanguageServerEvent("ConfigSquiggles", null, changedSquiggleMetrics);
900912
}

Extension/src/LanguageServer/extension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ export async function getBuildTasks(returnComplerPath: boolean): Promise<vscode.
171171

172172
let map: Map<string, string> = new Map<string, string>();
173173
const insertOrAssignEntry: (compilerPath: string) => void = (compilerPath: string): void => {
174-
const basename: string = path.basename(compilerPath);
175-
//map.has(basename) ? map.basename] = compilerPath :
174+
let basename: string = compilerPath;
175+
if (compilerPath === userCompilerPath) {
176+
// Make sure the compiler args are not part of the basename.
177+
const compilerPathAndArgs: util.CompilerPathAndArgs = util.extractCompilerPathAndArgs(compilerPath);
178+
basename = compilerPathAndArgs.compilerPath;
179+
}
180+
basename = path.basename(basename);
176181
map.set(basename, compilerPath);
177182
};
178183
compilerPaths.forEach(insertOrAssignEntry);

Extension/src/common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,6 @@ export function extractCompilerPathAndArgs(inputCompilerPath: string): CompilerP
767767
let additionalArgs: string[];
768768
let isWindows: boolean = os.platform() === 'win32';
769769
if (compilerPath) {
770-
compilerPath = compilerPath.trim();
771770
if (compilerPath.startsWith("\"")) {
772771
let endQuote: number = compilerPath.substr(1).search("\"") + 1;
773772
if (endQuote !== -1) {

0 commit comments

Comments
 (0)