aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r--editors/code/src/main.ts35
1 files changed, 22 insertions, 13 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 92c797d47..aaedc2431 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -6,7 +6,7 @@ import { promises as fs, PathLike } from "fs";
6import * as commands from './commands'; 6import * as commands from './commands';
7import { activateInlayHints } from './inlay_hints'; 7import { activateInlayHints } from './inlay_hints';
8import { Ctx } from './ctx'; 8import { Ctx } from './ctx';
9import { Config, NIGHTLY_TAG } from './config'; 9import { Config } from './config';
10import { log, assert, isValidExecutable } from './util'; 10import { log, assert, isValidExecutable } from './util';
11import { PersistentState } from './persistent_state'; 11import { PersistentState } from './persistent_state';
12import { fetchRelease, download } from './net'; 12import { fetchRelease, download } from './net';
@@ -156,16 +156,18 @@ export async function deactivate() {
156async function bootstrap(config: Config, state: PersistentState): Promise<string> { 156async function bootstrap(config: Config, state: PersistentState): Promise<string> {
157 await fs.mkdir(config.globalStoragePath, { recursive: true }); 157 await fs.mkdir(config.globalStoragePath, { recursive: true });
158 158
159 if (!config.currentExtensionIsNightly) {
160 await state.updateNightlyReleaseId(undefined);
161 }
159 await bootstrapExtension(config, state); 162 await bootstrapExtension(config, state);
160 const path = await bootstrapServer(config, state); 163 const path = await bootstrapServer(config, state);
161
162 return path; 164 return path;
163} 165}
164 166
165async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> { 167async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
166 if (config.package.releaseTag === null) return; 168 if (config.package.releaseTag === null) return;
167 if (config.channel === "stable") { 169 if (config.channel === "stable") {
168 if (config.package.releaseTag === NIGHTLY_TAG) { 170 if (config.currentExtensionIsNightly) {
169 void vscode.window.showWarningMessage( 171 void vscode.window.showWarningMessage(
170 `You are running a nightly version of rust-analyzer extension. ` + 172 `You are running a nightly version of rust-analyzer extension. ` +
171 `To switch to stable, uninstall the extension and re-install it from the marketplace` 173 `To switch to stable, uninstall the extension and re-install it from the marketplace`
@@ -176,27 +178,34 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
176 if (serverPath(config)) return; 178 if (serverPath(config)) return;
177 179
178 const now = Date.now(); 180 const now = Date.now();
179 if (config.package.releaseTag === NIGHTLY_TAG) { 181 const isInitialNightlyDownload = state.nightlyReleaseId === undefined;
182 if (config.currentExtensionIsNightly) {
180 // Check if we should poll github api for the new nightly version 183 // Check if we should poll github api for the new nightly version
181 // if we haven't done it during the past hour 184 // if we haven't done it during the past hour
182 const lastCheck = state.lastCheck; 185 const lastCheck = state.lastCheck;
183 186
184 const anHour = 60 * 60 * 1000; 187 const anHour = 60 * 60 * 1000;
185 const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; 188 const shouldCheckForNewNightly = isInitialNightlyDownload || (now - (lastCheck ?? 0)) > anHour;
186 189
187 if (!shouldCheckForNewNightly) return; 190 if (!shouldCheckForNewNightly) return;
188 } 191 }
189 192
190 const release = await downloadWithRetryDialog(state, async () => { 193 const latestNightlyRelease = await downloadWithRetryDialog(state, async () => {
191 return await fetchRelease("nightly", state.githubToken, config.httpProxy); 194 return await fetchRelease("nightly", state.githubToken, config.httpProxy);
192 }).catch(async (e) => { 195 }).catch(async (e) => {
193 log.error(e); 196 log.error(e);
194 if (state.releaseId === undefined) { // Show error only for the initial download 197 if (isInitialNightlyDownload) {
195 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); 198 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
196 } 199 }
197 return undefined; 200 return;
198 }); 201 });
199 if (release === undefined || release.id === state.releaseId) return; 202 if (latestNightlyRelease === undefined) {
203 if (isInitialNightlyDownload) {
204 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
205 }
206 return;
207 }
208 if (config.currentExtensionIsNightly && latestNightlyRelease.id === state.nightlyReleaseId) return;
200 209
201 const userResponse = await vscode.window.showInformationMessage( 210 const userResponse = await vscode.window.showInformationMessage(
202 "New version of rust-analyzer (nightly) is available (requires reload).", 211 "New version of rust-analyzer (nightly) is available (requires reload).",
@@ -204,8 +213,8 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
204 ); 213 );
205 if (userResponse !== "Update") return; 214 if (userResponse !== "Update") return;
206 215
207 const artifact = release.assets.find(artifact => artifact.name === "rust-analyzer.vsix"); 216 const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
208 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 217 assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
209 218
210 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); 219 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
211 220
@@ -221,7 +230,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
221 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); 230 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
222 await fs.unlink(dest); 231 await fs.unlink(dest);
223 232
224 await state.updateReleaseId(release.id); 233 await state.updateNightlyReleaseId(latestNightlyRelease.id);
225 await state.updateLastCheck(now); 234 await state.updateLastCheck(now);
226 await vscode.commands.executeCommand("workbench.action.reloadWindow"); 235 await vscode.commands.executeCommand("workbench.action.reloadWindow");
227} 236}