Skip to content

Commit cb19660

Browse files
committed
Add service container and improve import/order
1 parent 2800162 commit cb19660

17 files changed

+275
-350
lines changed

.eslintrc.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@
5353
"groups": [
5454
["builtin", "external"],
5555
"internal",
56-
["parent", "sibling", "index"],
56+
"parent",
57+
["sibling", "index"],
5758
"type"
5859
],
5960
"pathGroups": [
60-
{ "pattern": "@/**", "group": "internal", "position": "after" }
61+
{ "pattern": "@/**", "group": "internal", "position": "before" }
6162
],
62-
// Don't reclassify real externals like @babel/* into the alias group
6363
"pathGroupsExcludedImportTypes": ["builtin", "external"],
6464
"newlines-between": "always",
65-
"alphabetize": { "order": "asc", "caseInsensitive": true },
66-
"distinctGroup": true // separates type imports into the "type" group
65+
"alphabetize": { "order": "asc", "caseInsensitive": true }
6766
}
6867
],
6968
// Prevent duplicates and prefer merging into a single import

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
"eslint-plugin-prettier": "^5.5.4",
353353
"glob": "^10.4.2",
354354
"jsonc-eslint-parser": "^2.4.0",
355+
"markdown-eslint-parser": "^1.2.1",
355356
"memfs": "^4.46.0",
356357
"nyc": "^17.1.0",
357358
"prettier": "^3.5.3",

src/api/coderApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { type ClientOptions } from "ws";
1212

