Skip to content

Commit 2c78b16

Browse files
committed
WIP Assignments
wip WIP Assignments
1 parent 3e3924d commit 2c78b16

File tree

14 files changed

+566
-154
lines changed

14 files changed

+566
-154
lines changed

src/constants.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ export const GLOBAL_CLI_INSTALLATION_DIRNAME = join(
1515
);
1616

1717
const CLI_UNIX_PATHS = [
18+
// The local installation path takes precedence.
19+
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack"),
20+
// Check if it's in the PATH.
1821
"localstack",
22+
// Common installation paths.
1923
join("/", "usr", "bin", "localstack"),
2024
join("/", "usr", "local", "bin", "localstack"),
2125
join("/", "opt", "homebrew", "bin", "localstack"),
2226
join("/", "home", "linuxbrew", ".linuxbrew", "bin", "localstack"),
2327
join(homedir(), ".linuxbrew", "bin", "localstack"),
2428
join(homedir(), ".local", "bin", "localstack"),
25-
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack"),
2629
];
2730

2831
const CLI_WINDOWS_PATHS = [
32+
// The local installation path takes precedence.
33+
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack.exe"),
34+
// Check if it's in the PATH.
2935
"localstack.exe",
36+
// Common installation paths.
3037
join(GLOBAL_CLI_INSTALLATION_DIRNAME, "localstack", "localstack.exe"),
31-
join(LOCAL_CLI_INSTALLATION_DIRNAME, "localstack.exe"),
3238
];
3339

3440
export const CLI_PATHS =

src/extension.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import manage from "./plugins/manage.ts";
88
import setup from "./plugins/setup.ts";
99
import statusBar from "./plugins/status-bar.ts";
1010
import { PluginManager } from "./plugins.ts";
11+
import { createCliStatusTracker } from "./utils/cli.ts";
1112
import { createContainerStatusTracker } from "./utils/container-status.ts";
1213
import { createLocalStackStatusTracker } from "./utils/localstack-status.ts";
1314
import { getOrCreateExtensionSessionId } from "./utils/manage.ts";
@@ -29,6 +30,9 @@ export async function activate(context: ExtensionContext) {
2930
});
3031
context.subscriptions.push(outputChannel);
3132

33+
const cliStatusTracker = createCliStatusTracker(outputChannel);
34+
context.subscriptions.push(cliStatusTracker);
35+
3236
const timeTracker = createTimeTracker({ outputChannel });
3337

