@@ -715,6 +715,24 @@ namespace ts.server {
715
715
this . constructed = true ;
716
716
}
717
717
718
+ public send ( msg : protocol . Message ) {
719
+ if ( useNodeIpc ) {
720
+ if ( msg . type === "event" && ! this . canUseEvents ) {
721
+ if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
722
+ this . logger . info ( `Session does not support events: ignored event: ${ JSON . stringify ( msg ) } ` ) ;
723
+ }
724
+ return ;
725
+ }
726
+ // TODO: Do we need any perf stuff here?
727
+ // const msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
728
+ // perfLogger.logEvent(`Response message size: ${msgText.length}`);
729
+ process . send ! ( msg ) ;
730
+ }
731
+ else {
732
+ super . send ( msg ) ;
733
+ }
734
+ }
735
+
718
736
event < T extends object > ( body : T , eventName : string ) : void {
719
737
Debug . assert ( ! ! this . constructed , "Should only call `IOSession.prototype.event` on an initialized IOSession" ) ;
720
738
@@ -748,14 +766,21 @@ namespace ts.server {
748
766
}
749
767
750
768
listen ( ) {
751
- rl . on ( "line" , ( input : string ) => {
752
- const message = input . trim ( ) ;
753
- this . onMessage ( message ) ;
754
- } ) ;
769
+ if ( useNodeIpc ) {
770
+ process . on ( 'message' , ( e : any ) => {
771
+ this . onMessage ( JSON . stringify ( e ) ) ; // TODO: should not convert to back to a string just to parse again :)
772
+ } ) ;
773
+ }
774
+ else {
775
+ rl . on ( "line" , ( input : string ) => {
776
+ const message = input . trim ( ) ;
777
+ this . onMessage ( message ) ;
778
+ } ) ;
755
779
756
- rl . on ( "close" , ( ) => {
757
- this . exit ( ) ;
758
- } ) ;
780
+ rl . on ( "close" , ( ) => {
781
+ this . exit ( ) ;
782
+ } ) ;
783
+ }
759
784
}
760
785
}
761
786
@@ -765,6 +790,7 @@ namespace ts.server {
765
790
const npmLocation = findArgument ( Arguments . NpmLocation ) ;
766
791
const validateDefaultNpmLocation = hasArgument ( Arguments . ValidateDefaultNpmLocation ) ;
767
792
const disableAutomaticTypingAcquisition = hasArgument ( "--disableAutomaticTypingAcquisition" ) ;
793
+ const useNodeIpc = hasArgument ( '--useNodeIpc' ) ;
768
794
const telemetryEnabled = hasArgument ( Arguments . EnableTelemetry ) ;
769
795
const commandLineTraceDir = findArgument ( "--traceDirectory" ) ;
770
796
const traceDir = commandLineTraceDir
0 commit comments