@@ -30,6 +30,7 @@ export class LoggingDebugAdapterTrackerFactory implements vscode.DebugAdapterTra
30
30
interface OutputEventBody {
31
31
category : string ;
32
32
output : string ;
33
+ exitCode : number | undefined ;
33
34
}
34
35
35
36
interface DebugMessage {
@@ -68,7 +69,9 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker {
68
69
private static debugSessionIdMap : { [ id : string ] : LoggingDebugAdapterTracker } = { } ;
69
70
70
71
private cb ?: ( output : string ) => void ;
72
+ private exitHandler ?: ( exitCode : number ) => void ;
71
73
private output : string [ ] = [ ] ;
74
+ private exitCode : number | undefined ;
72
75
73
76
constructor ( public id : string ) {
74
77
LoggingDebugAdapterTracker . debugSessionIdMap [ id ] = this ;
@@ -77,49 +80,62 @@ export class LoggingDebugAdapterTracker implements vscode.DebugAdapterTracker {
77
80
static setDebugSessionCallback (
78
81
session : vscode . DebugSession ,
79
82
logger : SwiftLogger ,
80
- cb : ( log : string ) => void
83
+ cb : ( log : string ) => void ,
84
+ exitHandler : ( exitCode : number ) => void
81
85
) {
82
86
const loggingDebugAdapter = this . debugSessionIdMap [ session . id ] ;
83
87
if ( loggingDebugAdapter ) {
84
- loggingDebugAdapter . cb = cb ;
88
+ loggingDebugAdapter . setCallbacks ( cb , exitHandler ) ;
85
89
for ( const o of loggingDebugAdapter . output ) {
86
90
cb ( o ) ;
87
91
}
92
+ if ( loggingDebugAdapter . exitCode ) {
93
+ exitHandler ( loggingDebugAdapter . exitCode ) ;
94
+ }
88
95
loggingDebugAdapter . output = [ ] ;
96
+ loggingDebugAdapter . exitCode = undefined ;
89
97
} else {
90
98
logger . error ( "Could not find debug adapter for session: " + session . id ) ;
91
99
}
92
100
}
93
101
102
+ setCallbacks ( handleOutput : ( output : string ) => void , handleExit : ( exitCode : number ) => void ) {
103
+ this . cb = handleOutput ;
104
+ this . exitHandler = handleExit ;
105
+ }
106
+
94
107
/**
95
108
* The debug adapter has sent a Debug Adapter Protocol message to the editor. Check
96
109
* it is a output message and is not being sent to the console
97
110
*/
98
111
onDidSendMessage ( message : unknown ) : void {
99
112
const debugMessage = message as DebugMessage ;
100
- if (
101
- ! (
102
- debugMessage &&
103
- debugMessage . type === "event" &&
104
- debugMessage . event === "output" &&
105
- debugMessage . body . category !== "console"
106
- )
107
- ) {
113
+ if ( ! debugMessage ) {
108
114
return ;
109
115
}
110
- const output = debugMessage . body . output ;
111
- if ( this . cb ) {
112
- this . cb ( output ) ;
113
- } else {
114
- this . output . push ( output ) ;
116
+
117
+ if ( debugMessage . event === "exited" && debugMessage . body . exitCode ) {
118
+ this . exitCode = debugMessage . body . exitCode ;
119
+ this . exitHandler ?.( debugMessage . body . exitCode ) ;
120
+ } else if (
121
+ debugMessage . type === "event" &&
122
+ debugMessage . event === "output" &&
123
+ debugMessage . body . category !== "console"
124
+ ) {
125
+ const output = debugMessage . body . output ;
126
+ if ( this . cb ) {
127
+ this . cb ( output ) ;
128
+ } else {
129
+ this . output . push ( output ) ;
130
+ }
115
131
}
116
132
}
117
133
118
134
/**
119
135
* The debug adapter session is about to be stopped. Delete the session from
120
136
* the tracker
121
137
*/
122
- onWillStopSession ? ( ) : void {
138
+ onWillStopSession ( ) : void {
123
139
delete LoggingDebugAdapterTracker . debugSessionIdMap [ this . id ] ;
124
140
}
125
141
}
0 commit comments