Skip to content

Commit 2f87b30

Browse files
committed
Cleanup output channel correctly
Signed-off-by: worksofliam <[email protected]>
1 parent 584607b commit 2f87b30

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/api/IBMi.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,16 @@ export default class IBMi {
226226
this.currentPort = connectionObject.port;
227227
this.currentUser = connectionObject.username;
228228

229-
if (!reconnecting) {
229+
if (this.outputChannel) {
230+
this.appendOutput(`\n\nReconnecting to ${this.currentConnectionName}...\n\n`);
231+
232+
} else {
230233
this.outputChannel = vscode.window.createOutputChannel(`Code for IBM i: ${this.currentConnectionName}`);
231-
this.outputChannelContent = '';
232-
this.appendOutput(`Code for IBM i, version ${currentExtensionVersion}\n\n`);
233234
}
234235

236+
this.outputChannelContent = '';
237+
this.appendOutput(`Code for IBM i, version ${currentExtensionVersion}\n\n`);
238+
235239
let tempLibrarySet = false;
236240

237241
progress.report({
@@ -1091,13 +1095,10 @@ export default class IBMi {
10911095
});
10921096

10931097
} catch (e: any) {
1094-
1095-
if (this.client.isConnected()) {
1096-
this.client.dispose();
1097-
}
1098+
this.dispose();
10981099
if (reconnecting && await vscode.window.showWarningMessage(`Could not reconnect`, {
10991100
modal: true,
1100-
detail: `Reconnection to ${this.currentConnectionName} has failed. Would you like to try again?\n\n${e}`
1101+
detail: `Reconnection has failed. Would you like to try again?\n\n${e}`
11011102
}, `Yes`)) {
11021103
return this.connect(connectionObject, true);
11031104
}
@@ -1241,9 +1242,11 @@ export default class IBMi {
12411242
}
12421243

12431244
private async disconnect() {
1244-
this.client.connection?.removeAllListeners();
1245-
this.client.dispose();
1246-
this.client.connection = null;
1245+
if (this.client) {
1246+
this.client.connection?.removeAllListeners();
1247+
this.client.dispose();
1248+
this.client.connection = null;
1249+
}
12471250
instance.fire(`disconnected`);
12481251
}
12491252

0 commit comments

Comments
 (0)