Fix/external include handling by Subham-KRLX · Pull Request #14208 · microsoft/vscode-cpptools · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Extension/src/LanguageServer/client.ts
69 changes: 69 additions & 0 deletions Extension/src/Utility/msvcFlags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */

export interface IncludePathsFromArgs {
includePaths: string[];
externalIncludePaths: string[];
externalIncludeVars: string[];
}

/**
* Parses compiler arguments for include-related flags (MSVC/clang-cl style).
* Supports /I, /imsvc, /external:I, /external:var.
*/
export function extractIncludePathsFromArgs(args: string[]): IncludePathsFromArgs {
const result: IncludePathsFromArgs = {
includePaths: [],
externalIncludePaths: [],
externalIncludeVars: []
};

for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg.startsWith("/I") || arg.startsWith("-I")) {
let path = arg.substring(2);
if (path === "" && i + 1 < args.length) {
const nextArg = args[i + 1];
if (!nextArg.startsWith("/") && !nextArg.startsWith("-")) {
path = args[++i];
}
}
if (path !== "") {
result.includePaths.push(path);
}
} else if (arg.startsWith("/imsvc") || arg.startsWith("-imsvc")) {
let path = arg.substring(6);
if (path === "" && i + 1 < args.length) {
const nextArg = args[i + 1];
if (!nextArg.startsWith("/") && !nextArg.startsWith("-")) {
path = args[++i];
}
}
if (path !== "") {
// imsvc is treated as a system include, so we put it in externalIncludePaths
result.externalIncludePaths.push(path);
}
} else if (arg.startsWith("/external:I") || arg.startsWith("-external:I")) {
let path = arg.substring(11);
if (path === "" && i + 1 < args.length) {
const nextArg = args[i + 1];
if (!nextArg.startsWith("/") && !nextArg.startsWith("-")) {
path = args[++i];
}
}
if (path !== "") {
result.externalIncludePaths.push(path);
}
} else if (arg.startsWith("/external:var:") || arg.startsWith("-external:var:")) {

const varName = arg.substring(14);
if (varName !== "") {
result.externalIncludeVars.push(varName);
}
}
}

return result;
}
4 changes: 4 additions & 0 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1850,3 +1850,7 @@ export function getVSCodeLanguageModel(): any | undefined {
}
return vscodelm;
}

export * from './Utility/msvcFlags';


51 changes: 51 additions & 0 deletions Extension/test/unit/msvcArgumentParsing.test.ts