Skip to content

Commit 811c59a

Browse files
committed
Re-implement old channel clearing logic
Signed-off-by: worksofliam <[email protected]>
1 parent 04caaa4 commit 811c59a

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/Instance.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,19 @@ export interface ConnectionOptions {
2626

2727
export default class Instance {
2828
private connection: IBMi | undefined;
29-
private outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(`Code for IBM i`);
29+
30+
private output = {
31+
channel: vscode.window.createOutputChannel(`Code for IBM i`),
32+
content: ``,
33+
writeCount: 0
34+
};
35+
36+
private resetOutput() {
37+
this.output.channel.clear();
38+
this.output.content = ``;
39+
this.output.writeCount = 0;
40+
}
41+
3042
private storage: ConnectionStorage;
3143
private emitter: vscode.EventEmitter<IBMiEvent> = new vscode.EventEmitter();
3244
private subscribers: Map<IBMiEvent, SubscriptionMap> = new Map;
@@ -45,9 +57,14 @@ export default class Instance {
4557
connect(options: ConnectionOptions): Promise<ConnectionResult> {
4658
const connection = new IBMi();
4759

48-
this.outputChannel.clear();
60+
this.resetOutput();
4961
connection.appendOutput = (message) => {
50-
this.outputChannel.append(message);
62+
if (this.output.writeCount > 150) {
63+
this.resetOutput();
64+
}
65+
66+
this.output.channel.append(message);
67+
this.output.writeCount++;
5168
}
5269

5370
let result: ConnectionResult;
@@ -62,13 +79,12 @@ export default class Instance {
6279
let reconnect = choice === `Yes`;
6380
let collectLogs = choice === `No, get logs`;
6481

65-
// TODO: how to get output channel stuff?
66-
// if (collectLogs) {
67-
// const logs = conn.getOutputChannelContent();
68-
// vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
69-
// vscode.window.showTextDocument(doc);
70-
// });
71-
// }
82+
if (collectLogs) {
83+
const logs = this.output.content;
84+
vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
85+
vscode.window.showTextDocument(doc);
86+
});
87+
}
7288

7389
this.disconnect();
7490

0 commit comments

Comments
 (0)