@@ -1614,51 +1614,54 @@ export class CppProperties {
16141614 const telemetry : { [ key : string ] : number } = { } ;
16151615
16161616 // Don't error cl.exe paths because it could be for an older preview build.
1617- if ( ! isCl ) {
1618- // Get compiler path without arguments before checking if it exists
1619- if ( compilerPathAndArgs . compilerPath ) {
1620- resolvedCompilerPath = compilerPathAndArgs . compilerPath ;
1621- let pathExists : boolean = true ;
1622- const existsWithExeAdded : ( path : string ) => boolean = ( path : string ) => isWindows && ! path . startsWith ( "/" ) && fs . existsSync ( path + ".exe" ) ;
1623- if ( ! fs . existsSync ( resolvedCompilerPath ) ) {
1624- if ( existsWithExeAdded ( resolvedCompilerPath ) ) {
1625- resolvedCompilerPath += ".exe" ;
1626- } else {
1627- const pathLocation = which . sync ( resolvedCompilerPath , { nothrow : true } ) ;
1628- if ( pathLocation ) {
1629- resolvedCompilerPath = pathLocation ;
1630- compilerPathAndArgs . compilerPath = pathLocation ;
1631- } else if ( rootUri ) {
1632- // Check again for a relative path.
1633- const relativePath : string = rootUri . fsPath + path . sep + resolvedCompilerPath ;
1634- if ( ! fs . existsSync ( relativePath ) ) {
1635- if ( existsWithExeAdded ( relativePath ) ) {
1636- resolvedCompilerPath = relativePath + ".exe" ;
1637- } else {
1638- pathExists = false ;
1639- }
1617+ if ( ! isCl && compilerPathAndArgs . compilerPath ) {
1618+ const compilerPathMayNeedQuotes : boolean = ! resolvedCompilerPath . startsWith ( '"' ) && resolvedCompilerPath . includes ( " " ) && compilerPathAndArgs . compilerArgsFromCommandLineInPath . length > 0 ;
1619+ let pathExists : boolean = true ;
1620+ const existsWithExeAdded : ( path : string ) => boolean = ( path : string ) => isWindows && ! path . startsWith ( "/" ) && fs . existsSync ( path + ".exe" ) ;
1621+
1622+ resolvedCompilerPath = compilerPathAndArgs . compilerPath ;
1623+ if ( ! fs . existsSync ( resolvedCompilerPath ) ) {
1624+ if ( existsWithExeAdded ( resolvedCompilerPath ) ) {
1625+ resolvedCompilerPath += ".exe" ;
1626+ } else {
1627+ const pathLocation = which . sync ( resolvedCompilerPath , { nothrow : true } ) ;
1628+ if ( pathLocation ) {
1629+ resolvedCompilerPath = pathLocation ;
1630+ compilerPathAndArgs . compilerPath = pathLocation ;
1631+ } else if ( rootUri ) {
1632+ // Check again for a relative path.
1633+ const relativePath : string = rootUri . fsPath + path . sep + resolvedCompilerPath ;
1634+ if ( ! fs . existsSync ( relativePath ) ) {
1635+ if ( existsWithExeAdded ( relativePath ) ) {
1636+ resolvedCompilerPath = relativePath + ".exe" ;
16401637 } else {
1641- resolvedCompilerPath = relativePath ;
1638+ pathExists = false ;
16421639 }
1640+ } else {
1641+ resolvedCompilerPath = relativePath ;
16431642 }
16441643 }
16451644 }
1645+ }
16461646
1647- const compilerPathErrors : string [ ] = [ ] ;
1647+ const compilerPathErrors : string [ ] = [ ] ;
1648+ if ( compilerPathMayNeedQuotes && ! pathExists ) {
1649+ compilerPathErrors . push ( localize ( "path.with.spaces" , 'Compiler path with spaces and arguments is missing double quotes " around the path.' ) ) ;
1650+ telemetry . CompilerPathMissingQuotes = 1 ;
1651+ }
16481652
1649- if ( ! pathExists ) {
1650- const message : string = localize ( 'cannot.find' , "Cannot find: {0}" , resolvedCompilerPath ) ;
1651- compilerPathErrors . push ( message ) ;
1652- telemetry . PathNonExistent = 1 ;
1653- } else if ( ! util . checkExecutableWithoutExtensionExistsSync ( resolvedCompilerPath ) ) {
1654- const message : string = localize ( "path.is.not.a.file" , "Path is not a file: {0}" , resolvedCompilerPath ) ;
1655- compilerPathErrors . push ( message ) ;
1656- telemetry . PathNotAFile = 1 ;
1657- }
1653+ if ( ! pathExists ) {
1654+ const message : string = localize ( 'cannot.find' , "Cannot find: {0}" , resolvedCompilerPath ) ;
1655+ compilerPathErrors . push ( message ) ;
1656+ telemetry . PathNonExistent = 1 ;
1657+ } else if ( ! util . checkExecutableWithoutExtensionExistsSync ( resolvedCompilerPath ) ) {
1658+ const message : string = localize ( "path.is.not.a.file" , "Path is not a file: {0}" , resolvedCompilerPath ) ;
1659+ compilerPathErrors . push ( message ) ;
1660+ telemetry . PathNotAFile = 1 ;
1661+ }
16581662
1659- if ( compilerPathErrors . length > 0 ) {
1660- compilerPathAndArgs . error = compilerPathErrors . join ( '\n' ) ;
1661- }
1663+ if ( compilerPathErrors . length > 0 ) {
1664+ compilerPathAndArgs . error = compilerPathErrors . join ( '\n' ) ;
16621665 }
16631666 }
16641667 compilerPathAndArgs . telemetry = telemetry ;
0 commit comments