From 91e310996bbf1c22da56143eff9a81e546d7466a Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 29 Mar 2024 06:29:46 +0800 Subject: [PATCH 1/2] chore: create insiders.json --- insiders.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 insiders.json diff --git a/insiders.json b/insiders.json new file mode 100644 index 000000000..fbbbc9062 --- /dev/null +++ b/insiders.json @@ -0,0 +1,8 @@ +{ + "versions": [ + { + "version": "2.1.0-insiders.1", + "date": "2024-03-29" + } + ] +} \ No newline at end of file From 44ce1c89b923dda30840daa34b17d8b95c197a23 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Fri, 29 Mar 2024 06:43:46 +0800 Subject: [PATCH 2/2] chore: update insider status --- extensions/vscode/src/common.ts | 93 +++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/extensions/vscode/src/common.ts b/extensions/vscode/src/common.ts index 313ad4ab9..5cbebd6ef 100644 --- a/extensions/vscode/src/common.ts +++ b/extensions/vscode/src/common.ts @@ -97,43 +97,68 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang hybridModeStatus.severity = vscode.LanguageStatusSeverity.Warning; } + const item = vscode.languages.createLanguageStatusItem('vue-insider', 'vue'); if (!context.extension.packageJSON.version.includes('-insider')) { - const createLanguageStatus = () => { - const item = vscode.languages.createLanguageStatusItem('vue-upgrade', 'vue'); - item.text = '✨ Upgrade Vue - Official'; - item.severity = vscode.LanguageStatusSeverity.Warning; - item.command = { - title: 'Open Link', - command: 'vscode.open', - arguments: ['https://github.com/vuejs/language-tools/discussions/4127'], - }; + item.text = '✨ Get Vue - Official Insiders'; + item.severity = vscode.LanguageStatusSeverity.Warning; + item.command = { + title: 'More Info', + command: 'vscode.open', + arguments: ['https://github.com/vuejs/language-tools/wiki/Get-Insiders'], }; - const yyyymmdd = new Date().toISOString().split('T')[0].replace(/-/g, ''); - if (context.globalState.get('vue-upgrade-promote-date') !== yyyymmdd) { - context.globalState.update('vue-upgrade-promote-date', yyyymmdd); - let s = 10; - const upgradeStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 10000); - const interval = setInterval(() => { - s--; - upgradeStatus.text = `✨ Upgrade Vue - Official (${s})`; - if (s <= 0) { - upgradeStatus.dispose(); - clearInterval(interval); - createLanguageStatus(); + } + else { + const versionsUrl = 'https://cdn.jsdelivr.net/gh/vuejs/language-tools/insiders.json'; + item.text = '🚀 Vue - Official Insiders'; + item.detail = 'Installed'; + item.busy = true; + const currentVersion = context.extension.packageJSON.version; + fetch(versionsUrl) + .then(res => res.json()) + .then(({ versions }: { versions: { version: string; date: string; }[]; }) => { + item.command = { + title: 'Select Version', + command: 'vue-insiders.selectVersion', + arguments: [{ versions }], + }; + if (versions.length && versions[0].version !== currentVersion) { + item.command.title = 'Update'; + item.detail = 'New version available'; + item.severity = vscode.LanguageStatusSeverity.Warning; } - }, 1000); - upgradeStatus.text = `✨ Upgrade Vue - Official (${s})`; - upgradeStatus.color = '#ebb549'; - upgradeStatus.command = { - title: 'Open Link', - command: 'vscode.open', - arguments: ['https://github.com/vuejs/language-tools/discussions/4127'], - }; - upgradeStatus.show(); - } - else { - createLanguageStatus(); - } + }) + .catch(() => { + item.detail = 'Failed to fetch versions'; + }) + .finally(() => { + item.busy = false; + }); + vscode.commands.registerCommand('vue-insiders.selectVersion', async ({ versions }: { versions: { version: string; date: string; }[]; }) => { + const items = versions.map(version => ({ + label: version.version, + description: version.date + (version.version === currentVersion ? ' (current)' : ''), + })); + if (!items.some(item => item.description?.endsWith('(current)'))) { + items.push({ + label: '', + kind: vscode.QuickPickItemKind.Separator, + }, { + label: currentVersion, + description: '(current)', + }); + } + const selected = await vscode.window.showQuickPick( + items, + { + canPickMany: false, + placeHolder: 'Select a version', + }); + if (!selected || selected.label === currentVersion) { + return; + } + const updateUrl = `https://github.com/volarjs/insiders/releases/tag/v${selected.label}`; + vscode.env.openExternal(vscode.Uri.parse(updateUrl)); + }); } async function requestReloadVscode(msg: string) {