Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { type Logger } from "./logging/logger";
import { type LoginCoordinator } from "./login/loginCoordinator";
import { maybeAskAgent, maybeAskUrl } from "./promptUtils";
import { escapeCommandArg, toRemoteAuthority, toSafeHost } from "./util";
import { vscodeProposed } from "./vscodeProposed";
import {
AgentTreeItem,
type OpenableTreeItem,
WorkspaceTreeItem,
} from "./workspace/workspacesProvider";

export class Commands {
private readonly vscodeProposed: typeof vscode;
private readonly logger: Logger;
private readonly pathResolver: PathResolver;
private readonly mementoManager: MementoManager;
Expand All @@ -53,7 +53,6 @@ export class Commands {
private readonly extensionClient: CoderApi,
private readonly deploymentManager: DeploymentManager,
) {
this.vscodeProposed = serviceContainer.getVsCodeProposed();
this.logger = serviceContainer.getLogger();
this.pathResolver = serviceContainer.getPathResolver();
this.mementoManager = serviceContainer.getMementoManager();
Expand Down Expand Up @@ -492,7 +491,7 @@ export class Commands {
if (!this.workspace || !this.remoteWorkspaceClient) {
return;
}
const action = await this.vscodeProposed.window.showWarningMessage(
const action = await vscodeProposed.window.showWarningMessage(
"Update Workspace",
{
useCustom: true,
Expand Down
8 changes: 3 additions & 5 deletions src/core/binaryLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as lockfile from "proper-lockfile";
import * as vscode from "vscode";

import { type Logger } from "../logging/logger";
import { vscodeProposed } from "../vscodeProposed";

import * as downloadProgress from "./downloadProgress";

Expand All @@ -21,10 +22,7 @@ type LockRelease = () => Promise<void>;
* VS Code windows downloading the same binary.
*/
export class BinaryLock {
constructor(
private readonly vscodeProposed: typeof vscode,
private readonly output: Logger,
) {}
constructor(private readonly output: Logger) {}

/**
* Acquire the lock, or wait for another process if the lock is held.
Expand Down Expand Up @@ -78,7 +76,7 @@ export class BinaryLock {
binPath: string,
progressLogPath: string,
): Promise<LockRelease> {
return await this.vscodeProposed.window.withProgress(
return await vscodeProposed.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Another window is downloading the Coder CLI binary",
Expand Down
10 changes: 5 additions & 5 deletions src/core/cliManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as vscode from "vscode";
import { errToStr } from "../api/api-helper";
import { type Logger } from "../logging/logger";
import * as pgp from "../pgp";
import { vscodeProposed } from "../vscodeProposed";

import { BinaryLock } from "./binaryLock";
import * as cliUtils from "./cliUtils";
Expand All @@ -24,11 +25,10 @@ export class CliManager {
private readonly binaryLock: BinaryLock;

constructor(
private readonly vscodeProposed: typeof vscode,
private readonly output: Logger,
private readonly pathResolver: PathResolver,
) {
this.binaryLock = new BinaryLock(vscodeProposed, output);
this.binaryLock = new BinaryLock(output);
}

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ export class CliManager {
version: string,
reason: string,
): Promise<boolean> {
const choice = await this.vscodeProposed.window.showErrorMessage(
const choice = await vscodeProposed.window.showErrorMessage(
`${reason}. Run version ${version} anyway?`,
"Run",
);
Expand Down Expand Up @@ -621,7 +621,7 @@ export class CliManager {
options.push("Download signature");
}
options.push("Run without verification");
const action = await this.vscodeProposed.window.showWarningMessage(
const action = await vscodeProposed.window.showWarningMessage(
status === 404 ? "Signature not found" : "Failed to download signature",
{
useCustom: true,
Expand Down Expand Up @@ -675,7 +675,7 @@ export class CliManager {
this.output,
);
} catch (error) {
const action = await this.vscodeProposed.window.showWarningMessage(
const action = await vscodeProposed.window.showWarningMessage(
// VerificationError should be the only thing that throws, but
// unfortunately caught errors are always type unknown.
error instanceof pgp.VerificationError
Expand Down
16 changes: 2 additions & 14 deletions src/core/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export class ServiceContainer implements vscode.Disposable {
private readonly contextManager: ContextManager;
private readonly loginCoordinator: LoginCoordinator;

constructor(
context: vscode.ExtensionContext,
private readonly vscodeProposed: typeof vscode = vscode,
) {
constructor(context: vscode.ExtensionContext) {
this.logger = vscode.window.createOutputChannel("Coder", { log: true });
this.pathResolver = new PathResolver(
context.globalStorageUri.fsPath,
Expand All @@ -37,25 +34,16 @@ export class ServiceContainer implements vscode.Disposable {
context.globalState,
this.logger,
);
this.cliManager = new CliManager(
this.vscodeProposed,
this.logger,
this.pathResolver,
);
this.cliManager = new CliManager(this.logger, this.pathResolver);
this.contextManager = new ContextManager(context);
this.loginCoordinator = new LoginCoordinator(
this.secretsManager,
this.mementoManager,
this.vscodeProposed,
this.logger,
context.extension.id,
);
}

getVsCodeProposed(): typeof vscode {
return this.vscodeProposed;
}

getPathResolver(): PathResolver {
return this.pathResolver;
}
Expand Down
4 changes: 2 additions & 2 deletions src/error/certificateError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vscode from "vscode";
import { vscodeProposed } from "../vscodeProposed";

/**
* Base class for certificate-related errors that can display notifications to users.
Expand All @@ -23,7 +23,7 @@ export abstract class CertificateError extends Error {
const message =
!modal && title ? `${title}: ${this.detail}` : title || this.detail;

return await vscode.window.showErrorMessage(
return await vscodeProposed.window.showErrorMessage(
message,
{ modal, useCustom: modal, detail: this.detail },
...(items ?? []),
Expand Down
13 changes: 6 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { OAuthSessionManager } from "./oauth/sessionManager";
import { Remote } from "./remote/remote";
import { getRemoteSshExtension } from "./remote/sshExtension";
import { registerUriHandler } from "./uri/uriHandler";
import { initVscodeProposed } from "./vscodeProposed";
import {
WorkspaceProvider,
WorkspaceQuery,
Expand Down Expand Up @@ -54,7 +55,10 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
);
}

const serviceContainer = new ServiceContainer(ctx, vscodeProposed);
// Initialize the global vscodeProposed module for use throughout the extension
initVscodeProposed(vscodeProposed);

const serviceContainer = new ServiceContainer(ctx);
ctx.subscriptions.push(serviceContainer);

const output = serviceContainer.getLogger();
Expand Down Expand Up @@ -185,12 +189,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
const commands = new Commands(serviceContainer, client, deploymentManager);

ctx.subscriptions.push(
registerUriHandler(
serviceContainer,
deploymentManager,
commands,
vscodeProposed,
),
registerUriHandler(serviceContainer, deploymentManager, commands),
vscode.commands.registerCommand(
"coder.login",
commands.login.bind(commands),
Expand Down
10 changes: 6 additions & 4 deletions src/login/loginCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CertificateError } from "../error/certificateError";
import { OAuthAuthorizer } from "../oauth/authorizer";
import { buildOAuthTokenData } from "../oauth/utils";
import { maybeAskAuthMethod, maybeAskUrl } from "../promptUtils";
import { vscodeProposed } from "../vscodeProposed";

import type { User } from "coder/site/src/api/typesGenerated";

Expand Down Expand Up @@ -37,7 +38,6 @@ export class LoginCoordinator implements vscode.Disposable {
constructor(
private readonly secretsManager: SecretsManager,
private readonly mementoManager: MementoManager,
private readonly vscodeProposed: typeof vscode,
private readonly logger: Logger,
extensionId: string,
) {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class LoginCoordinator implements vscode.Disposable {
const { safeHostname, url, detailPrefix, message } = options;
return this.executeWithGuard(async () => {
// Show dialog promise
const dialogPromise = this.vscodeProposed.window
const dialogPromise = vscodeProposed.window
.showErrorMessage(
message || "Authentication Required",
{
Expand Down Expand Up @@ -291,9 +291,11 @@ export class LoginCoordinator implements vscode.Disposable {
if (isAutoLogin) {
this.logger.warn("Failed to log in to Coder server:", message);
} else if (err instanceof CertificateError) {
void err.showNotification("Failed to log in to Coder server");
void err.showNotification("Failed to log in to Coder server", {
modal: true,
});
} else {
void this.vscodeProposed.window.showErrorMessage(
void vscodeProposed.window.showErrorMessage(
"Failed to log in to Coder server",
{
detail: message,
Expand Down
37 changes: 16 additions & 21 deletions src/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
expandPath,
parseRemoteAuthority,
} from "../util";
import { vscodeProposed } from "../vscodeProposed";
import { WorkspaceMonitor } from "../workspace/workspaceMonitor";

import {
Expand All @@ -62,8 +63,6 @@ export interface RemoteDetails extends vscode.Disposable {
}

export class Remote {
// We use the proposed API to get access to useCustom in dialogs.
private readonly vscodeProposed: typeof vscode;
private readonly logger: Logger;
private readonly pathResolver: PathResolver;
private readonly cliManager: CliManager;
Expand All @@ -76,7 +75,6 @@ export class Remote {
private readonly commands: Commands,
private readonly extensionContext: vscode.ExtensionContext,
) {
this.vscodeProposed = serviceContainer.getVsCodeProposed();
this.logger = serviceContainer.getLogger();
this.pathResolver = serviceContainer.getPathResolver();
this.cliManager = serviceContainer.getCliManager();
Expand Down Expand Up @@ -257,7 +255,7 @@ export class Remote {

// Server versions before v0.14.1 don't support the vscodessh command!
if (!featureSet.vscodessh) {
await this.vscodeProposed.window.showErrorMessage(
await vscodeProposed.window.showErrorMessage(
"Incompatible Server",
{
detail:
Expand Down Expand Up @@ -293,16 +291,15 @@ export class Remote {
}
switch (error.response?.status) {
case 404: {
const result =
await this.vscodeProposed.window.showInformationMessage(
`That workspace doesn't exist!`,
{
modal: true,
detail: `${workspaceName} cannot be found on ${baseUrlRaw}. Maybe it was deleted...`,
useCustom: true,
},
"Open Workspace",
);
const result = await vscodeProposed.window.showInformationMessage(
`That workspace doesn't exist!`,
{
modal: true,
detail: `${workspaceName} cannot be found on ${baseUrlRaw}. Maybe it was deleted...`,
useCustom: true,
},
"Open Workspace",
);
disposables.forEach((d) => {
d.dispose();
});
Expand Down Expand Up @@ -334,7 +331,6 @@ export class Remote {
workspace,
workspaceClient,
this.logger,
this.vscodeProposed,
this.contextManager,
);
disposables.push(
Expand All @@ -351,12 +347,11 @@ export class Remote {
featureSet,
this.logger,
this.pathResolver,
this.vscodeProposed,
);
disposables.push(stateMachine);

try {
workspace = await this.vscodeProposed.window.withProgress(
workspace = await vscodeProposed.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
cancellable: false,
Expand Down Expand Up @@ -431,10 +426,10 @@ export class Remote {

// Do some janky setting manipulation.
this.logger.info("Modifying settings...");
const remotePlatforms = this.vscodeProposed.workspace
const remotePlatforms = vscodeProposed.workspace
.getConfiguration()
.get<Record<string, string>>("remote.SSH.remotePlatform", {});
const connTimeout = this.vscodeProposed.workspace
const connTimeout = vscodeProposed.workspace
.getConfiguration()
.get<number | undefined>("remote.SSH.connectTimeout");

Expand Down Expand Up @@ -864,7 +859,7 @@ export class Remote {
continue;
}

const result = await this.vscodeProposed.window.showErrorMessage(
const result = await vscodeProposed.window.showErrorMessage(
"Unexpected SSH Config Option",
{
useCustom: true,
Expand Down Expand Up @@ -986,7 +981,7 @@ export class Remote {
}
// VS Code caches resource label formatters in it's global storage SQLite database
// under the key "memento/cachedResourceLabelFormatters2".
return this.vscodeProposed.workspace.registerResourceLabelFormatter({
return vscodeProposed.workspace.registerResourceLabelFormatter({
scheme: "vscode-remote",
// authority is optional but VS Code prefers formatters that most
// accurately match the requested authority, so we include it.
Expand Down
4 changes: 2 additions & 2 deletions src/remote/workspaceStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "../api/workspace";
import { maybeAskAgent } from "../promptUtils";
import { type AuthorityParts } from "../util";
import { vscodeProposed } from "../vscodeProposed";

import { TerminalSession } from "./terminalSession";

Expand Down Expand Up @@ -44,7 +45,6 @@ export class WorkspaceStateMachine implements vscode.Disposable {
private readonly featureSet: FeatureSet,
private readonly logger: Logger,
private readonly pathResolver: PathResolver,
private readonly vscodeProposed: typeof vscode,
) {
this.terminal = new TerminalSession("Workspace Build");
}
Expand Down Expand Up @@ -231,7 +231,7 @@ export class WorkspaceStateMachine implements vscode.Disposable {
}

private async confirmStart(workspaceName: string): Promise<boolean> {
const action = await this.vscodeProposed.window.showInformationMessage(
const action = await vscodeProposed.window.showInformationMessage(
`Unable to connect to the workspace ${workspaceName} because it is not running. Start the workspace?`,
{
useCustom: true,
Expand Down
2 changes: 1 addition & 1 deletion src/uri/uriHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type DeploymentManager } from "../deployment/deploymentManager";
import { CALLBACK_PATH } from "../oauth/utils";
import { maybeAskUrl } from "../promptUtils";
import { toSafeHost } from "../util";
import { vscodeProposed } from "../vscodeProposed";

interface UriRouteContext {
params: URLSearchParams;
Expand All @@ -30,7 +31,6 @@ export function registerUriHandler(
serviceContainer: ServiceContainer,
deploymentManager: DeploymentManager,
commands: Commands,
vscodeProposed: typeof vscode,
): vscode.Disposable {
const output = serviceContainer.getLogger();

Expand Down
Loading