Skip to content
Closed
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: 22 additions & 11 deletions editors/code/src/installation/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export async function ensureProperExtensionVersion(config: Config, state: Persis
return await tryDownloadNightlyExtension(config, state);
}

const currentExtReleaseDate = state.installedNightlyExtensionReleaseDate.get();
const currentExtPublishDate = state.installedNightlyExtensionReleaseDate.get();

if (currentExtReleaseDate === null) {
if (currentExtPublishDate === null) {
void vscode.window.showErrorMessage(
"Nightly release date must've been set during the installation. " +
"Did you download and install the nightly .vsix package manually?"
Expand All @@ -54,12 +54,14 @@ export async function ensureProperExtensionVersion(config: Config, state: Persis
}

const dateNow = new Date;
const hoursSinceLastUpdate = diffInHours(currentExtReleaseDate, dateNow);
const hoursSinceLastUpdate = diffInHours(dateNow, currentExtPublishDate);
log.debug(
"Current rust-analyzer nightly was downloaded", hoursSinceLastUpdate,
"hours ago, namely:", currentExtReleaseDate, "and now is", dateNow
"Current rust-analyzer nightly was published", hoursSinceLastUpdate,
"hours ago, namely:", currentExtPublishDate, "and now is", dateNow
);

assert(hoursSinceLastUpdate >= 0, "bruh");

if (hoursSinceLastUpdate < HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS) {
return;
}
Expand All @@ -69,11 +71,11 @@ export async function ensureProperExtensionVersion(config: Config, state: Persis

await tryDownloadNightlyExtension(config, state, releaseInfo => {
assert(
currentExtReleaseDate.getTime() === state.installedNightlyExtensionReleaseDate.get()?.getTime(),
currentExtPublishDate.getTime() === state.installedNightlyExtensionReleaseDate.get()?.getTime(),
"Other active VSCode instance has reinstalled the extension"
);

if (releaseInfo.releaseDate.getTime() === currentExtReleaseDate.getTime()) {
if (releaseInfo.releaseDate.getTime() === currentExtPublishDate.getTime()) {
vscode.window.showInformationMessage(
"Whoops, it appears that your nightly version is up-to-date. " +
"There might be some problems with the upcomming nightly release " +
Expand Down Expand Up @@ -139,8 +141,17 @@ function diffInHours(a: Date, b: Date): number {
// Discard the time and time-zone information (to abstract from daylight saving time bugs)
// https://stackoverflow.com/a/15289883/9259330

const utcA = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
const utcB = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());

return (utcA - utcB) / (1000 * 60 * 60);
return (toUtc(a) - toUtc(b)) / (1000 * 60 * 60);

function toUtc(date: Date) {
return Date.UTC(
date.getFullYear(),
date.getMonth(),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds()
);
}
}