Skip to content

Commit 716979e

Browse files
authored
Prepending workspace path to relative paths from CppProperties (#10045)
* Relative paths of compileCommands to workspacePath * Address issue * Fix lint * Change rootUri for undefined * Minor fix
1 parent 117ec80 commit 716979e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,10 @@ export class DefaultClient implements Client {
23972397
} else {
23982398
modifiedConfig.compilerArgs = compilerPathAndArgs.allCompilerArgs;
23992399
}
2400+
2401+
if (modifiedConfig.compileCommands) {
2402+
modifiedConfig.compileCommands = cppProperties.resolvePath(modifiedConfig.compileCommands, os.platform() === "win32");
2403+
}
24002404
params.configurations.push(modifiedConfig);
24012405
});
24022406

Extension/src/LanguageServer/configurations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,15 +1353,15 @@ export class CppProperties {
13531353
return success;
13541354
}
13551355

1356-
private resolvePath(path: string | undefined, isWindows: boolean): string {
1357-
if (!path || path === "${default}") {
1356+
public resolvePath(input_path: string | undefined, isWindows: boolean): string {
1357+
if (!input_path || input_path === "${default}") {
13581358
return "";
13591359
}
13601360

13611361
let result: string = "";
13621362

13631363
// first resolve variables
1364-
result = util.resolveVariables(path, this.ExtendedEnvironment);
1364+
result = util.resolveVariables(input_path, this.ExtendedEnvironment);
13651365
if (this.rootUri) {
13661366
if (result.includes("${workspaceFolder}")) {
13671367
result = result.replace("${workspaceFolder}", this.rootUri.fsPath);
@@ -1377,6 +1377,11 @@ export class CppProperties {
13771377
result = result.replace(/\*/g, "");
13781378
}
13791379

1380+
// Make sure all paths result to an absolute path
1381+
if (!path.isAbsolute(result) && this.rootUri) {
1382+
result = path.join(this.rootUri.fsPath, result);
1383+
}
1384+
13801385
return result;
13811386
}
13821387

0 commit comments

Comments
 (0)