1
1
/// <reference types="node" />
2
+ /// <reference path="shared.ts" />
2
3
/// <reference path="session.ts" />
3
4
// used in fs.writeSync
4
5
/* tslint:disable:no-null-keyword */
@@ -17,7 +18,6 @@ namespace ts.server {
17
18
homedir ( ) : string
18
19
} = require ( "os" ) ;
19
20
20
-
21
21
function getGlobalTypingsCacheLocation ( ) {
22
22
let basePath : string ;
23
23
switch ( process . platform ) {
@@ -184,8 +184,10 @@ namespace ts.server {
184
184
private socket : NodeSocket ;
185
185
private projectService : ProjectService ;
186
186
private throttledOperations : ThrottledOperations ;
187
+ private telemetrySender : EventSender ;
187
188
188
189
constructor (
190
+ private readonly telemetryEnabled : boolean ,
189
191
private readonly logger : server . Logger ,
190
192
host : ServerHost ,
191
193
eventPort : number ,
@@ -214,15 +216,22 @@ namespace ts.server {
214
216
this . socket . write ( formatMessage ( { seq, type : "event" , event, body } , this . logger , Buffer . byteLength , this . newLine ) , "utf8" ) ;
215
217
}
216
218
219
+ setTelemetrySender ( telemetrySender : EventSender ) {
220
+ this . telemetrySender = telemetrySender ;
221
+ }
222
+
217
223
attach ( projectService : ProjectService ) {
218
224
this . projectService = projectService ;
219
225
if ( this . logger . hasLevel ( LogLevel . requestTime ) ) {
220
226
this . logger . info ( "Binding..." ) ;
221
227
}
222
228
223
- const args : string [ ] = [ "--globalTypingsCacheLocation" , this . globalTypingsCacheLocation ] ;
229
+ const args : string [ ] = [ Arguments . GlobalCacheLocation , this . globalTypingsCacheLocation ] ;
230
+ if ( this . telemetryEnabled ) {
231
+ args . push ( Arguments . EnableTelemetry ) ;
232
+ }
224
233
if ( this . logger . loggingEnabled ( ) && this . logger . getLogFileName ( ) ) {
225
- args . push ( "--logFile" , combinePaths ( getDirectoryPath ( normalizeSlashes ( this . logger . getLogFileName ( ) ) ) , `ti-${ process . pid } .log` ) ) ;
234
+ args . push ( Arguments . LogFile , combinePaths ( getDirectoryPath ( normalizeSlashes ( this . logger . getLogFileName ( ) ) ) , `ti-${ process . pid } .log` ) ) ;
226
235
}
227
236
const execArgv : string [ ] = [ ] ;
228
237
{
@@ -268,12 +277,25 @@ namespace ts.server {
268
277
} ) ;
269
278
}
270
279
271
- private handleMessage ( response : SetTypings | InvalidateCachedTypings ) {
280
+ private handleMessage ( response : SetTypings | InvalidateCachedTypings | TypingsInstallEvent ) {
272
281
if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
273
282
this . logger . info ( `Received response: ${ JSON . stringify ( response ) } ` ) ;
274
283
}
284
+ if ( response . kind === EventInstall ) {
285
+ if ( this . telemetrySender ) {
286
+ const body : protocol . TypingsInstalledTelemetryEventBody = {
287
+ telemetryEventName : "typingsInstalled" ,
288
+ payload : {
289
+ installedPackages : response . packagesToInstall . join ( "," )
290
+ }
291
+ } ;
292
+ const eventName : protocol . TelemetryEventName = "telemetry" ;
293
+ this . telemetrySender . event ( body , eventName ) ;
294
+ }
295
+ return ;
296
+ }
275
297
this . projectService . updateTypingsForProject ( response ) ;
276
- if ( response . kind == "set" && this . socket ) {
298
+ if ( response . kind == ActionSet && this . socket ) {
277
299
this . sendEvent ( 0 , "setTypings" , response ) ;
278
300
}
279
301
}
@@ -288,18 +310,25 @@ namespace ts.server {
288
310
useSingleInferredProject : boolean ,
289
311
disableAutomaticTypingAcquisition : boolean ,
290
312
globalTypingsCacheLocation : string ,
313
+ telemetryEnabled : boolean ,
291
314
logger : server . Logger ) {
292
- super (
293
- host ,
294
- cancellationToken ,
295
- useSingleInferredProject ,
296
- disableAutomaticTypingAcquisition
297
- ? nullTypingsInstaller
298
- : new NodeTypingsInstaller ( logger , host , installerEventPort , globalTypingsCacheLocation , host . newLine ) ,
299
- Buffer . byteLength ,
300
- process . hrtime ,
301
- logger ,
302
- canUseEvents ) ;
315
+ const typingsInstaller = disableAutomaticTypingAcquisition
316
+ ? undefined
317
+ : new NodeTypingsInstaller ( telemetryEnabled , logger , host , installerEventPort , globalTypingsCacheLocation , host . newLine ) ;
318
+
319
+ super (
320
+ host ,
321
+ cancellationToken ,
322
+ useSingleInferredProject ,
323
+ typingsInstaller || nullTypingsInstaller ,
324
+ Buffer . byteLength ,
325
+ process . hrtime ,
326
+ logger ,
327
+ canUseEvents ) ;
328
+
329
+ if ( telemetryEnabled && typingsInstaller ) {
330
+ typingsInstaller . setTelemetrySender ( this ) ;
331
+ }
303
332
}
304
333
305
334
exit ( ) {
@@ -526,17 +555,17 @@ namespace ts.server {
526
555
527
556
let eventPort : number ;
528
557
{
529
- const index = sys . args . indexOf ( "--eventPort" ) ;
530
- if ( index >= 0 && index < sys . args . length - 1 ) {
531
- const v = parseInt ( sys . args [ index + 1 ] ) ;
532
- if ( ! isNaN ( v ) ) {
533
- eventPort = v ;
534
- }
558
+ const str = findArgument ( "--eventPort" ) ;
559
+ const v = str && parseInt ( str ) ;
560
+ if ( ! isNaN ( v ) ) {
561
+ eventPort = v ;
535
562
}
536
563
}
537
564
538
- const useSingleInferredProject = sys . args . indexOf ( "--useSingleInferredProject" ) >= 0 ;
539
- const disableAutomaticTypingAcquisition = sys . args . indexOf ( "--disableAutomaticTypingAcquisition" ) >= 0 ;
565
+ const useSingleInferredProject = hasArgument ( "--useSingleInferredProject" ) ;
566
+ const disableAutomaticTypingAcquisition = hasArgument ( "--disableAutomaticTypingAcquisition" ) ;
567
+ const telemetryEnabled = hasArgument ( Arguments . EnableTelemetry ) ;
568
+
540
569
const ioSession = new IOSession (
541
570
sys ,
542
571
cancellationToken ,
@@ -545,6 +574,7 @@ namespace ts.server {
545
574
useSingleInferredProject ,
546
575
disableAutomaticTypingAcquisition ,
547
576
getGlobalTypingsCacheLocation ( ) ,
577
+ telemetryEnabled ,
548
578
logger ) ;
549
579
process . on ( "uncaughtException" , function ( err : Error ) {
550
580
ioSession . logError ( err , "unknown" ) ;
0 commit comments