@@ -434,11 +434,13 @@ function createInterface(msg: p.RequestMessage): m.Message {
434
434
let filePath = fileURLToPath ( params . uri ) ;
435
435
let bscNativePath = utils . findBscNativeOfFile ( filePath ) ;
436
436
let projDir = utils . findProjectRootOfFile ( filePath ) ;
437
+ let code = getOpenedFileContent ( params . uri ) ;
438
+ let isReactComponent = code . includes ( "@react.component" ) ;
437
439
438
- if ( bscNativePath === null || projDir === null ) {
440
+ if ( isReactComponent ) {
439
441
let params : p . ShowMessageParams = {
440
442
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 .` ,
442
444
} ;
443
445
444
446
let response : m . NotificationMessage = {
@@ -448,73 +450,87 @@ function createInterface(msg: p.RequestMessage): m.Message {
448
450
} ;
449
451
450
452
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
+ } ;
462
459
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
+ } ;
475
465
476
- if ( ! cmiAvailable ) {
466
+ return response ;
467
+ } else if ( extension !== c . resExt ) {
477
468
let params : p . ShowMessageParams = {
478
469
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 .` ,
480
471
} ;
481
472
482
473
let response : m . NotificationMessage = {
483
474
jsonrpc : c . jsonrpcVersion ,
484
475
method : "window/showMessage" ,
485
- params,
476
+ params : params ,
486
477
} ;
487
478
488
479
return response ;
489
480
} 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
494
484
) ;
485
+ let cmiPath = path . join (
486
+ projDir ,
487
+ c . compilerDirPartialPath ,
488
+ cmiPartialPath
489
+ ) ;
490
+ let cmiAvailable = fs . existsSync ( cmiPath ) ;
495
491
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.` ,
501
496
} ;
502
497
503
- return response ;
504
- } else {
505
- let response : m . ResponseMessage = {
498
+ let response : m . NotificationMessage = {
506
499
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,
512
502
} ;
513
503
514
504
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
+ }
515
532
}
516
533
}
517
- }
518
534
}
519
535
520
536
function onMessage ( msg : m . Message ) {
0 commit comments