@@ -380,84 +380,96 @@ namespace ts.server {
380380 this . logger . info ( `Received response: ${ JSON . stringify ( response ) } ` ) ;
381381 }
382382
383- if ( response . kind === EventInitializationFailed ) {
384- if ( ! this . eventSender ) {
385- return ;
386- }
387- const body : protocol . TypesInstallerInitializationFailedEventBody = {
388- message : response . message
389- } ;
390- const eventName : protocol . TypesInstallerInitializationFailedEventName = "typesInstallerInitializationFailed" ;
391- this . eventSender . event ( body , eventName ) ;
392- return ;
393- }
394-
395- if ( response . kind === EventBeginInstallTypes ) {
396- if ( ! this . eventSender ) {
397- return ;
398- }
399- const body : protocol . BeginInstallTypesEventBody = {
400- eventId : response . eventId ,
401- packages : response . packagesToInstall ,
402- } ;
403- const eventName : protocol . BeginInstallTypesEventName = "beginInstallTypes" ;
404- this . eventSender . event ( body , eventName ) ;
405-
406- return ;
407- }
408-
409- if ( response . kind === EventEndInstallTypes ) {
410- if ( ! this . eventSender ) {
411- return ;
383+ switch ( response . kind ) {
384+ case EventInitializationFailed :
385+ {
386+ if ( ! this . eventSender ) {
387+ break ;
388+ }
389+ const body : protocol . TypesInstallerInitializationFailedEventBody = {
390+ message : response . message
391+ } ;
392+ const eventName : protocol . TypesInstallerInitializationFailedEventName = "typesInstallerInitializationFailed" ;
393+ this . eventSender . event ( body , eventName ) ;
394+ break ;
412395 }
413- if ( this . telemetryEnabled ) {
414- const body : protocol . TypingsInstalledTelemetryEventBody = {
415- telemetryEventName : "typingsInstalled" ,
416- payload : {
417- installedPackages : response . packagesToInstall . join ( "," ) ,
418- installSuccess : response . installSuccess ,
419- typingsInstallerVersion : response . typingsInstallerVersion
420- }
396+ case EventBeginInstallTypes :
397+ {
398+ if ( ! this . eventSender ) {
399+ break ;
400+ }
401+ const body : protocol . BeginInstallTypesEventBody = {
402+ eventId : response . eventId ,
403+ packages : response . packagesToInstall ,
421404 } ;
422- const eventName : protocol . TelemetryEventName = "telemetry " ;
405+ const eventName : protocol . BeginInstallTypesEventName = "beginInstallTypes " ;
423406 this . eventSender . event ( body , eventName ) ;
407+ break ;
424408 }
409+ case EventEndInstallTypes :
410+ {
411+ if ( ! this . eventSender ) {
412+ break ;
413+ }
414+ if ( this . telemetryEnabled ) {
415+ const body : protocol . TypingsInstalledTelemetryEventBody = {
416+ telemetryEventName : "typingsInstalled" ,
417+ payload : {
418+ installedPackages : response . packagesToInstall . join ( "," ) ,
419+ installSuccess : response . installSuccess ,
420+ typingsInstallerVersion : response . typingsInstallerVersion
421+ }
422+ } ;
423+ const eventName : protocol . TelemetryEventName = "telemetry" ;
424+ this . eventSender . event ( body , eventName ) ;
425+ }
425426
426- const body : protocol . EndInstallTypesEventBody = {
427- eventId : response . eventId ,
428- packages : response . packagesToInstall ,
429- success : response . installSuccess ,
430- } ;
431- const eventName : protocol . EndInstallTypesEventName = "endInstallTypes" ;
432- this . eventSender . event ( body , eventName ) ;
433- return ;
434- }
435-
436- if ( response . kind === ActionSet ) {
437- if ( this . activeRequestCount > 0 ) {
438- this . activeRequestCount -- ;
427+ const body : protocol . EndInstallTypesEventBody = {
428+ eventId : response . eventId ,
429+ packages : response . packagesToInstall ,
430+ success : response . installSuccess ,
431+ } ;
432+ const eventName : protocol . EndInstallTypesEventName = "endInstallTypes" ;
433+ this . eventSender . event ( body , eventName ) ;
434+ break ;
439435 }
440- else {
441- Debug . fail ( "Received too many responses" ) ;
436+ case ActionInvalidate :
437+ {
438+ this . projectService . updateTypingsForProject ( response ) ;
439+ break ;
442440 }
441+ case ActionSet :
442+ {
443+ if ( this . activeRequestCount > 0 ) {
444+ this . activeRequestCount -- ;
445+ }
446+ else {
447+ Debug . fail ( "Received too many responses" ) ;
448+ }
443449
444- while ( this . requestQueue . length > 0 ) {
445- const queuedRequest = this . requestQueue . shift ( ) ;
446- if ( this . requestMap . get ( queuedRequest . operationId ) === queuedRequest ) {
447- this . requestMap . delete ( queuedRequest . operationId ) ;
448- this . scheduleRequest ( queuedRequest ) ;
449- break ;
450+ while ( this . requestQueue . length > 0 ) {
451+ const queuedRequest = this . requestQueue . shift ( ) ;
452+ if ( this . requestMap . get ( queuedRequest . operationId ) === queuedRequest ) {
453+ this . requestMap . delete ( queuedRequest . operationId ) ;
454+ this . scheduleRequest ( queuedRequest ) ;
455+ break ;
456+ }
457+
458+ if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
459+ this . logger . info ( `Skipping defunct request for: ${ queuedRequest . operationId } ` ) ;
460+ }
450461 }
451462
452- if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
453- this . logger . info ( `Skipping defunct request for: ${ queuedRequest . operationId } ` ) ;
463+ this . projectService . updateTypingsForProject ( response ) ;
464+
465+ if ( this . socket ) {
466+ this . sendEvent ( 0 , "setTypings" , response ) ;
454467 }
455- }
456- }
457468
458- this . projectService . updateTypingsForProject ( response ) ;
459- if ( response . kind === ActionSet && this . socket ) {
460- this . sendEvent ( 0 , "setTypings" , response ) ;
469+ break ;
470+ }
471+ default :
472+ assertTypeIsNever ( response ) ;
461473 }
462474 }
463475
0 commit comments