@@ -434,11 +434,13 @@ function createInterface(msg: p.RequestMessage): m.Message {
434434 let filePath = fileURLToPath ( params . uri ) ;
435435 let bscNativePath = utils . findBscNativeOfFile ( filePath ) ;
436436 let projDir = utils . findProjectRootOfFile ( filePath ) ;
437+ let code = getOpenedFileContent ( params . uri ) ;
438+ let isReactComponent = code . includes ( "@react.component" ) ;
437439
438- if ( bscNativePath === null || projDir === null ) {
440+ if ( isReactComponent ) {
439441 let params : p . ShowMessageParams = {
440442 type : p . MessageType . Error ,
441- message : `Cannot find a nearby bsc.exe to generate the interface file .` ,
443+ message : `Cannot create an interface for a file containing @react.component .` ,
442444 } ;
443445
444446 let response : m . NotificationMessage = {
@@ -448,73 +450,87 @@ function createInterface(msg: p.RequestMessage): m.Message {
448450 } ;
449451
450452 return response ;
451- } else if ( extension !== c . resExt ) {
452- let params : p . ShowMessageParams = {
453- type : p . MessageType . Error ,
454- message : `Not a ${ c . resExt } file. Cannot create an interface for it.` ,
455- } ;
456-
457- let response : m . NotificationMessage = {
458- jsonrpc : c . jsonrpcVersion ,
459- method : "window/showMessage" ,
460- params : params ,
461- } ;
453+ } else
454+ if ( bscNativePath === null || projDir === null ) {
455+ let params : p . ShowMessageParams = {
456+ type : p . MessageType . Error ,
457+ message : `Cannot find a nearby bsc.exe to generate the interface file.` ,
458+ } ;
462459
463- return response ;
464- } else {
465- let cmiPartialPath = utils . replaceFileExtension (
466- filePath . split ( projDir ) [ 1 ] ,
467- c . cmiExt
468- ) ;
469- let cmiPath = path . join (
470- projDir ,
471- c . compilerDirPartialPath ,
472- cmiPartialPath
473- ) ;
474- let cmiAvailable = fs . existsSync ( cmiPath ) ;
460+ let response : m . NotificationMessage = {
461+ jsonrpc : c . jsonrpcVersion ,
462+ method : "window/showMessage" ,
463+ params : params ,
464+ } ;
475465
476- if ( ! cmiAvailable ) {
466+ return response ;
467+ } else if ( extension !== c . resExt ) {
477468 let params : p . ShowMessageParams = {
478469 type : p . MessageType . Error ,
479- message : `No compiled interface file found. Please compile your project first .` ,
470+ message : `Not a ${ c . resExt } file. Cannot create an interface for it .` ,
480471 } ;
481472
482473 let response : m . NotificationMessage = {
483474 jsonrpc : c . jsonrpcVersion ,
484475 method : "window/showMessage" ,
485- params,
476+ params : params ,
486477 } ;
487478
488479 return response ;
489480 } else {
490- let intfResult = utils . createInterfaceFileUsingValidBscExePath (
491- filePath ,
492- cmiPath ,
493- bscNativePath
481+ let cmiPartialPath = utils . replaceFileExtension (
482+ filePath . split ( projDir ) [ 1 ] ,
483+ c . cmiExt
494484 ) ;
485+ let cmiPath = path . join (
486+ projDir ,
487+ c . compilerDirPartialPath ,
488+ cmiPartialPath
489+ ) ;
490+ let cmiAvailable = fs . existsSync ( cmiPath ) ;
495491
496- if ( intfResult . kind === "success" ) {
497- let response : m . ResponseMessage = {
498- jsonrpc : c . jsonrpcVersion ,
499- id : msg . id ,
500- result : intfResult . result ,
492+ if ( ! cmiAvailable ) {
493+ let params : p . ShowMessageParams = {
494+ type : p . MessageType . Error ,
495+ message : `No compiled interface file found. Please compile your project first.` ,
501496 } ;
502497
503- return response ;
504- } else {
505- let response : m . ResponseMessage = {
498+ let response : m . NotificationMessage = {
506499 jsonrpc : c . jsonrpcVersion ,
507- id : msg . id ,
508- error : {
509- code : m . ErrorCodes . InternalError ,
510- message : "Unable to create interface file." ,
511- } ,
500+ method : "window/showMessage" ,
501+ params,
512502 } ;
513503
514504 return response ;
505+ } else {
506+ let intfResult = utils . createInterfaceFileUsingValidBscExePath (
507+ filePath ,
508+ cmiPath ,
509+ bscNativePath
510+ ) ;
511+
512+ if ( intfResult . kind === "success" ) {
513+ let response : m . ResponseMessage = {
514+ jsonrpc : c . jsonrpcVersion ,
515+ id : msg . id ,
516+ result : intfResult . result ,
517+ } ;
518+
519+ return response ;
520+ } else {
521+ let response : m . ResponseMessage = {
522+ jsonrpc : c . jsonrpcVersion ,
523+ id : msg . id ,
524+ error : {
525+ code : m . ErrorCodes . InternalError ,
526+ message : "Unable to create interface file." ,
527+ } ,
528+ } ;
529+
530+ return response ;
531+ }
515532 }
516533 }
517- }
518534}
519535
520536function onMessage ( msg : m . Message ) {
0 commit comments