@@ -233,7 +233,7 @@ namespace ts.server {
233233
234234 // Override sys.write because fs.writeSync is not reliable on Node 4
235235 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.
237237 // The advantage of polling is that it works reliably
238238 // on all os and with network mounted files.
239239 // For 90 referenced files, the average time to detect
@@ -759,12 +759,40 @@ namespace ts.server {
759759 }
760760 }
761761
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+
762789 const eventPort : number | undefined = parseEventPort ( findArgument ( "--eventPort" ) ) ;
763790 const typingSafeListLocation = findArgument ( Arguments . TypingSafeListLocation ) ! ; // TODO: GH#18217
764791 const typesMapLocation = findArgument ( Arguments . TypesMapLocation ) || combinePaths ( getDirectoryPath ( sys . getExecutingFilePath ( ) ) , "typesMap.json" ) ;
765792 const npmLocation = findArgument ( Arguments . NpmLocation ) ;
766793 const validateDefaultNpmLocation = hasArgument ( Arguments . ValidateDefaultNpmLocation ) ;
767794 const disableAutomaticTypingAcquisition = hasArgument ( "--disableAutomaticTypingAcquisition" ) ;
795+ const useNodeIpc = hasArgument ( "--useNodeIpc" ) ;
768796 const telemetryEnabled = hasArgument ( Arguments . EnableTelemetry ) ;
769797 const commandLineTraceDir = findArgument ( "--traceDirectory" ) ;
770798 const traceDir = commandLineTraceDir
@@ -774,7 +802,7 @@ namespace ts.server {
774802 startTracing ( "server" , traceDir ) ;
775803 }
776804
777- const ioSession = new IOSession ( ) ;
805+ const ioSession = useNodeIpc ? new IpcIOSession ( ) : new IOSession ( ) ;
778806 process . on ( "uncaughtException" , err => {
779807 ioSession . logError ( err , "unknown" ) ;
780808 } ) ;
0 commit comments