Skip to content

Commit 88f419f

Browse files
authored
Remove the full path for the cl.exe compilerPath generated for c_cpp_properties.json (#10485)
* change description for natvisDiagnostics * update natvisDiagnostics * update compiler logic to only set "cl.exe" * fix lint errors * resolve PR * resolve PR * resolve PR * resolve PR * resolve PR * resolve PR
1 parent fc4fc00 commit 88f419f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -920,21 +920,13 @@ export class DefaultClient implements Client {
920920

921921
const items: IndexableQuickPickItem[] = [];
922922
for (let i: number = 0; i < paths.length; i++) {
923-
let option: string | undefined;
924-
let isCompiler: boolean = false;
925-
const slash: string = (os.platform() === 'win32') ? "\\" : "/";
923+
const compilerName: string = path.basename(paths[i]);
924+
const isCompiler: boolean = compilerName !== paths[i];
926925

927-
if (paths[i].includes(slash)) {
928-
if (paths[i].split(slash).pop() !== undefined) {
929-
option = paths[i].split(slash).pop();
930-
isCompiler = true;
931-
}
932-
}
933-
934-
if (option !== undefined && isCompiler) {
935-
const path: string | undefined = paths[i].replace(option, "");
926+
if (isCompiler) {
927+
const path: string | undefined = paths[i].replace(compilerName, "");
936928
const description: string = localize("found.string", "Found at {0}", path);
937-
items.push({ label: option, description: description, index: i });
929+
items.push({ label: compilerName, description: description, index: i });
938930
} else {
939931
items.push({ label: paths[i], index: i });
940932
}

Extension/src/LanguageServer/configurations.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,15 @@ export class CppProperties {
396396
(isUnset(settings.defaultCompileCommands) || settings.defaultCompileCommands === "") && !configuration.compileCommands) {
397397
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
398398
// don't set a default when compileCommands is in use.
399-
configuration.compilerPath = this.defaultCompilerPath;
399+
400+
// if the compiler is a cl.exe compiler, replace the full path with the "cl.exe" string.
401+
const compiler: string = path.basename(this.defaultCompilerPath).toLowerCase();
402+
403+
if (compiler === "cl.exe") {
404+
configuration.compilerPath = "cl.exe";
405+
} else {
406+
configuration.compilerPath = this.defaultCompilerPath;
407+
}
400408
}
401409
if ((isUnset(settings.defaultCStandard) || settings.defaultCStandard === "") && this.defaultCStandard) {
402410
configuration.cStandard = this.defaultCStandard;

0 commit comments

Comments
 (0)