Skip to content

Commit d998ac2

Browse files
authored
feat: add Coder Ping Workspace command (#873)
Adds a `coder.pingWorkspace` command that runs `coder ping <workspace>` locally and streams output to a custom PTY terminal, helping users diagnose connection problems (latency, P2P diagnostics, DERP info). Closes #749
1 parent 0c3c250 commit d998ac2

5 files changed

Lines changed: 324 additions & 71 deletions

File tree

package.json

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@
259259
"when": "!coder.authenticated && coder.loaded"
260260
}
261261
],
262+
"submenus": [
263+
{
264+
"id": "coder.diagnostics",
265+
"label": "Diagnostics"
266+
}
267+
],
262268
"commands": [
263269
{
264270
"command": "coder.login",
@@ -368,6 +374,11 @@
368374
"command": "coder.applyRecommendedSettings",
369375
"title": "Apply Recommended SSH Settings",
370376
"category": "Coder"
377+
},
378+
{
379+
"command": "coder.pingWorkspace",
380+
"title": "Ping Workspace",
381+
"category": "Coder"
371382
}
372383
],
373384
"menus": {
@@ -400,6 +411,10 @@
400411
"command": "coder.navigateToWorkspaceSettings",
401412
"when": "coder.workspace.connected"
402413
},
414+
{
415+
"command": "coder.pingWorkspace",
416+
"when": "coder.authenticated"
417+
},
403418
{
404419
"command": "coder.workspace.update",
405420
"when": "coder.workspace.updatable"
@@ -494,18 +509,28 @@
494509
"view/item/context": [
495510
{
496511
"command": "coder.openFromSidebar",
497-
"when": "coder.authenticated && viewItem == coderWorkspaceSingleAgent || coder.authenticated && viewItem == coderAgent",
512+
"when": "coder.authenticated && viewItem =~ /^coderWorkspaceSingleAgent/ || coder.authenticated && viewItem =~ /^coderAgent/",
498513
"group": "inline"
499514
},
500515
{
501516
"command": "coder.navigateToWorkspace",
502-
"when": "coder.authenticated && viewItem == coderWorkspaceSingleAgent || coder.authenticated && viewItem == coderWorkspaceMultipleAgents",
517+
"when": "coder.authenticated && viewItem =~ /^coderWorkspaceSingleAgent/ || coder.authenticated && viewItem =~ /^coderWorkspaceMultipleAgents/",
503518
"group": "inline"
504519
},
505520
{
506521
"command": "coder.navigateToWorkspaceSettings",
507-
"when": "coder.authenticated && viewItem == coderWorkspaceSingleAgent || coder.authenticated && viewItem == coderWorkspaceMultipleAgents",
522+
"when": "coder.authenticated && viewItem =~ /^coderWorkspaceSingleAgent/ || coder.authenticated && viewItem =~ /^coderWorkspaceMultipleAgents/",
508523
"group": "inline"
524+
},
525+
{
526+
"submenu": "coder.diagnostics",
527+
"when": "coder.authenticated && viewItem =~ /\\+running/",
528+
"group": "navigation"
529+
}
530+
],
531+
"coder.diagnostics": [
532+
{
533+
"command": "coder.pingWorkspace"
509534
}
510535
],
511536
"statusBar/remoteIndicator": [

src/api/api-helper.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type Workspace,
44
type WorkspaceAgent,
55
type WorkspaceResource,
6+
type WorkspaceStatus,
67
} from "coder/site/src/api/typesGenerated";
78
import { ErrorEvent } from "eventsource";
89
import { z } from "zod";
@@ -49,6 +50,26 @@ export function extractAgents(
4950
}, [] as WorkspaceAgent[]);
5051
}
5152

53+
const WORKSPACE_STATUS_LABEL: Readonly<Record<WorkspaceStatus, string>> = {
54+
canceled: "Canceled",
55+
canceling: "Canceling",
56+
deleted: "Deleted",
57+
deleting: "Deleting",
58+
failed: "Failed",
59+
pending: "Pending",
60+
running: "Running",
61+
starting: "Starting",
62+
stopped: "Stopped",
63+
stopping: "Stopping",
64+
};
65+
66+
export function workspaceStatusLabel(status: WorkspaceStatus): string {
67+
return (
68+
WORKSPACE_STATUS_LABEL[status] ??
69+
status.charAt(0).toUpperCase() + status.slice(1)
70+
);
71+
}
72+
5273
export const AgentMetadataEventSchema = z.object({
5374
result: z.object({
5475
collected_at: z.string(),

0 commit comments

Comments
 (0)