Skip to content

Commit e6329c5

Browse files
committed
Remove unused code
1 parent 6dd75db commit e6329c5

File tree

4 files changed

+3
-148
lines changed

4 files changed

+3
-148
lines changed

src/plugins/status-bar.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { commands, QuickPickItemKind, ThemeColor, window } from "vscode";
22
import type { QuickPickItem } from "vscode";
33

44
import { createPlugin } from "../plugins.ts";
5-
import { checkLocalstackInstalled } from "../utils/install.ts";
65

76
export default createPlugin(
87
"status-bar",

src/utils/exec.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
11
import * as childProcess from "node:child_process";
22
import * as util from "node:util";
33

4-
// import { appendToEnvPath } from "./env-path.ts";
5-
6-
export const COMMAND_NOT_FOUND_EXIT_CODE = 127;
7-
84
export const exec = util.promisify(childProcess.exec);
9-
10-
// const execAsync = util.promisify(childProcess.exec);
11-
12-
// export const exec = (command: string, options?: childProcess.ExecOptions) => {
13-
// return execAsync(command, {
14-
// env: {
15-
// ...options?.env,
16-
// //
17-
// PATH: appendToEnvPath(options?.env.PATH ?? "", ""),
18-
// },
19-
// ...options,
20-
// });
21-
// };
22-
23-
export interface ExecException extends Error {
24-
cmd: string;
25-
code: number;
26-
stdout: string;
27-
stderr: string;
28-
}
29-
30-
export function isExecException(error: unknown): error is ExecException {
31-
return (
32-
typeof error === "object" &&
33-
error !== null &&
34-
"code" in error &&
35-
"cmd" in error &&
36-
"stderr" in error &&
37-
"stdout" in error
38-
);
39-
}

src/utils/manage.ts

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ import type { ExtensionContext, LogOutputChannel, MessageItem } from "vscode";
33
import { commands, env, Uri, window } from "vscode";
44

55
import { spawnLocalStack } from "./cli.ts";
6-
import { exec } from "./exec.ts";
76
import { checkIsLicenseValid } from "./license.ts";
87
import type { Telemetry } from "./telemetry.ts";
98

10-
export type LocalstackStatus = "running" | "starting" | "stopping" | "stopped";
11-
12-
let previousStatus: LocalstackStatus | undefined;
13-
149
export async function fetchHealth(): Promise<boolean> {
15-
// health is ok in the majority of use cases, however, determining status based on it can be flaky.
16-
// for example, if localstack becomes unhealthy while running for reasons other that stop then reporting "stopping" may be misleading.
17-
// though we don't know if it happens often.
10+
// Health is OK in the majority of use cases, however, determining status based on it can be flaky.
11+
// For example, if localstack becomes unhealthy while running for reasons other than the stop,
12+
// then reporting "stopping" may be misleading.
1813
try {
1914
const response = await fetch("http://127.0.0.1:4566/_localstack/health");
2015
return response.ok;
@@ -38,50 +33,6 @@ async function fetchLocalStackSessionId(): Promise<string> {
3833
return "";
3934
}
4035

41-
async function getStatusFromCLI(): Promise<LocalstackStatus | undefined> {
42-
try {
43-
const result = await exec(
44-
"docker inspect -f '{{.State.Status}}' localstack-main",
45-
);
46-
if (result.stdout.includes("running")) {
47-
return "running";
48-
} else if (result.stdout.includes("stopped")) {
49-
return "stopped";
50-
}
51-
} catch {
52-
return undefined;
53-
}
54-
}
55-
56-
export async function getLocalstackStatus(): Promise<LocalstackStatus> {
57-
const [healthOk, status] = await Promise.all([
58-
fetchHealth(),
59-
getStatusFromCLI(),
60-
]);
61-
62-
if (healthOk && status === "running") {
63-
previousStatus = "running";
64-
return "running";
65-
}
66-
67-
if (!healthOk && status !== "running") {
68-
previousStatus = "stopped";
69-
return "stopped";
70-
}
71-
72-
if (previousStatus === "stopped" && !healthOk && status === "running") {
73-
previousStatus = "starting";
74-
return "starting";
75-
}
76-
77-
if (previousStatus === "running" && !healthOk) {
78-
previousStatus = "stopping";
79-
return "stopping";
80-
}
81-
82-
return previousStatus ?? "stopped";
83-
}
84-
8536
export async function startLocalStack(
8637
outputChannel: LogOutputChannel,
8738
telemetry: Telemetry,
@@ -226,25 +177,6 @@ async function showErrorMessage(
226177
}
227178
}
228179

229-
export async function getLocalstackVersion(
230-
outputChannel: LogOutputChannel,
231-
): Promise<string | undefined> {
232-
try {
233-
const { stdout } = await exec("localstack --version");
234-
const versionMatch = stdout.match(/\d+\.\d+\.\d+/);
235-
if (!versionMatch) {
236-
outputChannel.error(
237-
`Failed to parse LocalStack from version output: ${stdout}`,
238-
);
239-
return undefined;
240-
}
241-
242-
return versionMatch[0];
243-
} catch {
244-
return undefined;
245-
}
246-
}
247-
248180
// Checks for session_id in workspaceState, creates if missing
249181
export async function getOrCreateExtensionSessionId(
250182
context: ExtensionContext,

src/utils/prompts.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,6 @@ import type { CancellationToken, LogOutputChannel } from "vscode";
66

77
import { spawn, SpawnError } from "./spawn.ts";
88

9-
export interface DarwinPromptOptions {
10-
message: string;
11-
title: string;
12-
icon: "note";
13-
buttons: string[];
14-
outputChannel: LogOutputChannel;
15-
outputLabel?: string;
16-
cancellationToken?: CancellationToken;
17-
}
18-
19-
export async function darwinPrompt(
20-
options: DarwinPromptOptions,
21-
): Promise<{ cancelled: boolean }> {
22-
try {
23-
await spawn(
24-
"osascript",
25-
[
26-
"-e",
27-
`'display dialog ${JSON.stringify(options.message)} with title ${JSON.stringify(options.title)} with icon ${options.icon} buttons {${options.buttons.map((button) => JSON.stringify(button)).join(",")}} default button 1'`,
28-
],
29-
{
30-
outputChannel: options.outputChannel,
31-
outputLabel: options.outputLabel,
32-
cancellationToken: options.cancellationToken,
33-
},
34-
);
35-
return {
36-
cancelled: false,
37-
};
38-
} catch (error) {
39-
options.outputChannel.error(error instanceof Error ? error : String(error));
40-
41-
// osascript will terminate with code 1 if the user cancels the dialog.
42-
if (error instanceof SpawnError && error.code === 1) {
43-
return { cancelled: true };
44-
}
45-
46-
throw error;
47-
}
48-
}
49-
509
export interface SpawnElevatedDarwinOptions {
5110
script: string;
5211
outputChannel: LogOutputChannel;

0 commit comments

Comments
 (0)