Skip to content

Commit d1985b6

Browse files
committed
refactor: replace util modules with topic-named modules
Remove `src/util.ts` and the `src/util/` folder. Helpers with a single owner move next to it, and shared helpers move into topic folders: - `fs/`: `atomicWrite`, `fileCleanup`, `expandPath` - `text/`: `lowercase`, `countSubstring`, `shellEscape` - `ui/`: `progress`, `prompts`, `statusBar` - `uri/url`, `remote/authority`, `remote/sshLogPort`, `telemetry/date`, `login/credentials`, `webviews/workspaces/poller` Split or rename the feature-level grab-bag files by what they hold: - `api/api-helper` into `error/normalize` (`errToStr`), `deployment/roles`, `workspace/agents`, `workspace/labels` and `api/agentMetadata` - `api/utils` to `api/httpAgent`, `api/agentMetadataHelper` to `api/agentMetadata`, `core/cliUtils` to `core/cliBinary` - `error/errorUtils` into `error/abort` and `error/normalize` - `logging/utils` into `logging/ids` and `logging/formatters` - `oauth/utils` into `oauth/pkce`, `oauth/tokens` and `oauth/constants` - `websocket/utils` into `websocket/encoding` and `websocket/handshakeError` Tests move and split to mirror the new layout. No behavior changes.
1 parent 58ef491 commit d1985b6

130 files changed

Lines changed: 1032 additions & 1041 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/announcements/manager.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as vscode from "vscode";
22

3-
import { errToStr } from "../api/api-helper";
4-
import { withProgress } from "../progress";
3+
import { errToStr } from "../error/normalize";
54
import { areNotificationsDisabled } from "../settings/notifications";
6-
import { createStatusBarItem } from "../util/statusBar";
5+
import { withProgress } from "../ui/progress";
6+
import { createStatusBarItem } from "../ui/statusBar";
77