3438
const {
@@ -65,6 +69,7 @@ export async function activate(context: ExtensionContext) {
6569
const setupStatusTracker = await createSetupStatusTracker(
6670
outputChannel,
6771
timeTracker,
72+
cliStatusTracker,
6873
);
6974
context.subscriptions.push(setupStatusTracker);
7075
const endStatusTracker = Date.now();
@@ -100,6 +105,7 @@ export async function activate(context: ExtensionContext) {
100105
context,
101106
outputChannel,
102107
statusBarItem,
108+
cliStatusTracker,
103109
containerStatusTracker,
104110
localStackStatusTracker,
105111
setupStatusTracker,

src/plugins.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ms from "ms";
22
import type { ExtensionContext, LogOutputChannel, StatusBarItem } from "vscode";
33

4+
import type { LocalStackCliTracker } from "./utils/cli.ts";
45
import type { ContainerStatusTracker } from "./utils/container-status.ts";
56
import type { LocalStackStatusTracker } from "./utils/localstack-status.ts";
67
import type { SetupStatusTracker } from "./utils/setup-status.ts";
@@ -13,6 +14,7 @@ export interface PluginOptions {
1314
context: ExtensionContext;
1415
outputChannel: LogOutputChannel;
1516
statusBarItem: StatusBarItem;
17+
cliStatusTracker: LocalStackCliTracker;
1618
containerStatusTracker: ContainerStatusTracker;
1719
localStackStatusTracker: LocalStackStatusTracker;
1820
setupStatusTracker: SetupStatusTracker;

src/plugins/manage.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ import {
99

1010
export default createPlugin(
1111
"manage",
12-
({ context, outputChannel, telemetry, localStackStatusTracker }) => {
12+
({
13+
context,
14+
outputChannel,
15+
telemetry,
16+
localStackStatusTracker,
17+
cliStatusTracker,
18+
}) => {
1319
context.subscriptions.push(
1420
commands.registerCommand("localstack.start", async () => {
21+
const cliPath = cliStatusTracker.cliPath();
22+
if (!cliPath) {
23+
window.showInformationMessage(
24+
"LocalStack CLI could not be found. Please, run the setup wizard.",
25+
);
26+
return;
27+
}
28+
1529
if (localStackStatusTracker.status() !== "stopped") {
1630
window.showInformationMessage("LocalStack is already running.");
1731
return;
1832
}
1933
localStackStatusTracker.forceContainerStatus("running");
2034
try {
21-
await startLocalStack(outputChannel, telemetry);
35+
await startLocalStack(cliPath, outputChannel, telemetry);
2236
} catch {
2337
localStackStatusTracker.forceContainerStatus("stopped");
2438
}
@@ -27,12 +41,20 @@ export default createPlugin(
2741

2842
context.subscriptions.push(
2943
commands.registerCommand("localstack.stop", () => {
44+
const cliPath = cliStatusTracker.cliPath();
45+
if (!cliPath) {
46+
window.showInformationMessage(
47+
"LocalStack CLI could not be found. Please, run the setup wizard.",
48+
);
49+
return;
50+
}
51+
3052
if (localStackStatusTracker.status() !== "running") {
3153
window.showInformationMessage("LocalStack is not running.");
3254
return;
3355
}
3456
localStackStatusTracker.forceContainerStatus("stopping");
35-
void stopLocalStack(outputChannel, telemetry);
57+
void stopLocalStack(cliPath, outputChannel, telemetry);
3658
}),
3759
);
3860

src/plugins/setup.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default createPlugin(
2525
outputChannel,
2626
setupStatusTracker,
2727
localStackStatusTracker,
28+
cliStatusTracker,
2829
telemetry,
2930
}) => {
3031
context.subscriptions.push(
@@ -43,7 +44,15 @@ export default createPlugin(
4344
},
4445
});
4546

46-
window.withProgress(
47+
const cliPath = cliStatusTracker.cliPath();
48+
if (!cliPath) {
49+
void window.showErrorMessage(
50+
"LocalStack CLI is not configured. Please set it up before running the setup wizard.",
51+
);
52+
return;
53+
}
54+
55+
void window.withProgress(
4756
{
4857
location: ProgressLocation.Notification,
4958
title: "Setup LocalStack",
@@ -55,13 +64,14 @@ export default createPlugin(
5564
let authenticationStatus: "COMPLETED" | "SKIPPED" = "COMPLETED";
5665
{
5766
const installationStartedAt = new Date().toISOString();
58-
const { cancelled, skipped } = await runInstallProcess(
67+
const { cancelled, skipped } = await runInstallProcess({
68+
cliPath,
5969
progress,
6070
cancellationToken,
6171
outputChannel,
6272
telemetry,
63-
origin_trigger,
64-
);
73+
origin: origin_trigger,
74+
});
6575
cliStatus = skipped === true ? "SKIPPED" : "COMPLETED";
6676
if (cancelled || cancellationToken.isCancellationRequested) {
6777
telemetry.track({
@@ -227,8 +237,8 @@ export default createPlugin(
227237
// Activating the license pre-emptively to know its state during the setup process.
228238
const licenseCheckStartedAt = new Date().toISOString();
229239
const licenseIsValid = await minDelay(
230-
activateLicense(outputChannel).then(() =>
231-
checkIsLicenseValid(outputChannel),
240+
activateLicense(cliPath, outputChannel).then(() =>
241+
checkIsLicenseValid(cliPath, outputChannel),
232242
),
233243
);
234244
if (!licenseIsValid) {
@@ -240,6 +250,7 @@ export default createPlugin(
240250
await commands.executeCommand("localstack.openLicensePage");
241251

242252
await activateLicenseUntilValid(
253+
cliPath,
243254
outputChannel,
244255
cancellationToken,
245256
);

src/plugins/status-bar.ts

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ import { commands, QuickPickItemKind, ThemeColor, window } from "vscode";
22
import type { QuickPickItem } from "vscode";
33

44
import { createPlugin } from "../plugins.ts";
5+
import { immediateOnce } from "../utils/immediate-once.ts";
56

67
export default createPlugin(
78
"status-bar",
89
({
910
context,
1011
statusBarItem,
12+
cliStatusTracker,
1113
localStackStatusTracker,
1214
setupStatusTracker,
1315
outputChannel,
1416
}) => {
1517
context.subscriptions.push(
1618
commands.registerCommand("localstack.showCommands", async () => {
1719
const shouldShowLocalStackStart = () =>
18-
setupStatusTracker.statuses().isInstalled &&
20+
cliStatusTracker.status() === "ok" &&
1921
localStackStatusTracker.status() === "stopped";
2022
const shouldShowLocalStackStop = () =>
21-
setupStatusTracker.statuses().isInstalled &&
23+
cliStatusTracker.status() === "ok" &&
2224
localStackStatusTracker.status() === "running";
2325
const shouldShowRunSetupWizard = () =>
2426
setupStatusTracker.status() === "setup_required";
@@ -77,63 +79,84 @@ export default createPlugin(
7779
}),
7880
);
7981

80-
context.subscriptions.push(
81-
commands.registerCommand("localstack.refreshStatusBar", () => {
82-
const setupStatus = setupStatusTracker.status();
83-
const localStackStatus = localStackStatusTracker.status();
84-
const localStackInstalled = setupStatusTracker.statuses().isInstalled;
85-
86-
statusBarItem.command = "localstack.showCommands";
87-
statusBarItem.backgroundColor =
88-
setupStatus === "setup_required"
89-
? new ThemeColor("statusBarItem.errorBackground")
90-
: undefined;
91-
92-
const shouldSpin =
93-
localStackStatus === "starting" || localStackStatus === "stopping";
94-
const icon =
95-
setupStatus === "setup_required"
96-
? "$(error)"
97-
: shouldSpin
98-
? "$(sync~spin)"
99-
: "$(localstack-logo)";
100-
101-
const statusText = localStackInstalled
102-
? `${localStackStatus}`
103-
: "not installed";
104-
statusBarItem.text = `${icon} LocalStack: ${statusText}`;
105-
106-
statusBarItem.tooltip = "Show LocalStack commands";
107-
statusBarItem.show();
108-
}),
109-
);
110-
111-
let refreshStatusBarImmediateId: NodeJS.Immediate | undefined;
112-
const refreshStatusBarImmediate = () => {
113-
if (!refreshStatusBarImmediateId) {
114-
refreshStatusBarImmediateId = setImmediate(() => {
115-
void commands.executeCommand("localstack.refreshStatusBar");
116-
refreshStatusBarImmediateId = undefined;
117-
});
82+
// context.subscriptions.push(
83+
// commands.registerCommand("localstack.refreshStatusBar", () => {
84+
// const setupStatus = setupStatusTracker.status();
85+
// const localStackStatus = localStackStatusTracker.status();
86+
// const localStackInstalled = cliStatusTracker.status() === "ok"
87+
88+
// statusBarItem.command = "localstack.showCommands";
89+
// statusBarItem.backgroundColor =
90+
// setupStatus === "setup_required"
91+
// ? new ThemeColor("statusBarItem.errorBackground")
92+
// : undefined;
93+
94+
// const shouldSpin =
95+
// localStackStatus === "starting" || localStackStatus === "stopping";
96+
// const icon =
97+
// setupStatus === "setup_required"
98+
// ? "$(error)"
99+
// : shouldSpin
100+
// ? "$(sync~spin)"
101+
// : "$(localstack-logo)";
102+
103+
// const statusText = localStackInstalled
104+
// ? `${localStackStatus}`
105+
// : "not installed";
106+
// statusBarItem.text = `${icon} LocalStack: ${statusText}`;
107+
108+
// statusBarItem.tooltip = "Show LocalStack commands";
109+
// statusBarItem.show();
110+
// }),
111+
// );
112+
113+
const refreshStatusBar = immediateOnce(() => {
114+
// await commands.executeCommand("localstack.refreshStatusBar");
115+
const setupStatus = setupStatusTracker.status();
116+
const localStackStatus = localStackStatusTracker.status();
117+
const cliStatus = cliStatusTracker.status();
118+
119+
if (
120+
setupStatus === undefined ||
121+
localStackStatus === undefined ||
122+
cliStatus === undefined
123+
) {
124+
return;
118125
}
119-
};
120126

121-
context.subscriptions.push({
122-
dispose() {
123-
clearImmediate(refreshStatusBarImmediateId);
124-
},
127+
statusBarItem.command = "localstack.showCommands";
128+
statusBarItem.backgroundColor =
129+
setupStatus === "setup_required"
130+
? new ThemeColor("statusBarItem.errorBackground")
131+
: undefined;
132+
133+
const shouldSpin =
134+
localStackStatus === "starting" || localStackStatus === "stopping";
135+
const icon =
136+
setupStatus === "setup_required"
137+
? "$(error)"
138+
: shouldSpin
139+
? "$(sync~spin)"
140+
: "$(localstack-logo)";
141+
142+
const statusText =
143+
cliStatus === "ok" ? `${localStackStatus}` : "not installed";
144+
statusBarItem.text = `${icon} LocalStack: ${statusText}`;
145+
146+
statusBarItem.tooltip = "Show LocalStack commands";
147+
// statusBarItem.show();
125148
});
126149

127-
refreshStatusBarImmediate();
150+
// refreshStatusBar();
128151

129152
localStackStatusTracker.onChange(() => {
130153
outputChannel.trace("[status-bar]: localStackStatusTracker changed");
131-
refreshStatusBarImmediate();
154+
refreshStatusBar();
132155
});
133156

134157
setupStatusTracker.onChange(() => {
135158
outputChannel.trace("[status-bar]: setupStatusTracker changed");
136-
refreshStatusBarImmediate();
159+
refreshStatusBar();
137160
});
138161
},
139162
);

0 commit comments

Comments
 (0)