@@ -437,10 +437,10 @@ function createInterface(msg: p.RequestMessage): m.Message {
437437 let code = getOpenedFileContent ( params . uri ) ;
438438 let isReactComponent = code . includes ( "@react.component" ) ;
439439
440- if ( isReactComponent ) {
440+ if ( bscNativePath === null || projDir === null ) {
441441 let params : p . ShowMessageParams = {
442442 type : p . MessageType . Error ,
443- message : `Cannot create an interface for a file containing @react.component .` ,
443+ message : `Cannot find a nearby bsc.exe to generate the interface file .` ,
444444 } ;
445445
446446 let response : m . NotificationMessage = {
@@ -450,11 +450,11 @@ function createInterface(msg: p.RequestMessage): m.Message {
450450 } ;
451451
452452 return response ;
453- } else
454- if ( bscNativePath === null || projDir === null ) {
453+ } else
454+ if ( isReactComponent ) {
455455 let params : p . ShowMessageParams = {
456456 type : p . MessageType . Error ,
457- message : `Cannot find a nearby bsc.exe to generate the interface file .` ,
457+ message : `Cannot create an interface for a file containing @react.component .` ,
458458 } ;
459459
460460 let response : m . NotificationMessage = {
@@ -464,73 +464,74 @@ function createInterface(msg: p.RequestMessage): m.Message {
464464 } ;
465465
466466 return response ;
467- } else if ( extension !== c . resExt ) {
468- let params : p . ShowMessageParams = {
469- type : p . MessageType . Error ,
470- message : `Not a ${ c . resExt } file. Cannot create an interface for it.` ,
471- } ;
472-
473- let response : m . NotificationMessage = {
474- jsonrpc : c . jsonrpcVersion ,
475- method : "window/showMessage" ,
476- params : params ,
477- } ;
478-
479- return response ;
480- } else {
481- let cmiPartialPath = utils . replaceFileExtension (
482- filePath . split ( projDir ) [ 1 ] ,
483- c . cmiExt
484- ) ;
485- let cmiPath = path . join (
486- projDir ,
487- c . compilerDirPartialPath ,
488- cmiPartialPath
489- ) ;
490- let cmiAvailable = fs . existsSync ( cmiPath ) ;
491-
492- if ( ! cmiAvailable ) {
467+ } else
468+ if ( extension !== c . resExt ) {
493469 let params : p . ShowMessageParams = {
494470 type : p . MessageType . Error ,
495- message : `No compiled interface file found. Please compile your project first .` ,
471+ message : `Not a ${ c . resExt } file. Cannot create an interface for it .` ,
496472 } ;
497473
498474 let response : m . NotificationMessage = {
499475 jsonrpc : c . jsonrpcVersion ,
500476 method : "window/showMessage" ,
501- params,
477+ params : params ,
502478 } ;
503479
504480 return response ;
505481 } else {
506- let intfResult = utils . createInterfaceFileUsingValidBscExePath (
507- filePath ,
508- cmiPath ,
509- bscNativePath
482+ let cmiPartialPath = utils . replaceFileExtension (
483+ filePath . split ( projDir ) [ 1 ] ,
484+ c . cmiExt
510485 ) ;
486+ let cmiPath = path . join (
487+ projDir ,
488+ c . compilerDirPartialPath ,
489+ cmiPartialPath
490+ ) ;
491+ let cmiAvailable = fs . existsSync ( cmiPath ) ;
511492
512- if ( intfResult . kind === "success" ) {
513- let response : m . ResponseMessage = {
514- jsonrpc : c . jsonrpcVersion ,
515- id : msg . id ,
516- result : intfResult . result ,
493+ if ( ! cmiAvailable ) {
494+ let params : p . ShowMessageParams = {
495+ type : p . MessageType . Error ,
496+ message : `No compiled interface file found. Please compile your project first.` ,
517497 } ;
518498
519- return response ;
520- } else {
521- let response : m . ResponseMessage = {
499+ let response : m . NotificationMessage = {
522500 jsonrpc : c . jsonrpcVersion ,
523- id : msg . id ,
524- error : {
525- code : m . ErrorCodes . InternalError ,
526- message : "Unable to create interface file." ,
527- } ,
501+ method : "window/showMessage" ,
502+ params,
528503 } ;
529504
530505 return response ;
506+ } else {
507+ let intfResult = utils . createInterfaceFileUsingValidBscExePath (
508+ filePath ,
509+ cmiPath ,
510+ bscNativePath
511+ ) ;
512+
513+ if ( intfResult . kind === "success" ) {
514+ let response : m . ResponseMessage = {
515+ jsonrpc : c . jsonrpcVersion ,
516+ id : msg . id ,
517+ result : intfResult . result ,
518+ } ;
519+
520+ return response ;
521+ } else {
522+ let response : m . ResponseMessage = {
523+ jsonrpc : c . jsonrpcVersion ,
524+ id : msg . id ,
525+ error : {
526+ code : m . ErrorCodes . InternalError ,
527+ message : "Unable to create interface file." ,
528+ } ,
529+ } ;
530+
531+ return response ;
532+ }
531533 }
532534 }
533- }
534535}
535536
536537function onMessage ( msg : m . Message ) {
0 commit comments