Skip to content

Commit fe83ed9

Browse files
committed
fix(utils-ai-vscode): use a single channel
fix #33
1 parent 9b091d9 commit fe83ed9

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

packages/utils-ai-vscode/src/commands/correct_command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { Logger } from '../logger.js'
66
import { SecretsStorage } from '../secrets_storage.js'
77

88
export function correctCommand(context: vscode.ExtensionContext) {
9-
const logger = new Logger(
10-
vscode.window,
11-
)
9+
const logger = new Logger()
1210

1311
const secretsStorage = new SecretsStorage(
1412
context.secrets,

packages/utils-ai-vscode/src/commands/delete_auth_token_command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { SecretsStorage } from '../secrets_storage.js'
33
import { Logger } from '../logger.js'
44

55
export function deleteAuthTokenCommand(context: vscode.ExtensionContext) {
6-
const logger = new Logger(
7-
vscode.window,
8-
)
6+
const logger = new Logger()
97

108
const secretsStorage = new SecretsStorage(
119
context.secrets,

packages/utils-ai-vscode/src/commands/description_command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { Configurator } from '../configurator.js'
66
import { SecretsStorage } from '../secrets_storage.js'
77

88
export function descriptionCommand(context: vscode.ExtensionContext) {
9-
const logger = new Logger(
10-
vscode.window,
11-
)
9+
const logger = new Logger()
1210

1311
const secretsStorage = new SecretsStorage(
1412
context.secrets,

packages/utils-ai-vscode/src/commands/save_auth_token_command.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { SecretsStorage } from '../secrets_storage.js'
44
import { Logger } from '../logger.js'
55

66
export function saveAuthTokenCommand(context: vscode.ExtensionContext) {
7-
const logger = new Logger(
8-
vscode.window,
9-
)
7+
const logger = new Logger()
108

119
const secretsStorage = new SecretsStorage(
1210
context.secrets,

packages/utils-ai-vscode/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { saveAuthTokenCommand } from './commands/save_auth_token_command.js'
55
import { deleteAuthTokenCommand } from './commands/delete_auth_token_command.js'
66
import { SecretsStorage } from './secrets_storage.js'
77
import { Configurator } from './configurator.js'
8+
import { Logger } from './logger.js'
89

910
export function activate(context: vscode.ExtensionContext) {
11+
Logger.createChannel(vscode.window)
12+
1013
/**
1114
* Set context for the `package.json` because it's an array and using `config.` will interpret as a string.
1215
*/
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import type * as vscode from 'vscode'
22

33
export class Logger {
4-
#key = 'Utils AI'
4+
static readonly channelName = 'Utils AI'
5+
static channel: vscode.OutputChannel
56

6-
#channel: vscode.OutputChannel
7+
static createChannel(window: typeof vscode.window) {
8+
if (Logger.channel)
9+
return
710

8-
constructor(
9-
private window: typeof vscode.window,
10-
) {
11-
this.#channel = this.window.createOutputChannel(this.#key)
11+
Logger.channel = window.createOutputChannel(Logger.channelName)
1212
}
1313

1414
log(message: string) {
15-
this.#channel.appendLine(message)
15+
Logger.channel.appendLine(message)
1616
}
1717

1818
show() {
19-
this.#channel.show(true)
19+
Logger.channel.show(true)
2020
}
2121
}

0 commit comments

Comments
 (0)