Skip to content

Commit 94f0586

Browse files
committed
Merge branch 'dev/garretts/implement-lldb-dap' of https://github.com/microsoft/vscode-cpptools into dev/garretts/implement-lldb-dap
2 parents 5e17eee + c983a01 commit 94f0586

File tree

12 files changed

+416
-174
lines changed

12 files changed

+416
-174
lines changed

Extension/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ server
1010
debugAdapters
1111
LLVM
1212
bin/cpptools*
13+
bin/libc.so
1314
bin/*.dll
1415
bin/.vs
1516
bin/LICENSE.txt

Extension/c_cpp_properties.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"markdownDescription": "Full path of the compiler being used, e.g. `/usr/bin/gcc`, to enable more accurate IntelliSense.",
2020
"descriptionHint": "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered.",
2121
"type": [
22-
"string",
23-
"null"
22+
"null",
23+
"string"
2424
]
2525
},
2626
"compilerArgs": {
@@ -312,4 +312,4 @@
312312
"version"
313313
],
314314
"additionalProperties": false
315-
}
315+
}

Extension/src/LanguageServer/configurations.ts

Lines changed: 101 additions & 124 deletions
Large diffs are not rendered by default.

Extension/src/LanguageServer/cppBuildTaskProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class CppBuildTaskProvider implements TaskProvider {
9898

9999
// Get user compiler path.
100100
const userCompilerPathAndArgs: util.CompilerPathAndArgs | undefined = await activeClient.getCurrentCompilerPathAndArgs();
101-
let userCompilerPath: string | undefined | null;
101+
let userCompilerPath: string | undefined;
102102
if (userCompilerPathAndArgs) {
103103
userCompilerPath = userCompilerPathAndArgs.compilerPath;
104104
if (userCompilerPath && userCompilerPathAndArgs.compilerName) {

Extension/src/common.ts

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,74 +1183,66 @@ export function isCl(compilerPath: string): boolean {
11831183

11841184
/** CompilerPathAndArgs retains original casing of text input for compiler path and args */
11851185
export interface CompilerPathAndArgs {
1186-
compilerPath?: string | null;
1186+
compilerPath?: string;
11871187
compilerName: string;
11881188
compilerArgs?: string[];
11891189
compilerArgsFromCommandLineInPath: string[];
11901190
allCompilerArgs: string[];
1191+
error?: string;
1192+
telemetry?: { [key: string]: number };
11911193
}
11921194

