Skip to content

Commit cd45997

Browse files
committed
refactor: remove dead code, fix duplication and indentation
- Remove unused getErrorHtml() (dead after proxy removal). - Extract renderView() to deduplicate resolveWebviewView/refresh. - Fix package.json indentation (extra nesting introduced in prior commit).
1 parent 5aecb0e commit cd45997

File tree

2 files changed

+68
-94
lines changed

2 files changed

+68
-94
lines changed

package.json

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -180,61 +180,62 @@
180180
}
181181
}
182182
},
183-
"viewsContainers": {
184-
"activitybar": [
185-
{
186-
"id": "coder",
187-
"title": "Coder Remote",
188-
"icon": "media/shorthand-logo.svg"
189-
},
190-
{
191-
"id": "coderTasks",
192-
"title": "Coder Tasks",
193-
"icon": "media/tasks-logo.svg"
194-
}
195-
],
196-
"panel": [
197-
{
198-
"id": "coderChat",
199-
"title": "Coder Chat",
200-
"icon": "media/shorthand-logo.svg"
201-
}
202-
]
203-
},
204-
"views": {
205-
"coder": [
206-
{
207-
"id": "myWorkspaces",
208-
"name": "My Workspaces",
209-
"visibility": "visible",
210-
"icon": "media/logo-white.svg"
211-
},
212-
{
213-
"id": "allWorkspaces",
214-
"name": "All Workspaces",
215-
"visibility": "visible",
216-
"icon": "media/logo-white.svg",
217-
"when": "coder.authenticated && coder.isOwner"
218-
}
219-
],
220-
"coderTasks": [
221-
{
222-
"type": "webview",
223-
"id": "coder.tasksPanel",
224-
"name": "Coder Tasks",
225-
"icon": "media/tasks-logo.svg",
226-
"when": "coder.authenticated"
227-
}
228-
],
229-
"coderChat": [
230-
{
231-
"type": "webview",
232-
"id": "coder.chatPanel",
233-
"name": "Coder Chat"
234-
}
235-
]
236-
},
237-
"viewsWelcome": [ {
183+
"viewsContainers": {
184+
"activitybar": [
185+
{
186+
"id": "coder",
187+
"title": "Coder Remote",
188+
"icon": "media/shorthand-logo.svg"
189+
},
190+
{
191+
"id": "coderTasks",
192+
"title": "Coder Tasks",
193+
"icon": "media/tasks-logo.svg"
194+
}
195+
],
196+
"panel": [
197+
{
198+
"id": "coderChat",
199+
"title": "Coder Chat",
200+
"icon": "media/shorthand-logo.svg"
201+
}
202+
]
203+
},
204+
"views": {
205+
"coder": [
206+
{
207+
"id": "myWorkspaces",
208+
"name": "My Workspaces",
209+
"visibility": "visible",
210+
"icon": "media/logo-white.svg"
211+
},
212+
{
213+
"id": "allWorkspaces",
214+
"name": "All Workspaces",
215+
"visibility": "visible",
216+
"icon": "media/logo-white.svg",
217+
"when": "coder.authenticated && coder.isOwner"
218+
}
219+
],
220+
"coderTasks": [
221+
{
222+
"type": "webview",
223+
"id": "coder.tasksPanel",
224+
"name": "Coder Tasks",
225+
"icon": "media/tasks-logo.svg",
226+
"when": "coder.authenticated"
227+
}
228+
],
229+
"coderChat": [
230+
{
231+
"type": "webview",
232+
"id": "coder.chatPanel",
233+
"name": "Coder Chat"
234+
}
235+
]
236+
},
237+
"viewsWelcome": [
238+
{
238239
"view": "myWorkspaces",
239240
"contents": "Coder is a platform that provisions remote development environments. \n[Login](command:coder.login)",
240241
"when": "!coder.authenticated && coder.loaded"

src/webviews/chat/chatPanelProvider.ts

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,61 +51,43 @@ export class ChatPanelProvider
5151
_token: vscode.CancellationToken,
5252
): Promise<void> {
5353
this.view = webviewView;
54-
55-
if (!this.agentId) {
56-
webviewView.webview.html = this.getNoAgentHtml();
57-
return;
58-
}
59-
60-
const coderUrl = this.client.getHost();
61-
if (!coderUrl) {
62-
webviewView.webview.html = this.getNoAgentHtml();
63-
return;
64-
}
65-
66-
webviewView.webview.options = { enableScripts: true };
67-
68-
this.disposeInternals();
69-
70-
this.disposables.push(
71-
webviewView.webview.onDidReceiveMessage((msg: unknown) => {
72-
this.handleMessage(msg);
73-
}),
74-
);
75-
76-
const embedUrl = `${coderUrl}/agents/${this.agentId}/embed`;
77-
webviewView.webview.html = this.getIframeHtml(embedUrl, coderUrl);
78-
54+
this.renderView();
7955
webviewView.onDidDispose(() => this.disposeInternals());
8056
}
8157

8258
public refresh(): void {
8359
if (!this.view) {
8460
return;
8561
}
62+
this.renderView();
63+
}
64+
65+
private renderView(): void {
66+
const webview = this.view!.webview;
8667

8768
if (!this.agentId) {
88-
this.view.webview.html = this.getNoAgentHtml();
69+
webview.html = this.getNoAgentHtml();
8970
return;
9071
}
9172

9273
const coderUrl = this.client.getHost();
9374
if (!coderUrl) {
94-
this.view.webview.html = this.getNoAgentHtml();
75+
webview.html = this.getNoAgentHtml();
9576
return;
9677
}
9778

9879
this.disposeInternals();
9980

81+
webview.options = { enableScripts: true };
82+
10083
this.disposables.push(
101-
this.view.webview.onDidReceiveMessage((msg: unknown) => {
84+
webview.onDidReceiveMessage((msg: unknown) => {
10285
this.handleMessage(msg);
10386
}),
10487
);
10588

106-
this.view.webview.options = { enableScripts: true };
10789
const embedUrl = `${coderUrl}/agents/${this.agentId}/embed`;
108-
this.view.webview.html = this.getIframeHtml(embedUrl, coderUrl);
90+
webview.html = this.getIframeHtml(embedUrl, coderUrl);
10991
}
11092

11193
private handleMessage(message: unknown): void {
@@ -217,15 +199,6 @@ text-align:center;}</style></head>
217199
<body><p>No active chat session. Open a chat from the Agents tab on your Coder deployment.</p></body></html>`;
218200
}
219201

220-
private getErrorHtml(message: string): string {
221-
return /* html */ `<!DOCTYPE html>
222-
<html lang="en"><head><meta charset="UTF-8">
223-
<style>body{display:flex;align-items:center;justify-content:center;
224-
height:100vh;margin:0;font-family:var(--vscode-font-family);
225-
color:var(--vscode-errorForeground,#f44);}</style></head>
226-
<body><p>${message}</p></body></html>`;
227-
}
228-
229202
private disposeInternals(): void {
230203
for (const d of this.disposables) {
231204
d.dispose();

0 commit comments

Comments
 (0)