1- /// <reference types="node" />
21/// <reference path="shared.ts" />
32/// <reference path="session.ts" />
43
@@ -7,7 +6,7 @@ namespace ts.server {
76 host : ServerHost ;
87 cancellationToken : ServerCancellationToken ;
98 canUseEvents : boolean ;
10- installerEventPort : number ;
9+ eventPort : number ;
1110 useSingleInferredProject : boolean ;
1211 useInferredProjectPerProjectRoot : boolean ;
1312 disableAutomaticTypingAcquisition : boolean ;
@@ -22,10 +21,6 @@ namespace ts.server {
2221 allowLocalPluginLoads : boolean ;
2322 }
2423
25- const net : {
26- connect ( options : { port : number } , onConnect ?: ( ) => void ) : NodeSocket
27- } = require ( "net" ) ;
28-
2924 const childProcess : {
3025 fork ( modulePath : string , args : string [ ] , options ?: { execArgv : string [ ] , env ?: MapLike < string > } ) : NodeChildProcess ;
3126 execFileSync ( file : string , args : string [ ] , options : { stdio : "ignore" , env : MapLike < string > } ) : string | Buffer ;
@@ -83,10 +78,6 @@ namespace ts.server {
8378 pid : number ;
8479 }
8580
86- interface NodeSocket {
87- write ( data : string , encoding : string ) : boolean ;
88- }
89-
9081 interface ReadLineOptions {
9182 input : NodeJS . ReadableStream ;
9283 output ?: NodeJS . WritableStream ;
@@ -244,9 +235,8 @@ namespace ts.server {
244235 class NodeTypingsInstaller implements ITypingsInstaller {
245236 private installer : NodeChildProcess ;
246237 private installerPidReported = false ;
247- private socket : NodeSocket ;
248238 private projectService : ProjectService ;
249- private eventSender : EventSender ;
239+ private eventSender : EventSender | undefined ;
250240 private activeRequestCount = 0 ;
251241 private requestQueue : QueuedOperation [ ] = [ ] ;
252242 private requestMap = createMap < QueuedOperation > ( ) ; // Maps operation ID to newest requestQueue entry with that ID
@@ -267,18 +257,10 @@ namespace ts.server {
267257 private readonly telemetryEnabled : boolean ,
268258 private readonly logger : server . Logger ,
269259 private readonly host : ServerHost ,
270- eventPort : number ,
271260 readonly globalTypingsCacheLocation : string ,
272261 readonly typingSafeListLocation : string ,
273262 readonly typesMapLocation : string ,
274- private readonly npmLocation : string | undefined ,
275- private newLine : string ) {
276- if ( eventPort ) {
277- const s = net . connect ( { port : eventPort } , ( ) => {
278- this . socket = s ;
279- this . reportInstallerProcessId ( ) ;
280- } ) ;
281- }
263+ private readonly npmLocation : string | undefined ) {
282264 }
283265
284266 isKnownTypesPackageName ( name : string ) : boolean {
@@ -310,26 +292,23 @@ namespace ts.server {
310292 if ( this . installerPidReported ) {
311293 return ;
312294 }
313- if ( this . socket && this . installer ) {
314- this . sendEvent ( 0 , "typingsInstallerPid" , { pid : this . installer . pid } ) ;
295+ if ( this . installer && this . eventSender ) {
296+ this . eventSender . event ( { pid : this . installer . pid } , "typingsInstallerPid" ) ;
315297 this . installerPidReported = true ;
316298 }
317299 }
318300
319- private sendEvent ( seq : number , event : string , body : any ) : void {
320- this . socket . write ( formatMessage ( { seq, type : "event" , event, body } , this . logger , Buffer . byteLength , this . newLine ) , "utf8" ) ;
321- }
322301
323- setTelemetrySender ( telemetrySender : EventSender ) {
324- this . eventSender = telemetrySender ;
325- }
326-
327- attach ( projectService : ProjectService ) {
302+ attach ( projectService : ProjectService , eventSender ?: EventSender ) {
328303 this . projectService = projectService ;
329304 if ( this . logger . hasLevel ( LogLevel . requestTime ) ) {
330305 this . logger . info ( "Binding..." ) ;
331306 }
332307
308+ if ( eventSender ) {
309+ this . eventSender = eventSender ;
310+ }
311+
333312 const args : string [ ] = [ Arguments . GlobalCacheLocation , this . globalTypingsCacheLocation ] ;
334313 if ( this . telemetryEnabled ) {
335314 args . push ( Arguments . EnableTelemetry ) ;
@@ -353,10 +332,10 @@ namespace ts.server {
353332 if ( match ) {
354333 // if port is specified - use port + 1
355334 // otherwise pick a default port depending on if 'debug' or 'inspect' and use its value + 1
356- const currentPort = match [ 2 ] !== undefined
357- ? + match [ 2 ]
358- : match [ 1 ] . charAt ( 0 ) === "d" ? 5858 : 9229 ;
359- execArgv . push ( `--${ match [ 1 ] } =${ currentPort + 1 } ` ) ;
335+ // const currentPort = match[2] !== undefined
336+ // ? +match[2]
337+ // : match[1].charAt(0) === "d" ? 5858 : 9229;
338+ // execArgv.push(`--${match[1]}=${currentPort + 1}`);
360339 break ;
361340 }
362341 }
@@ -508,8 +487,8 @@ namespace ts.server {
508487
509488 this . projectService . updateTypingsForProject ( response ) ;
510489
511- if ( this . socket ) {
512- this . sendEvent ( 0 , "setTypings" , response ) ;
490+ if ( this . eventSender ) {
491+ this . eventSender . event ( response , "setTypings" ) ;
513492 }
514493
515494 break ;
@@ -530,10 +509,10 @@ namespace ts.server {
530509
531510 class IOSession extends Session {
532511 constructor ( options : IoSessionOptions ) {
533- const { host, installerEventPort , globalTypingsCacheLocation, typingSafeListLocation, typesMapLocation, npmLocation, canUseEvents } = options ;
512+ const { host, eventPort , globalTypingsCacheLocation, typingSafeListLocation, typesMapLocation, npmLocation, canUseEvents } = options ;
534513 const typingsInstaller = disableAutomaticTypingAcquisition
535514 ? undefined
536- : new NodeTypingsInstaller ( telemetryEnabled , logger , host , installerEventPort , globalTypingsCacheLocation , typingSafeListLocation , typesMapLocation , npmLocation , host . newLine ) ;
515+ : new NodeTypingsInstaller ( telemetryEnabled , logger , host , globalTypingsCacheLocation , typingSafeListLocation , typesMapLocation , npmLocation ) ;
537516
538517 super ( {
539518 host,
@@ -545,13 +524,10 @@ namespace ts.server {
545524 hrtime : process . hrtime ,
546525 logger,
547526 canUseEvents,
527+ eventPort,
548528 globalPlugins : options . globalPlugins ,
549529 pluginProbeLocations : options . pluginProbeLocations ,
550530 allowLocalPluginLoads : options . allowLocalPluginLoads } ) ;
551-
552- if ( telemetryEnabled && typingsInstaller ) {
553- typingsInstaller . setTelemetrySender ( this ) ;
554- }
555531 }
556532
557533 exit ( ) {
@@ -936,8 +912,8 @@ namespace ts.server {
936912 const options : IoSessionOptions = {
937913 host : sys ,
938914 cancellationToken,
939- installerEventPort : eventPort ,
940- canUseEvents : eventPort === undefined ,
915+ eventPort,
916+ canUseEvents : true ,
941917 useSingleInferredProject,
942918 useInferredProjectPerProjectRoot,
943919 disableAutomaticTypingAcquisition,
0 commit comments