1193-
export function extractCompilerPathAndArgs(useLegacyBehavior: boolean, inputCompilerPath?: string | null, compilerArgs?: string[]): CompilerPathAndArgs {
1194-
let compilerPath: string | undefined | null = inputCompilerPath;
1195+
/**
1196+
* Parse the compiler path input into a compiler path and compiler args. If there are no args in the input string, this function will have
1197+
* verified that the compiler exists. (e.g. `compilerArgsFromCommandLineInPath` will be empty)
1198+
*
1199+
* @param useLegacyBehavior - If true, use the legacy behavior of separating the compilerPath from the args.
1200+
* @param inputCompilerPath - The compiler path input from the user.
1201+
* @param compilerArgs - The compiler args input from the user.
1202+
* @param cwd - The directory used to resolve relative paths.
1203+
*/
1204+
export function extractCompilerPathAndArgs(useLegacyBehavior: boolean, inputCompilerPath?: string, compilerArgs?: string[], cwd?: string): CompilerPathAndArgs {
1205+
let compilerPath: string | undefined = inputCompilerPath;
11951206
let compilerName: string = "";
11961207
let compilerArgsFromCommandLineInPath: string[] = [];
1208+
const trimLegacyQuotes = (compilerPath?: string): string | undefined => {
1209+
if (compilerPath && useLegacyBehavior) {
1210+
// Try to trim quotes from compiler path.
1211+
const tempCompilerPath: string[] = extractArgs(compilerPath);
1212+
if (tempCompilerPath.length > 0) {
1213+
return tempCompilerPath[0];
1214+
}
1215+
}
1216+
return compilerPath;
1217+
};
11971218
if (compilerPath) {
11981219
compilerPath = compilerPath.trim();
11991220
if (isCl(compilerPath) || checkExecutableWithoutExtensionExistsSync(compilerPath)) {
12001221
// If the path ends with cl, or if a file is found at that path, accept it without further validation.
12011222
compilerName = path.basename(compilerPath);
1223+
} else if (cwd && checkExecutableWithoutExtensionExistsSync(path.join(cwd, compilerPath))) {
1224+
// If the path is relative and a file is found at that path, accept it without further validation.
1225+
compilerPath = path.join(cwd, compilerPath);
1226+
compilerName = path.basename(compilerPath);
12021227
} else if (compilerPath.startsWith("\"") || (os.platform() !== 'win32' && compilerPath.startsWith("'"))) {
12031228
// If the string starts with a quote, treat it as a command line.
12041229
// Otherwise, a path with a leading quote would not be valid.
1205-
if (useLegacyBehavior) {
1206-
compilerArgsFromCommandLineInPath = legacyExtractArgs(compilerPath);
1207-
if (compilerArgsFromCommandLineInPath.length > 0) {
1208-
compilerPath = compilerArgsFromCommandLineInPath.shift();
1209-
if (compilerPath) {
1210-
// Try to trim quotes from compiler path.
1211-
const tempCompilerPath: string[] | undefined = extractArgs(compilerPath);
1212-
if (tempCompilerPath && compilerPath.length > 0) {
1213-
compilerPath = tempCompilerPath[0];
1214-
}
1215-
compilerName = path.basename(compilerPath);
1216-
}
1217-
}
1218-
} else {
1219-
compilerArgsFromCommandLineInPath = extractArgs(compilerPath);
1220-
if (compilerArgsFromCommandLineInPath.length > 0) {
1221-
compilerPath = compilerArgsFromCommandLineInPath.shift();
1222-
if (compilerPath) {
1223-
compilerName = path.basename(compilerPath);
1224-
}
1225-
}
1230+
compilerArgsFromCommandLineInPath = useLegacyBehavior ? legacyExtractArgs(compilerPath) : extractArgs(compilerPath);
1231+
if (compilerArgsFromCommandLineInPath.length > 0) {
1232+
compilerPath = trimLegacyQuotes(compilerArgsFromCommandLineInPath.shift());
1233+
compilerName = path.basename(compilerPath ?? '');
12261234
}
12271235
} else {
1228-
const spaceStart: number = compilerPath.lastIndexOf(" ");
1229-
if (spaceStart !== -1) {
1230-
// There is no leading quote, but a space suggests it might be a command line.
1231-
// Try processing it as a command line, and validate that by checking for the executable.
1236+
if (compilerPath.includes(' ')) {
1237+
// There is no leading quote, but there is a space so we'll treat it as a command line.
12321238
const potentialArgs: string[] = useLegacyBehavior ? legacyExtractArgs(compilerPath) : extractArgs(compilerPath);
1233-
let potentialCompilerPath: string | undefined = potentialArgs.shift();
1234-
if (useLegacyBehavior) {
1235-
if (potentialCompilerPath) {
1236-
const tempCompilerPath: string[] | undefined = extractArgs(potentialCompilerPath);
1237-
if (tempCompilerPath && compilerPath.length > 0) {
1238-
potentialCompilerPath = tempCompilerPath[0];
1239-
}
1240-
}
1241-
}
1242-
if (potentialCompilerPath) {
1243-
if (isCl(potentialCompilerPath) || checkExecutableWithoutExtensionExistsSync(potentialCompilerPath)) {
1244-
compilerArgsFromCommandLineInPath = potentialArgs;
1245-
compilerPath = potentialCompilerPath;
1246-
compilerName = path.basename(compilerPath);
1247-
}
1248-
}
1239+
compilerPath = trimLegacyQuotes(potentialArgs.shift());
1240+
compilerArgsFromCommandLineInPath = potentialArgs;
12491241
}
1242+
compilerName = path.basename(compilerPath ?? '');
12501243
}
12511244
}
1252-
let allCompilerArgs: string[] = !compilerArgs ? [] : compilerArgs;
1253-
allCompilerArgs = allCompilerArgs.concat(compilerArgsFromCommandLineInPath);
1245+
const allCompilerArgs: string[] = (compilerArgs ?? []).concat(compilerArgsFromCommandLineInPath);
12541246
return { compilerPath, compilerName, compilerArgs, compilerArgsFromCommandLineInPath, allCompilerArgs };
12551247
}
12561248

Extension/test/scenarios/SimpleCppProject/assets/b i n/clang++

Whitespace-only changes.

Extension/test/scenarios/SimpleCppProject/assets/b i n/clang++.exe

Whitespace-only changes.

Extension/test/scenarios/SimpleCppProject/assets/bin/cl.exe

Whitespace-only changes.

Extension/test/scenarios/SimpleCppProject/assets/bin/clang-cl.exe

Whitespace-only changes.

Extension/test/scenarios/SimpleCppProject/assets/bin/gcc

Whitespace-only changes.

0 commit comments

Comments
 (0)