From 498bb8176faf4a3fc03ff789c65931c6430cdb99 Mon Sep 17 00:00:00 2001 From: Viet Dinh <54ckb0y789@gmail.com> Date: Thu, 28 Mar 2024 13:06:37 -0400 Subject: [PATCH] fix: correct conditions for new nightlies --- client/src/extension.ts | 12 ++++++++---- client/src/utils.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index fe5dec0..7c887c5 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -17,6 +17,7 @@ import { isWindows, makeStates, openLink, + parseNightly, tryStatSync, which, } from "./utils"; @@ -145,10 +146,13 @@ async function downloadLspBinary(context: vscode.ExtensionContext) { const shaLink = `${link}.sha256`; const shaOutput = `${latest}.sha256`; - let stat: Stats | null; - const hasNewerNightly = - // biome-ignore lint/suspicious/noAssignInExpressions: - release.startsWith("nightly") && (!(stat = tryStatSync(vsixOutput)) || compareDate(stat.ctime, new Date()) < 0); + const hasNewerNightly = (() => { + if (!release.startsWith("nightly-")) return false; + const releaseDate = parseNightly(release); + const vsixStat = tryStatSync(vsixOutput); + if (!vsixStat) return false; + return compareDate(vsixStat.birthtime, releaseDate) < 0; + })(); const powershell = { shell: "powershell.exe" }; const sh = { shell: "sh" }; diff --git a/client/src/utils.ts b/client/src/utils.ts index 46009e0..321200a 100644 --- a/client/src/utils.ts +++ b/client/src/utils.ts @@ -91,3 +91,15 @@ export async function openLink(url: string) { } return await $(`${opener} ${url}`); } + +export function parseNightly(releaseName: string) { + if (!releaseName.startsWith('nightly-')) { + throw new Error(`bug: releaseName=${releaseName} is not a nightly release`); + } + // nightly-YYYYMMDD + const dateString = releaseName.slice('nightly-'.length); + const yearString = dateString.slice(0, 4); + const monthString = dateString.slice(4, 6); + const dayString = dateString.slice(6, 8); + return new Date(Date.UTC(+yearString, +monthString, +dayString)) +}