@@ -117,17 +117,23 @@ export class CppBuildTaskProvider implements TaskProvider {
117117 }
118118
119119 const isCompilerValid : boolean = userCompilerPath ? await util . checkFileExists ( userCompilerPath ) : false ;
120+ const userCompilerIsCl : boolean = isCompilerValid && ! ! userCompilerPathAndArgs && userCompilerPathAndArgs . compilerName === "cl.exe" ;
120121
121122 // Get known compiler paths. Do not include the known compiler path that is the same as user compiler path.
122123 // Filter them based on the file type to get a reduced list appropriate for the active file.
124+ // Only allow one instance of cl.exe to be included, as the user must launch VS Code using a VS command
125+ // prompt in order to build with cl.exe, so only one can apply.
123126 const knownCompilerPathsSet : Set < string > = new Set ( ) ;
124127 let knownCompilers : configs . KnownCompiler [ ] | undefined = await activeClient . getKnownCompilers ( ) ;
125128 if ( knownCompilers ) {
126- knownCompilers = knownCompilers . filter ( info =>
127- ( ( fileIsCpp && ! info . isC ) || ( fileIsC && info . isC ) ) &&
128- ( ! isCompilerValid || ( userCompilerPathAndArgs &&
129+ const compiler_condition : ( info : configs . KnownCompiler ) => boolean = info => ( ( fileIsCpp && ! info . isC ) || ( fileIsC && info . isC ) ) &&
130+ ( ! isCompilerValid || ( ! ! userCompilerPathAndArgs &&
129131 ( path . basename ( info . path ) !== userCompilerPathAndArgs . compilerName ) ) ) &&
130- ( ! isWindows || ! info . path . startsWith ( "/" ) ) ) ; // TODO: Add WSL compiler support.
132+ ( ! isWindows || ! info . path . startsWith ( "/" ) ) ; // TODO: Add WSL compiler support.
133+ const cl_to_add : configs . KnownCompiler | undefined = userCompilerIsCl ? undefined : knownCompilers . find ( info =>
134+ ( ( path . basename ( info . path ) === "cl.exe" ) && compiler_condition ( info ) ) ) ;
135+ knownCompilers = knownCompilers . filter ( info =>
136+ ( ( info === cl_to_add ) || ( path . basename ( info . path ) !== "cl.exe" && compiler_condition ( info ) ) ) ) ;
131137 knownCompilers . map < void > ( info => {
132138 knownCompilerPathsSet . add ( info . path ) ;
133139 } ) ;
0 commit comments