Skip to content

Commit 014ea7b

Browse files
committed
refactor: simplify chat panel rendering
1 parent cd45997 commit 014ea7b

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

src/webviews/chat/chatPanelProvider.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ export class ChatPanelProvider
3838
public openChat(agentId: string): void {
3939
this.agentId = agentId;
4040
this.refresh();
41-
vscode.commands
42-
.executeCommand("workbench.action.focusAuxiliaryBar")
43-
.then(() =>
44-
vscode.commands.executeCommand("coder.chatPanel.focus"),
45-
);
41+
void vscode.commands.executeCommand("coder.chatPanel.focus");
4642
}
4743

4844
async resolveWebviewView(
@@ -51,6 +47,12 @@ export class ChatPanelProvider
5147
_token: vscode.CancellationToken,
5248
): Promise<void> {
5349
this.view = webviewView;
50+
webviewView.webview.options = { enableScripts: true };
51+
this.disposables.push(
52+
webviewView.webview.onDidReceiveMessage((msg: unknown) => {
53+
this.handleMessage(msg);
54+
}),
55+
);
5456
this.renderView();
5557
webviewView.onDidDispose(() => this.disposeInternals());
5658
}
@@ -76,16 +78,6 @@ export class ChatPanelProvider
7678
return;
7779
}
7880

79-
this.disposeInternals();
80-
81-
webview.options = { enableScripts: true };
82-
83-
this.disposables.push(
84-
webview.onDidReceiveMessage((msg: unknown) => {
85-
this.handleMessage(msg);
86-
}),
87-
);
88-
8981
const embedUrl = `${coderUrl}/agents/${this.agentId}/embed`;
9082
webview.html = this.getIframeHtml(embedUrl, coderUrl);
9183
}
@@ -150,12 +142,7 @@ export class ChatPanelProvider
150142
const iframe = document.getElementById('chat-frame');
151143
const status = document.getElementById('status');
152144
153-
function log(msg) { console.log('[CoderChat] ' + msg); }
154-
155-
log('Webview loaded, iframe src: ' + iframe.src);
156-
157145
iframe.addEventListener('load', () => {
158-
log('iframe load event');
159146
iframe.style.display = 'block';
160147
status.style.display = 'none';
161148
});
@@ -165,17 +152,14 @@ export class ChatPanelProvider
165152
if (!data || typeof data !== 'object') return;
166153
167154
if (event.source === iframe.contentWindow) {
168-
log('From iframe: ' + JSON.stringify(data.type));
169155
if (data.type === 'coder:vscode-ready') {
170-
log('Requesting token from extension host');
171156
status.textContent = 'Authenticating…';
172157
vscode.postMessage({ type: 'coder:vscode-ready' });
173158
}
174159
return;
175160
}
176161
177162
if (data.type === 'coder:auth-bootstrap-token') {
178-
log('Forwarding token to iframe');
179163
status.textContent = 'Signing in…';
180164
iframe.contentWindow.postMessage({
181165
type: 'coder:vscode-auth-bootstrap',

0 commit comments

Comments
 (0)