Skip to content

Commit 851d9ca

Browse files
committed
fix: fetch insiders data correctly
1 parent 423bb6b commit 851d9ca

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

extensions/vscode/src/common.ts

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as lsp from "@volar/vscode";
2-
import type { VueInitializationOptions } from "@vue/language-server";
1+
import * as lsp from '@volar/vscode';
2+
import type { VueInitializationOptions } from '@vue/language-server';
33
import {
44
executeCommand,
55
nextTick,
@@ -9,14 +9,14 @@ import {
99
useCommand,
1010
useVscodeContext,
1111
watch,
12-
} from "reactive-vscode";
13-
import * as vscode from "vscode";
14-
import { config } from "./config";
15-
import { activate as activateDoctor } from "./features/doctor";
16-
import { activate as activateNameCasing } from "./features/nameCasing";
17-
import { activate as activateSplitEditors } from "./features/splitEditors";
18-
import { enabledHybridMode, enabledTypeScriptPlugin, useHybridModeStatusItem, useHybridModeTips } from "./hybridMode";
19-
import { useInsidersStatusItem } from "./insiders";
12+
} from 'reactive-vscode';
13+
import * as vscode from 'vscode';
14+
import { config } from './config';
15+
import { activate as activateDoctor } from './features/doctor';
16+
import { activate as activateNameCasing } from './features/nameCasing';
17+
import { activate as activateSplitEditors } from './features/splitEditors';
18+
import { enabledHybridMode, enabledTypeScriptPlugin, useHybridModeStatusItem, useHybridModeTips } from './hybridMode';
19+
import { useInsidersStatusItem } from './insiders';
2020

2121
let client: lsp.BaseLanguageClient;
2222

