11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33'use strict' ;
4- import { injectable } from 'inversify' ;
5- import { DebugSession , Event , EventEmitter } from 'vscode' ;
4+ import { DebugAdapterTracker , Event , EventEmitter } from 'vscode' ;
65import { DebugProtocol } from 'vscode-debugprotocol' ;
76
8- import { StopWatch } from '../common/utils/stopWatch' ;
9- import { AttachRequestArguments , ConsoleType , LaunchRequestArguments , TriggerType } from '../debugger/types' ;
10- import { sendTelemetryEvent } from '../telemetry' ;
11- import { EventName } from '../telemetry/constants' ;
12- import { IDebugLocation , IDebugLocationTracker } from './types' ;
7+ import { IDebugLocation } from './types' ;
138
149// When a python debugging session is active keep track of the current debug location
15- @injectable ( )
16- export class DebugLocationTracker implements IDebugLocationTracker {
10+ export class DebugLocationTracker implements DebugAdapterTracker {
1711 private waitingForStackTrace : boolean = false ;
1812 private _debugLocation : IDebugLocation | undefined ;
1913 private debugLocationUpdatedEvent : EventEmitter < void > = new EventEmitter < void > ( ) ;
20- private trigger : TriggerType = 'launch' ;
21- private console : ConsoleType | undefined ;
22- private timer = new StopWatch ( ) ;
14+ private sessionEndedEmitter : EventEmitter < DebugLocationTracker > = new EventEmitter < DebugLocationTracker > ( ) ;
2315
24- public setDebugSession ( targetSession : DebugSession ) {
16+ constructor ( private _sessionId : string ) {
2517 this . DebugLocation = undefined ;
26- this . waitingForStackTrace = false ;
27- this . trigger = targetSession . configuration . type as TriggerType ;
28- const debugConfiguration = targetSession . configuration as Partial < LaunchRequestArguments & AttachRequestArguments > ;
29- this . console = debugConfiguration . console ;
18+ }
19+
20+ public get sessionId ( ) {
21+ return this . _sessionId ;
22+ }
23+
24+ public get sessionEnded ( ) : Event < DebugLocationTracker > {
25+ return this . sessionEndedEmitter . event ;
3026 }
3127
3228 public get debugLocationUpdated ( ) : Event < void > {
@@ -37,20 +33,8 @@ export class DebugLocationTracker implements IDebugLocationTracker {
3733 return this . _debugLocation ;
3834 }
3935
40- public onWillStartSession ( ) {
41- this . sendTelemetry ( EventName . DEBUG_SESSION_START ) ;
42- }
43-
4436 // tslint:disable-next-line:no-any
4537 public onDidSendMessage ( message : DebugProtocol . ProtocolMessage ) {
46- if ( message . type === 'response' ) {
47- const response = message as DebugProtocol . Response ;
48- if ( response . command === 'configurationDone' ) {
49- // "configurationDone" response is sent immediately after user code starts running.
50- this . sendTelemetry ( EventName . DEBUG_SESSION_USER_CODE_RUNNING ) ;
51- }
52- }
53-
5438 if ( this . isStopEvent ( message ) ) {
5539 // Some type of stop, wait to see our next stack trace to find our location
5640 this . waitingForStackTrace = true ;
@@ -70,15 +54,10 @@ export class DebugLocationTracker implements IDebugLocationTracker {
7054 this . waitingForStackTrace = false ;
7155 }
7256 }
73-
7457 }
7558
7659 public onWillStopSession ( ) {
77- this . sendTelemetry ( EventName . DEBUG_SESSION_STOP ) ;
78- }
79-
80- public onError ?( _error : Error ) {
81- this . sendTelemetry ( EventName . DEBUG_SESSION_ERROR ) ;
60+ this . sessionEndedEmitter . fire ( this ) ;
8261 }
8362
8463 // Set our new location and fire our debug event
@@ -146,15 +125,4 @@ export class DebugLocationTracker implements IDebugLocationTracker {
146125
147126 return false ;
148127 }
149-
150- private sendTelemetry ( eventName : EventName ) {
151- if ( eventName === EventName . DEBUG_SESSION_START ) {
152- this . timer . reset ( ) ;
153- }
154- const telemetryProps = {
155- trigger : this . trigger ,
156- console : this . console
157- } ;
158- sendTelemetryEvent ( eventName , this . timer . elapsedTime , telemetryProps ) ;
159- }
160128}
0 commit comments