@@ -431,30 +431,15 @@ process.on("message", (msg: m.Message) => {
431431 process . send ! ( fakeSuccessResponse ) ;
432432 process . send ! ( response ) ;
433433 } else {
434- let bscExePath = path . join ( projectRootPath , c . bscExePartialPath ) ;
435- let bscNodePath = path . join ( projectRootPath , c . bscNodePartialPath ) ;
436- // There are the native bsc.exe binaries the bs-platform package, and
437- // the javascript bsc wrapper within node_modules/.bin. The JS wrapper
438- // starts and finds the right platform-specific native binary to call.
439- // This has nontrivial overhead each formatting, so we try to directly
440- // invoke the platform-specific native binary (inside bs-platform).
441-
442- // However, we won't always be able to find the bs-platform package;
443- // for example yarn workspace lifts up the dependencies packages to a
444- // directory higher (grumbles); that setup only leaves us to find
445- // node_modules/.bin (which it doesn't touch, thankfully). So for
446- // quirky npm setups, we need to have a graceful degradation and find
447- // the JS bsc wrapper. If we can't even find node_modules/.bin then we
448- // give up
449- let resolvedBscPath = fs . existsSync ( bscExePath )
450- ? bscExePath
451- : fs . existsSync ( bscNodePath )
452- ? bscNodePath
453- : null ;
454- if ( resolvedBscPath === null ) {
434+ // See comment on findBscExeDirUpwardFromProjectRoot for why we need
435+ // to recursively search for bsc.exe upward
436+ let bscExeDir = utils . findBscExeDirUpwardFromProjectRoot (
437+ projectRootPath
438+ ) ;
439+ if ( bscExeDir === null ) {
455440 let params : p . ShowMessageParams = {
456441 type : p . MessageType . Error ,
457- message : `Cannot find a nearby ${ c . bscExePartialPath } nor ${ c . bscNodePartialPath } . It's needed for formatting.` ,
442+ message : `Cannot find a nearby ${ c . bscExePartialPath } . It's needed for formatting.` ,
458443 } ;
459444 let response : m . NotificationMessage = {
460445 jsonrpc : c . jsonrpcVersion ,
@@ -464,6 +449,7 @@ process.on("message", (msg: m.Message) => {
464449 process . send ! ( fakeSuccessResponse ) ;
465450 process . send ! ( response ) ;
466451 } else {
452+ let resolvedBscPath = path . join ( bscExeDir , c . bscExePartialPath ) ;
467453 // code will always be defined here, even though technically it can be undefined
468454 let code = getOpenedFileContent ( params . textDocument . uri ) ;
469455 let formattedResult = utils . formatUsingValidBscPath (
0 commit comments