@@ -54,13 +54,13 @@ async function activateLc(
5454
context: vscode.ExtensionContext,
5555
createLc: CreateLanguageClient
5656
) {
57-
useVscodeContext("vue.activated", true);
58-
const outputChannel = useOutputChannel("Vue Language Server");
57+
useVscodeContext('vue.activated', true);
58+
const outputChannel = useOutputChannel('Vue Language Server');
5959
const selectors = config.server.value.includeLanguages;
6060

6161
client = createLc(
62-
"vue",
63-
"Vue",
62+
'vue',
63+
'Vue',
6464
selectors,
6565
await getInitializationOptions(context, enabledHybridMode.value),
6666
6009,
@@ -71,46 +71,44 @@ async function activateLc(
7171
if (newValues[0] !== oldValues[0]) {
7272
requestReloadVscode(
7373
newValues[0]
74-
? "Please reload VSCode to enable Hybrid Mode."
75-
: "Please reload VSCode to disable Hybrid Mode."
74+
? 'Please reload VSCode to enable Hybrid Mode.'
75+
: 'Please reload VSCode to disable Hybrid Mode.'
7676
);
7777
} else if (newValues[1] !== oldValues[1]) {
7878
requestReloadVscode(
7979
newValues[1]
80-
? "Please reload VSCode to enable Vue TypeScript Plugin."
81-
: "Please reload VSCode to disable Vue TypeScript Plugin."
80+
? 'Please reload VSCode to enable Vue TypeScript Plugin.'
81+
: 'Please reload VSCode to disable Vue TypeScript Plugin.'
8282
);
8383
}
8484
});
8585

8686
watch(() => config.server.value.includeLanguages, () => {
8787
if (enabledHybridMode.value) {
8888
requestReloadVscode(
89-
"Please reload VSCode to apply the new language settings."
89+
'Please reload VSCode to apply the new language settings.'
9090
);
9191
}
9292
});
9393

9494
watch(config.server, () => {
9595
if (!enabledHybridMode.value) {
96-
executeCommand("vue.action.restartServer", false);
96+
executeCommand('vue.action.restartServer', false);
9797
}
9898
});
9999

100100
watch(Object.values(config).filter((conf) => conf !== config.server), () => {
101-
executeCommand("vue.action.restartServer", false);
101+
executeCommand('vue.action.restartServer', false);
102102
});
103103

104-
useCommand("vue.action.restartServer", async (restartTsServer: boolean = true) => {
104+
useCommand('vue.action.restartServer', async (restartTsServer: boolean = true) => {
105105
if (restartTsServer) {
106-
await executeCommand("typescript.restartTsServer");
106+
await executeCommand('typescript.restartTsServer');
107107
}
108108
await client.stop();
109109
outputChannel.clear();
110-
client.clientOptions.initializationOptions =
111-
await getInitializationOptions(context, enabledHybridMode.value);
110+
client.clientOptions.initializationOptions = await getInitializationOptions(context, enabledHybridMode.value);
112111
await client.start();
113-
activateNameCasing(client, selectors);
114112
});
115113

116114
activateDoctor(context, client);
@@ -119,17 +117,12 @@ async function activateLc(
119117

120118
lsp.activateAutoInsertion(selectors, client);
121119
lsp.activateDocumentDropEdit(selectors, client);
122-
lsp.activateWriteVirtualFiles("vue.action.writeVirtualFiles", client);
120+
lsp.activateWriteVirtualFiles('vue.action.writeVirtualFiles', client);
123121

124122
if (!enabledHybridMode.value) {
125-
lsp.activateTsConfigStatusItem(selectors, "vue.tsconfig", client);
126-
lsp.activateTsVersionStatusItem(
127-
selectors,
128-
"vue.tsversion",
129-
context,
130-
(text) => "TS " + text
131-
);
132-
lsp.activateFindFileReferences("vue.findAllFileReferences", client);
123+
lsp.activateTsConfigStatusItem(selectors, 'vue.tsconfig', client);
124+
lsp.activateTsVersionStatusItem(selectors, 'vue.tsversion', context, (text) => 'TS ' + text);
125+
lsp.activateFindFileReferences('vue.findAllFileReferences', client);
133126
}
134127

135128
useHybridModeStatusItem();
@@ -138,12 +131,12 @@ async function activateLc(
138131
async function requestReloadVscode(msg: string) {
139132
const reload = await vscode.window.showInformationMessage(
140133
msg,
141-
"Reload Window"
134+
'Reload Window'
142135
);
143136
if (reload === undefined) {
144137
return; // cancel
145138
}
146-
executeCommand("workbench.action.reloadWindow");
139+
executeCommand('workbench.action.reloadWindow');
147140
}
148141
}
149142

extensions/vscode/src/compatibility.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const unknownExtensions = computed(() => {
1616
.map((ext) => ext.id);
1717
});
1818

19-
2019
function isExtensionCompatibleWithHybridMode(extension: vscode.Extension<any>) {
2120
if (
2221
extension.id === 'Vue.volar'
@@ -46,4 +45,4 @@ function isExtensionCompatibleWithHybridMode(extension: vscode.Extension<any>) {
4645
if (extension.id === 'svelte.svelte-vscode') {
4746
return semver.gte(extension.packageJSON.version, '108.4.0');
4847
}
49-
}
48+
}

extensions/vscode/src/insiders.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ export function useInsidersStatusItem(context: vscode.ExtensionContext) {
88
item.busy = true;
99
let succeed = false;
1010

11-
Promise.race([
12-
"https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json",
13-
"https://cdn.jsdelivr.net/gh/vuejs/language-tools/insiders.json",
14-
].map((url) => fetch(url)))
15-
.then(async (res) => {
16-
onJson(await res.json() as any);
17-
item.busy = false;
18-
if (!succeed) {
19-
item.text = "Failed to Fetch Versions";
20-
item.severity = vscode.LanguageStatusSeverity.Error;
11+
fetchJson();
12+
13+
async function fetchJson() {
14+
for (const url of [
15+
"https://raw.githubusercontent.com/vuejs/language-tools/HEAD/insiders.json",
16+
"https://cdn.jsdelivr.net/gh/vuejs/language-tools/insiders.json",
17+
]) {
18+
try {
19+
const res = await fetch(url);
20+
onJson(await res.json() as any);
21+
succeed = true;
22+
break;
2123
}
22-
})
23-
.catch();
24+
catch {};
25+
}
26+
27+
item.busy = false;
28+
if (!succeed) {
29+
item.text = "Failed to Fetch Versions";
30+
item.severity = vscode.LanguageStatusSeverity.Error;
31+
}
32+
}
2433

2534
function onJson(json: {
2635
latest: string;

0 commit comments

Comments
 (0)