@@ -417,11 +417,15 @@ process.on("message", (msg: m.Message) => {
417417 process . send ! ( fakeSuccessResponse ) ;
418418 process . send ! ( response ) ;
419419 } else {
420- let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
421- if ( projectRootPath == null ) {
420+ // See comment on findBscExeDirOfFile for why we need
421+ // to recursively search for bsc.exe upward
422+ let bscExeDir = utils . findBscExeDirOfFile (
423+ filePath
424+ ) ;
425+ if ( bscExeDir === null ) {
422426 let params : p . ShowMessageParams = {
423427 type : p . MessageType . Error ,
424- message : `Cannot find a nearby ${ c . bsconfigPartialPath } . It's needed for determining the project's root .` ,
428+ message : `Cannot find a nearby ${ c . bscExePartialPath } . It's needed for formatting .` ,
425429 } ;
426430 let response : m . NotificationMessage = {
427431 jsonrpc : c . jsonrpcVersion ,
@@ -431,58 +435,39 @@ process.on("message", (msg: m.Message) => {
431435 process . send ! ( fakeSuccessResponse ) ;
432436 process . send ! ( response ) ;
433437 } else {
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+ let resolvedBscPath = path . join ( bscExeDir , c . bscExePartialPath ) ;
439+ // code will always be defined here, even though technically it can be undefined
440+ let code = getOpenedFileContent ( params . textDocument . uri ) ;
441+ let formattedResult = utils . formatUsingValidBscPath (
442+ code ,
443+ resolvedBscPath ,
444+ extension === c . resiExt
438445 ) ;
439- if ( bscExeDir === null ) {
440- let params : p . ShowMessageParams = {
441- type : p . MessageType . Error ,
442- message : `Cannot find a nearby ${ c . bscExePartialPath } . It's needed for formatting.` ,
443- } ;
444- let response : m . NotificationMessage = {
446+ if ( formattedResult . kind === "success" ) {
447+ let result : p . TextEdit [ ] = [
448+ {
449+ range : {
450+ start : { line : 0 , character : 0 } ,
451+ end : {
452+ line : Number . MAX_VALUE ,
453+ character : Number . MAX_VALUE ,
454+ } ,
455+ } ,
456+ newText : formattedResult . result ,
457+ } ,
458+ ] ;
459+ let response : m . ResponseMessage = {
445460 jsonrpc : c . jsonrpcVersion ,
446- method : "window/showMessage" ,
447- params : params ,
461+ id : msg . id ,
462+ result : result ,
448463 } ;
449- process . send ! ( fakeSuccessResponse ) ;
450464 process . send ! ( response ) ;
451465 } else {
452- let resolvedBscPath = path . join ( bscExeDir , c . bscExePartialPath ) ;
453- // code will always be defined here, even though technically it can be undefined
454- let code = getOpenedFileContent ( params . textDocument . uri ) ;
455- let formattedResult = utils . formatUsingValidBscPath (
456- code ,
457- resolvedBscPath ,
458- extension === c . resiExt
459- ) ;
460- if ( formattedResult . kind === "success" ) {
461- let result : p . TextEdit [ ] = [
462- {
463- range : {
464- start : { line : 0 , character : 0 } ,
465- end : {
466- line : Number . MAX_VALUE ,
467- character : Number . MAX_VALUE ,
468- } ,
469- } ,
470- newText : formattedResult . result ,
471- } ,
472- ] ;
473- let response : m . ResponseMessage = {
474- jsonrpc : c . jsonrpcVersion ,
475- id : msg . id ,
476- result : result ,
477- } ;
478- process . send ! ( response ) ;
479- } else {
480- // let the diagnostics logic display the updated syntax errors,
481- // from the build.
482- // Again, not sending the actual errors. See fakeSuccessResponse
483- // above for explanation
484- process . send ! ( fakeSuccessResponse ) ;
485- }
466+ // let the diagnostics logic display the updated syntax errors,
467+ // from the build.
468+ // Again, not sending the actual errors. See fakeSuccessResponse
469+ // above for explanation
470+ process . send ! ( fakeSuccessResponse ) ;
486471 }
487472 }
488473 }
0 commit comments