@@ -20,6 +20,7 @@ import { DebugAdapterFactory } from "./debugger/debugAdapterFactory";
20
20
import { DebuggerCommunicationServer } from "./debuggerCommunicationServer" ;
21
21
import * as utils from "./extension_utils/utils" ;
22
22
import { SerialMonitor } from "./serialMonitor" ;
23
+ import { DebuggerCommunicationService } from "./service/debuggerCommunicationService" ;
23
24
import { MessagingService } from "./service/messagingService" ;
24
25
import { SimulatorDebugConfigurationProvider } from "./simulatorDebugConfigurationProvider" ;
25
26
import TelemetryAI from "./telemetry/telemetryAI" ;
@@ -32,12 +33,12 @@ let telemetryAI: TelemetryAI;
32
33
let pythonExecutableName : string = "python" ;
33
34
let configFileCreated : boolean = false ;
34
35
let inDebugMode : boolean = false ;
35
- let debuggerCommunicationHandler : DebuggerCommunicationServer ;
36
36
// Notification booleans
37
37
let firstTimeClosed : boolean = true ;
38
38
let shouldShowInvalidFileNamePopup : boolean = true ;
39
39
let shouldShowRunCodePopup : boolean = true ;
40
40
const messagingService = new MessagingService ( ) ;
41
+ const debuggerCommunicationService = new DebuggerCommunicationService ( ) ;
41
42
42
43
let currentActiveDevice : string = DEFAULT_DEVICE ;
43
44
@@ -181,11 +182,11 @@ export async function activate(context: vscode.ExtensionContext) {
181
182
console . log ( `About to write ${ messageJson } \n` ) ;
182
183
if (
183
184
inDebugMode &&
184
- debuggerCommunicationHandler
185
+ debuggerCommunicationService . getCurrentDebuggerServer ( )
185
186
) {
186
- debuggerCommunicationHandler . emitInputChanged (
187
- messageJson
188
- ) ;
187
+ debuggerCommunicationService
188
+ . getCurrentDebuggerServer ( )
189
+ . emitInputChanged ( messageJson ) ;
189
190
} else if ( childProcess ) {
190
191
childProcess . stdin . write (
191
192
messageJson + "\n"
@@ -228,11 +229,11 @@ export async function activate(context: vscode.ExtensionContext) {
228
229
console . log ( `Sensor changed ${ messageJson } \n` ) ;
229
230
if (
230
231
inDebugMode &&
231
- debuggerCommunicationHandler
232
+ debuggerCommunicationService . getCurrentDebuggerServer ( )
232
233
) {
233
- debuggerCommunicationHandler . emitInputChanged (
234
- messageJson
235
- ) ;
234
+ debuggerCommunicationService
235
+ . getCurrentDebuggerServer ( )
236
+ . emitInputChanged ( messageJson ) ;
236
237
} else if ( childProcess ) {
237
238
childProcess . stdin . write (
238
239
messageJson + "\n"
@@ -271,8 +272,12 @@ export async function activate(context: vscode.ExtensionContext) {
271
272
currentPanel . onDidDispose (
272
273
( ) => {
273
274
currentPanel = undefined ;
274
- if ( debuggerCommunicationHandler ) {
275
- debuggerCommunicationHandler . setWebview ( undefined ) ;
275
+ if (
276
+ debuggerCommunicationService . getCurrentDebuggerServer ( )
277
+ ) {
278
+ debuggerCommunicationService
279
+ . getCurrentDebuggerServer ( )
280
+ . setWebview ( undefined ) ;
276
281
}
277
282
killProcessIfRunning ( ) ;
278
283
if ( firstTimeClosed ) {
@@ -921,7 +926,8 @@ export async function activate(context: vscode.ExtensionContext) {
921
926
922
927
const debugAdapterFactory = new DebugAdapterFactory (
923
928
vscode . debug . activeDebugSession ,
924
- messagingService
929
+ messagingService ,
930
+ debuggerCommunicationService
925
931
) ;
926
932
vscode . debug . registerDebugAdapterTrackerFactory (
927
933
"python" ,
@@ -932,27 +938,29 @@ export async function activate(context: vscode.ExtensionContext) {
932
938
if ( simulatorDebugConfiguration . deviceSimulatorExpressDebug ) {
933
939
// Reinitialize process
934
940
killProcessIfRunning ( ) ;
935
- console . log ( "Debug Started" ) ;
936
941
inDebugMode = true ;
937
942
938
943
try {
939
944
// Shut down existing server on debug restart
940
- if ( debuggerCommunicationHandler ) {
941
- debuggerCommunicationHandler . closeConnection ( ) ;
942
- debuggerCommunicationHandler = undefined ;
945
+ if ( debuggerCommunicationService . getCurrentDebuggerServer ( ) ) {
946
+ debuggerCommunicationService . resetCurrentDebuggerServer ( ) ;
943
947
}
944
948
945
- debuggerCommunicationHandler = new DebuggerCommunicationServer (
946
- currentPanel ,
947
- utils . getServerPortConfig ( ) ,
948
- currentActiveDevice
949
+ debuggerCommunicationService . setCurrentDebuggerServer (
950
+ new DebuggerCommunicationServer (
951
+ currentPanel ,
952
+ utils . getServerPortConfig ( ) ,
953
+ currentActiveDevice
954
+ )
949
955
) ;
950
956
951
957
handleDebuggerTelemetry ( ) ;
952
958
953
959
openWebview ( ) ;
954
960
if ( currentPanel ) {
955
- debuggerCommunicationHandler . setWebview ( currentPanel ) ;
961
+ debuggerCommunicationService
962
+ . getCurrentDebuggerServer ( )
963
+ . setWebview ( currentPanel ) ;
956
964
currentPanel . webview . postMessage ( {
957
965
currentActiveDevice,
958
966
command : "activate-play" ,
@@ -982,9 +990,8 @@ export async function activate(context: vscode.ExtensionContext) {
982
990
console . log ( "Debug Stopped" ) ;
983
991
inDebugMode = false ;
984
992
simulatorDebugConfiguration . deviceSimulatorExpressDebug = false ;
985
- if ( debuggerCommunicationHandler ) {
986
- debuggerCommunicationHandler . closeConnection ( ) ;
987
- debuggerCommunicationHandler = undefined ;
993
+ if ( debuggerCommunicationService . getCurrentDebuggerServer ( ) ) {
994
+ debuggerCommunicationService . resetCurrentDebuggerServer ( ) ;
988
995
}
989
996
if ( currentPanel ) {
990
997
currentPanel . webview . postMessage ( {
0 commit comments