Skip to content

feat: set 'vscode_connection' as build reason on workspace start #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as vscode from "vscode";
import * as ws from "ws";
import { errToStr } from "./api-helper";
import { CertificateError } from "./error";
import { FeatureSet } from "./featureSet";
import { getHeaderArgs } from "./headers";
import { getProxyForUrl } from "./proxy";
import { Storage } from "./storage";
Expand Down Expand Up @@ -174,6 +175,7 @@ export async function startWorkspaceIfStoppedOrFailed(
binPath: string,
workspace: Workspace,
writeEmitter: vscode.EventEmitter<string>,
featureSet: FeatureSet,
): Promise<Workspace> {
// Before we start a workspace, we make an initial request to check it's not already started
const updatedWorkspace = await restClient.getWorkspace(workspace.id);
Expand All @@ -191,6 +193,10 @@ export async function startWorkspaceIfStoppedOrFailed(
"--yes",
workspace.owner_name + "/" + workspace.name,
];
if (featureSet.buildReason) {
startArgs.push(...["--reason", "vscode_connection"]);
}

const startProcess = spawn(binPath, startArgs);

startProcess.stdout.on("data", (data: Buffer) => {
Expand Down
6 changes: 6 additions & 0 deletions src/featureSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type FeatureSet = {
vscodessh: boolean;
proxyLogDirectory: boolean;
wildcardSSH: boolean;
buildReason: boolean;
};

/**
Expand All @@ -29,5 +30,10 @@ export function featureSetForVersion(
wildcardSSH:
(version ? version.compare("2.19.0") : -1) >= 0 ||
version?.prerelease[0] === "devel",

// --reason flag was added in 2.25.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// --reason flag was added in 2.25.0
// The --reason flag was added to `coder start` in 2.25.0

buildReason:
(version?.compare("2.25.0") || 0) >= 0 ||
version?.prerelease[0] === "devel",
};
}
4 changes: 4 additions & 0 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Remote {
workspace: Workspace,
label: string,
binPath: string,
featureSet: FeatureSet,
): Promise<Workspace | undefined> {
const workspaceName = `${workspace.owner_name}/${workspace.name}`;

Expand Down Expand Up @@ -140,6 +141,7 @@ export class Remote {
binPath,
workspace,
writeEmitter,
featureSet,
);
break;
case "failed":
Expand All @@ -159,6 +161,7 @@ export class Remote {
binPath,
workspace,
writeEmitter,
featureSet,
);
break;
}
Expand Down Expand Up @@ -393,6 +396,7 @@ export class Remote {
workspace,
parts.label,
binaryPath,
featureSet,
);
if (!updatedWorkspace) {
// User declined to start the workspace.
Expand Down