88
import {
99
type Announcement,
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import { type WorkspaceAgent } from "coder/site/src/api/typesGenerated";
22
import * as vscode from "vscode";
3+
import { z } from "zod";
34

5+
import { errToStr } from "../error/normalize";
46
import { WebSocketCloseCode } from "../websocket/codes";
57

6-
import {
7-
type AgentMetadataEvent,
8-
AgentMetadataEventSchemaArray,
9-
errToStr,
10-
} from "./api-helper";
11-
128
import type { UnidirectionalStream } from "../websocket/eventStreamConnection";
139

10+
export const AgentMetadataEventSchema = z.object({
11+
result: z.object({
12+
collected_at: z.string(),
13+
age: z.number(),
14+
value: z.string(),
15+
error: z.string(),
16+
}),
17+
description: z.object({
18+
display_name: z.string(),
19+
key: z.string(),
20+
script: z.string(),
21+
interval: z.number(),
22+
timeout: z.number(),
23+
}),
24+
});
25+
26+
export const AgentMetadataEventSchemaArray = z.array(AgentMetadataEventSchema);
27+
28+
export type AgentMetadataEvent = z.infer<typeof AgentMetadataEventSchema>;
29+
1430
export interface AgentMetadataClient {
1531
watchAgentMetadata(
1632
agentId: string,

‎src/api/api-helper.ts‎

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

‎src/api/authInterceptor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type AxiosError, isAxiosError } from "axios";
22

33
import { AuthTelemetry } from "../instrumentation/auth";
44
import { OAuthError } from "../oauth/errors";
5-
import { toSafeHost } from "../util/uri";
5+
import { toSafeHost } from "../uri/url";
66

77
import { HttpStatusCode } from "./httpStatusCode";
88

‎src/api/coderApi.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import {
1414
} from "../configWatcher";
1515
import { sessionId } from "../core/sessionId";
1616
import { ClientCertificateError } from "../error/clientCertificateError";
17-
import { toError } from "../error/errorUtils";
17+
import { toError } from "../error/normalize";
1818
import { ServerCertificateError } from "../error/serverCertificateError";
1919
import { getHeaders } from "../headers";
2020
import { EventStreamLogger } from "../logging/eventStreamLogger";
21+
import { sizeOf } from "../logging/formatters";
2122
import {
2223
createRequestMeta,
2324
logError,
@@ -29,7 +30,6 @@ import {
2930
type RequestConfigWithMeta,
3031
type HttpClientLogLevel,
3132
} from "../logging/types";
32-
import { sizeOf } from "../logging/utils";
3333
import { AuthConfigTracker } from "../settings/authConfig";
3434
import { getHeaderCommand } from "../settings/headers";
3535
import { readHttpClientLogLevel } from "../settings/logger";
@@ -38,6 +38,7 @@ import {
3838
type TelemetryReporter,
3939
} from "../telemetry/reporter";
4040
import { WebSocketCloseCode } from "../websocket/codes";
41+
import { handshakeStatus } from "../websocket/handshakeError";
4142
import {
4243
OneWayWebSocket,
4344
type OneWayWebSocketInit,
@@ -49,16 +50,15 @@ import {
4950
type SocketFactory,
5051
} from "../websocket/reconnectingWebSocket";
5152
import { SseConnection } from "../websocket/sseConnection";
52-
import { handshakeStatus } from "../websocket/utils";
5353

5454
import { getRefreshCommand, refreshCertificates } from "./certificateRefresh";
55+
import { createHttpAgent } from "./httpAgent";
5556
import { HttpStatusCode } from "./httpStatusCode";
5657
import {
5758
parseApiResponse,
5859
VALIDATED_RESPONSES,
5960
type ValidatedMethods,
6061
} from "./responseValidation";
61-
import { createHttpAgent } from "./utils";
6262

6363
import type {
6464
GetInboxNotificationResponse,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
22
import { ProxyAgent } from "proxy-agent";
33
import { type WorkspaceConfiguration } from "vscode";
44

5-
import { expandPath } from "../util";
5+
import { expandPath } from "../fs/expandPath";
66

77
import { getProxyForUrl, joinNoProxy } from "./proxy";
88

‎src/api/workspace.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { spawn } from "node:child_process";
22
import * as vscode from "vscode";
33

4+
import { errToStr } from "../error/normalize";
45
import { getGlobalFlags, type CliAuth } from "../settings/cli";
5-
6-
import { errToStr, createWorkspaceIdentifier } from "./api-helper";
6+
import { createWorkspaceIdentifier } from "../workspace/labels";
77

88
import type { Api } from "coder/site/src/api/api";
99
import type {

‎src/command/diagnosticFlow.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as vscode from "vscode";
22
import { ZodError } from "zod";
33

4-
import { toError } from "../error/errorUtils";
5-
import { withCancellableProgress, type ProgressContext } from "../progress";
4+
import { toError } from "../error/normalize";
5+
import { withCancellableProgress, type ProgressContext } from "../ui/progress";
66
import { openJsonBeside } from "../webviews/openJson";
77

88
import type { DiagnosticTrace } from "../instrumentation/diagnostics";

‎src/commands.ts‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import * as path from "node:path";
44
import * as semver from "semver";
55
import * as vscode from "vscode";
66

7-
import {
8-
createWorkspaceIdentifier,
9-
extractAgents,
10-
workspaceStatusLabel,
11-
} from "./api/api-helper";
127
import { runDiagnosticCli } from "./command/diagnosticFlow";
138
import * as cliExec from "./core/cliExec";
9+
import { raceWithAbort } from "./error/abort";
1410
import { CertificateError } from "./error/certificateError";
15-
import { raceWithAbort, toError } from "./error/errorUtils";
11+
import { toError } from "./error/normalize";
1612
import { type CliFeatureSet, cliFeatureSet } from "./featureSet";
1713
import {
1814
AuthTelemetry,
@@ -34,11 +30,15 @@ import {
3430
type WorkspacePickerSource,
3531
} from "./instrumentation/workspaceOpen";
3632
import {
37-
reportElapsedProgress,
38-
withCancellableProgress,
39-
withProgress,
40-
} from "./progress";
41-
import { maybeAskAgent, maybeAskUrl } from "./promptUtils";
33+
LegacyEditorId,
34+
currentEditorId,
35+
hostEditorId,
36+
isRemoteAuthorityCompatible,
37+
parseRemoteAuthority,
38+
sshHostOf,
39+
toLegacyAuthority,
40+
toRemoteAuthority,
41+
} from "./remote/authority";
4242
import {
4343
RECOMMENDED_SSH_SETTINGS,
4444
applySettingOverrides,
@@ -51,19 +51,20 @@ import {
5151
} from "./supportBundle/remoteServerDataPath";
5252
import { runExportTelemetryCommand } from "./telemetry/export/command";
5353
import {
54-
LegacyEditorId,
55-
currentEditorId,
56-
hostEditorId,
57-
isRemoteAuthorityCompatible,
58-
parseRemoteAuthority,
59-
sshHostOf,
60-
toLegacyAuthority,
61-
toRemoteAuthority,
62-
} from "./util/authority";
63-
import { openInBrowser, toSafeHost } from "./util/uri";
54+
reportElapsedProgress,
55+
withCancellableProgress,
56+
withProgress,
57+
} from "./ui/progress";
58+
import { maybeAskAgent, maybeAskUrl } from "./ui/prompts";
59+
import { openInBrowser, toSafeHost } from "./uri/url";
6460
import { vscodeProposed } from "./vscodeProposed";
6561
import { parseNetcheckReport } from "./webviews/netcheck/types";
6662
import { parseSpeedtestResult } from "./webviews/speedtest/types";
63+
import { extractAgents } from "./workspace/agents";
64+
import {
65+
createWorkspaceIdentifier,
66+
workspaceStatusLabel,
67+
} from "./workspace/labels";
6768
import {
6869
AgentTreeItem,
6970
type OpenableTreeItem,

0 commit comments

Comments
 (0)