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
33 changes: 19 additions & 14 deletions src/plugins/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
});

window.withProgress(

Check warning on line 46 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
{
location: ProgressLocation.Notification,
title: "Setup LocalStack",
Expand Down Expand Up @@ -296,8 +296,6 @@
}),
);

void commands.executeCommand("localstack.refreshStatusBar");

progress.report({
message:
'Finished configuring the AWS profile named "localstack".',
Expand Down Expand Up @@ -326,27 +324,29 @@
return;
}

void commands.executeCommand("localstack.refreshStatusBar");

/////////////////////////////////////////////////////////////////////
if (localStackStatusTracker.status() === "running") {
window

Check warning on line 331 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.showInformationMessage("LocalStack is running.", {
title: "View Logs",
command: "localstack.viewLogs",
})
.then((selection) => {
if (selection) {
commands.executeCommand(selection.command);

Check warning on line 338 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
});
} else {
window

Check warning on line 342 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.showInformationMessage("LocalStack is ready to start.", {
title: "Start LocalStack",
command: "localstack.start",
})
.then((selection) => {
if (selection) {
commands.executeCommand(selection.command);

Check warning on line 349 in src/plugins/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
});
}
Expand All @@ -368,17 +368,22 @@
),
);

if (setupStatusTracker.status() === "setup_required") {
window
.showInformationMessage("Setup LocalStack to get started.", {
title: "Setup",
command: "localstack.setup",
})
.then((selected) => {
if (selected) {
commands.executeCommand(selected.command, "extension_startup");
}
});
}
setupStatusTracker.onChange((status) => {
if (status === "setup_required") {
void window
.showInformationMessage("Setup LocalStack to get started.", {
title: "Setup",
command: "localstack.setup",
})
.then((selected) => {
if (selected) {
void commands.executeCommand(
selected.command,
"extension_startup",
);
}
});
}
});
},
);
34 changes: 31 additions & 3 deletions src/utils/setup-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,30 @@ export async function createSetupStatusTracker(
);

const checkStatusNow = async () => {
const allStatusesInitialized = Object.values({
awsProfileTracker: awsProfileTracker.status(),
authTracker: localStackAuthenticationTracker.status(),
licenseTracker: licenseTracker.status(),
}).every((check) => check !== undefined);

if (!allStatusesInitialized) {
outputChannel.trace(
`[setup-status] File watchers not initialized yet, skipping status check : ${JSON.stringify(
{
awsProfileTracker: awsProfileTracker.status() ?? "undefined",
authTracker:
localStackAuthenticationTracker.status() ?? "undefined",
licenseTracker: licenseTracker.status() ?? "undefined",
},
)}`,
);
return;
}

statuses = await checkSetupStatus(outputChannel);

const setupRequired = [
Object.values(statuses),
...Object.values(statuses),
awsProfileTracker.status() === "ok",
localStackAuthenticationTracker.status() === "ok",
licenseTracker.status() === "ok",
Expand All @@ -60,7 +80,12 @@ export async function createSetupStatusTracker(
if (status !== newStatus) {
status = newStatus;
outputChannel.trace(
`[setup-status] Status changed to ${JSON.stringify(statuses)}`,
`[setup-status] Status changed to ${JSON.stringify({
...statuses,
awsProfileTracker: awsProfileTracker.status() ?? "undefined",
authTracker: localStackAuthenticationTracker.status() ?? "undefined",
licenseTracker: licenseTracker.status() ?? "undefined",
})}`,
);
await emitter.emit(status);
}
Expand Down Expand Up @@ -178,6 +203,9 @@ function createFileStatusTracker(
outputChannel.error(error instanceof Error ? error : String(error));
});

// Update the status immediately on file tracker initialization
void updateStatus();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I checked the docs and chokidar docs should call one of their callbacks upon initialization:

ignoreInitial (default: false). If set to false then add/addDir events are also emitted for matching paths while instantiating the watching as chokidar discovers these file paths (before the ready event).

So I think this shouldn't be required, although it doesn't hurt either.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retract my words.

Chokidar will only emit add if the file was already present, but won't emit unlink. We are interested in that, as well, so we have to run the check.


return {
status() {
return status;
Expand Down Expand Up @@ -247,7 +275,7 @@ function createLicenseStatusTracker(
return createFileStatusTracker(
outputChannel,
"[setup-status.license]",
[LICENSE_FILENAME],
[LOCALSTACK_AUTH_FILENAME, LICENSE_FILENAME], //TODO rewrite to depend on change in localStackAuthenticationTracker
async () =>
(await checkIsLicenseValid(outputChannel)) ? "ok" : "setup_required",
);
Expand Down
Loading