1313
import { CertificateError } from "../error";
1414
import { getHeaderCommand, getHeaders } from "../headers";
15-
import { createHttpAgent } from "./utils";
1615
import {
1716
createRequestMeta,
1817
logRequest,
@@ -30,6 +29,8 @@ import {
3029
type OneWayWebSocketInit,
3130
} from "../websocket/oneWayWebSocket";
3231

32+
import { createHttpAgent } from "./utils";
33+
3334
const coderSessionTokenHeader = "Coder-Session-Token";
3435

3536
type WorkspaceConfigurationProvider = () => WorkspaceConfiguration;

src/api/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import fs from "fs";
22
import { ProxyAgent } from "proxy-agent";
33
import { type WorkspaceConfiguration } from "vscode";
44

5-
import { getProxyForUrl } from "./proxy";
65
import { expandPath } from "../util";
76

7+
import { getProxyForUrl } from "./proxy";
8+
89
/**
910
* Return whether the API will need a token for authorization.
1011
* If mTLS is in use (as specified by the cert or key files being set) then

src/api/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from "vscode";
66
import { type FeatureSet } from "../featureSet";
77
import { getGlobalFlags } from "../globalFlags";
88
import { escapeCommandArg } from "../util";
9+
910
import { errToStr, createWorkspaceIdentifier } from "./api-helper";
1011
import { type CoderApi } from "./coderApi";
1112

src/cliUtils.test.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

src/commands.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createWorkspaceIdentifier, extractAgents } from "./api/api-helper";
1111
import { CoderApi } from "./api/coderApi";
1212
import { needToken } from "./api/utils";
1313
import { type CliManager } from "./core/cliManager";
14+
import { type ServiceContainer } from "./core/container";
1415
import { type MementoManager } from "./core/mementoManager";
1516
import { type PathResolver } from "./core/pathResolver";
1617
import { type SecretsManager } from "./core/secretsManager";
@@ -25,6 +26,12 @@ import {
2526
} from "./workspace/workspacesProvider";
2627

2728
export class Commands {
29+
private readonly vscodeProposed: typeof vscode;
30+
private readonly logger: Logger;
31+
private readonly pathResolver: PathResolver;
32+
private readonly mementoManager: MementoManager;
33+
private readonly secretsManager: SecretsManager;
34+
private readonly cliManager: CliManager;
2835
// These will only be populated when actively connected to a workspace and are
2936
// used in commands. Because commands can be executed by the user, it is not
3037
// possible to pass in arguments, so we have to store the current workspace
@@ -37,14 +44,16 @@ export class Commands {
3744
public workspaceRestClient?: Api;
3845

3946
public constructor(
40-
private readonly vscodeProposed: typeof vscode,
47+
serviceContainer: ServiceContainer,
4148
private readonly restClient: Api,
42-
private readonly logger: Logger,
43-
private readonly pathResolver: PathResolver,
44-
private readonly mementoManager: MementoManager,
45-
private readonly secretsManager: SecretsManager,
46-
private readonly cliManager: CliManager,
47-
) {}
49+
) {
50+
this.vscodeProposed = serviceContainer.getVsCodeProposed();
51+
this.logger = serviceContainer.getLogger();
52+
this.pathResolver = serviceContainer.getPathResolver();
53+
this.mementoManager = serviceContainer.getMementoManager();
54+
this.secretsManager = serviceContainer.getSecretsManager();
55+
this.cliManager = serviceContainer.getCliManager();
56+
}
4857

4958
/**
5059
* Find the requested agent if specified, otherwise return the agent if there

src/core/cliManager.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import * as semver from "semver";
1212
import * as vscode from "vscode";
1313

1414
import { errToStr } from "../api/api-helper";
15-
import * as cli from "./cliUtils";
1615
import { type Logger } from "../logging/logger";
1716
import * as pgp from "../pgp";
17+
18+
import * as cliUtils from "./cliUtils";
1819
import { type PathResolver } from "./pathResolver";
1920

2021
export class CliManager {
@@ -58,16 +59,16 @@ export class CliManager {
5859
// downloads are disabled, we can return early.
5960
const binPath = path.join(
6061
this.pathResolver.getBinaryCachePath(label),
61-
cli.name(),
62+
cliUtils.name(),
6263
);
6364
this.output.info("Using binary path", binPath);
64-
const stat = await cli.stat(binPath);
65+
const stat = await cliUtils.stat(binPath);
6566
if (stat === undefined) {
6667
this.output.info("No existing binary found, starting download");
6768
} else {
6869
this.output.info("Existing binary size is", prettyBytes(stat.size));
6970
try {
70-
const version = await cli.version(binPath);
71+
const version = await cliUtils.version(binPath);
7172
this.output.info("Existing binary version is", version);
7273
// If we have the right version we can avoid the request entirely.
7374
if (version === buildInfo.version) {
@@ -97,7 +98,7 @@ export class CliManager {
9798
}
9899

99100
// Remove any left-over old or temporary binaries and signatures.
100-
const removed = await cli.rmOld(binPath);
101+
const removed = await cliUtils.rmOld(binPath);
101102
removed.forEach(({ fileName, error }) => {
102103
if (error) {
103104
this.output.warn("Failed to remove", fileName, error);
@@ -107,7 +108,7 @@ export class CliManager {
107108
});
108109

109110
// Figure out where to get the binary.
110-
const binName = cli.name();
111+
const binName = cliUtils.name();
111112
const configSource = cfg.get("binarySource");
112113
const binSource =
113114
configSource && String(configSource).trim().length > 0
@@ -117,7 +118,7 @@ export class CliManager {
117118

118119
// Ideally we already caught that this was the right version and returned
119120
// early, but just in case set the ETag.
120-
const etag = stat !== undefined ? await cli.eTag(binPath) : "";
121+
const etag = stat !== undefined ? await cliUtils.eTag(binPath) : "";
121122
this.output.info("Using ETag", etag);
122123

123124
// Download the binary to a temporary file.
@@ -173,14 +174,14 @@ export class CliManager {
173174
await fs.rename(tempFile, binPath);
174175

175176
// For debugging, to see if the binary only partially downloaded.
176-
const newStat = await cli.stat(binPath);
177+
const newStat = await cliUtils.stat(binPath);
177178
this.output.info(
178179
"Downloaded binary size is",
179180
prettyBytes(newStat?.size || 0),
180181
);
181182

182183
// Make sure we can execute this new binary.
183-
const version = await cli.version(binPath);
184+
const version = await cliUtils.version(binPath);
184185
this.output.info("Downloaded binary version is", version);
185186

186187
return binPath;
@@ -199,8 +200,8 @@ export class CliManager {
199200
if (!value) {
200201
return;
201202
}
202-
const os = cli.goos();
203-
const arch = cli.goarch();
203+
const os = cliUtils.goos();
204+
const arch = cliUtils.goarch();
204205
const params = new URLSearchParams({
205206
title: `Support the \`${os}-${arch}\` platform`,
206207
body: `I'd like to use the \`${os}-${arch}\` architecture with the VS Code extension.`,
@@ -223,7 +224,7 @@ export class CliManager {
223224
return;
224225
}
225226
const params = new URLSearchParams({
226-
title: `Failed to download binary on \`${cli.goos()}-${cli.goarch()}\``,
227+
title: `Failed to download binary on \`${cliUtils.goos()}-${cliUtils.goarch()}\``,
227228
body: `Received status code \`${status}\` when downloading the binary.`,
228229
});
229230
const uri = vscode.Uri.parse(

0 commit comments

Comments
 (0)