@@ -233,7 +233,7 @@ namespace ts.server {
233
233
234
234
// Override sys.write because fs.writeSync is not reliable on Node 4
235
235
sys . write = ( s : string ) => writeMessage ( sys . bufferFrom ! ( s , "utf8" ) as globalThis . Buffer ) ;
236
- // REVIEW: for now this implementation uses polling.
236
+ // REVIEW: for now this implementation uses polling.
237
237
// The advantage of polling is that it works reliably
238
238
// on all os and with network mounted files.
239
239
// For 90 referenced files, the average time to detect
@@ -759,12 +759,40 @@ namespace ts.server {
759
759
}
760
760
}
761
761
762
+ class IpcIOSession extends IOSession {
763
+
764
+ protected writeMessage ( msg : protocol . Message ) : void {
765
+ const verboseLogging = logger . hasLevel ( LogLevel . verbose ) ;
766
+ if ( verboseLogging ) {
767
+ const json = JSON . stringify ( msg ) ;
768
+ logger . info ( `${ msg . type } :${ indent ( json ) } ` ) ;
769
+ }
770
+
771
+ process . send ! ( msg ) ;
772
+ }
773
+
774
+ protected parseMessage ( message : any ) : protocol . Request {
775
+ return message as protocol . Request ;
776
+ }
777
+
778
+ protected toStringMessage ( message : any ) {
779
+ return JSON . stringify ( message , undefined , 2 ) ;
780
+ }
781
+
782
+ public listen ( ) {
783
+ process . on ( "message" , ( e : any ) => {
784
+ this . onMessage ( e ) ;
785
+ } ) ;
786
+ }
787
+ }
788
+
762
789
const eventPort : number | undefined = parseEventPort ( findArgument ( "--eventPort" ) ) ;
763
790
const typingSafeListLocation = findArgument ( Arguments . TypingSafeListLocation ) ! ; // TODO: GH#18217
764
791
const typesMapLocation = findArgument ( Arguments . TypesMapLocation ) || combinePaths ( getDirectoryPath ( sys . getExecutingFilePath ( ) ) , "typesMap.json" ) ;
765
792
const npmLocation = findArgument ( Arguments . NpmLocation ) ;
766
793
const validateDefaultNpmLocation = hasArgument ( Arguments . ValidateDefaultNpmLocation ) ;
767
794
const disableAutomaticTypingAcquisition = hasArgument ( "--disableAutomaticTypingAcquisition" ) ;
795
+ const useNodeIpc = hasArgument ( "--useNodeIpc" ) ;
768
796
const telemetryEnabled = hasArgument ( Arguments . EnableTelemetry ) ;
769
797
const commandLineTraceDir = findArgument ( "--traceDirectory" ) ;
770
798
const traceDir = commandLineTraceDir
@@ -774,7 +802,7 @@ namespace ts.server {
774
802
startTracing ( "server" , traceDir ) ;
775
803
}
776
804
777
- const ioSession = new IOSession ( ) ;
805
+ const ioSession = useNodeIpc ? new IpcIOSession ( ) : new IOSession ( ) ;
778
806
process . on ( "uncaughtException" , err => {
779
807
ioSession . logError ( err , "unknown" ) ;
780
808
} ) ;
0 commit comments