about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorKirill Bulatov <mail4score@gmail.com>2021-05-23 13:57:04 +0300
committerKirill Bulatov <mail4score@gmail.com>2021-05-23 13:57:04 +0300
commitdaedcc2b77187486fde13a2813809b06b2385ac0 (patch)
tree60b2b267baadbc1be09ac338611c68de59fd0174 /editors/code/src
parent223dbd2187e5b966d192dac9745d47831dccb9b3 (diff)
downloadrust-daedcc2b77187486fde13a2813809b06b2385ac0.tar.gz
rust-daedcc2b77187486fde13a2813809b06b2385ac0.zip
More style fixes
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/config.ts6
-rw-r--r--editors/code/src/main.ts29
2 files changed, 19 insertions, 16 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index c9249768d2c..fbb7a556a86 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -4,7 +4,7 @@ import { log } from "./util";
 
 export type UpdatesChannel = "stable" | "nightly";
 
-export const NIGHTLY_TAG = "nightly";
+const NIGHTLY_TAG = "nightly";
 
 export type RunnableEnvCfg = undefined | Record<string, string> | { mask?: string; env: Record<string, string> }[];
 
@@ -170,4 +170,8 @@ export class Config {
             gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
         };
     }
+
+    get currentExtensionIsNightly() {
+        return this.package.releaseTag === NIGHTLY_TAG;
+    }
 }
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a6c1c0906ae..aaedc243143 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -6,7 +6,7 @@ import { promises as fs, PathLike } from "fs";
 import * as commands from './commands';
 import { activateInlayHints } from './inlay_hints';
 import { Ctx } from './ctx';
-import { Config, NIGHTLY_TAG } from './config';
+import { Config } from './config';
 import { log, assert, isValidExecutable } from './util';
 import { PersistentState } from './persistent_state';
 import { fetchRelease, download } from './net';
@@ -156,7 +156,7 @@ export async function deactivate() {
 async function bootstrap(config: Config, state: PersistentState): Promise<string> {
     await fs.mkdir(config.globalStoragePath, { recursive: true });
 
-    if (config.package.releaseTag !== NIGHTLY_TAG) {
+    if (!config.currentExtensionIsNightly) {
         await state.updateNightlyReleaseId(undefined);
     }
     await bootstrapExtension(config, state);
@@ -166,9 +166,8 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
 
 async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
     if (config.package.releaseTag === null) return;
-    const currentExtensionIsNightly = config.package.releaseTag === NIGHTLY_TAG;
     if (config.channel === "stable") {
-        if (currentExtensionIsNightly) {
+        if (config.currentExtensionIsNightly) {
             void vscode.window.showWarningMessage(
                 `You are running a nightly version of rust-analyzer extension. ` +
                 `To switch to stable, uninstall the extension and re-install it from the marketplace`
@@ -179,34 +178,34 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
     if (serverPath(config)) return;
 
     const now = Date.now();
-    const isInitialDownload = state.nightlyReleaseId === undefined;
-    if (currentExtensionIsNightly) {
+    const isInitialNightlyDownload = state.nightlyReleaseId === undefined;
+    if (config.currentExtensionIsNightly) {
         // Check if we should poll github api for the new nightly version
         // if we haven't done it during the past hour
         const lastCheck = state.lastCheck;
 
         const anHour = 60 * 60 * 1000;
-        const shouldCheckForNewNightly = isInitialDownload || (now - (lastCheck ?? 0)) > anHour;
+        const shouldCheckForNewNightly = isInitialNightlyDownload || (now - (lastCheck ?? 0)) > anHour;
 
         if (!shouldCheckForNewNightly) return;
     }
 
-    const release = await downloadWithRetryDialog(state, async () => {
+    const latestNightlyRelease = await downloadWithRetryDialog(state, async () => {
         return await fetchRelease("nightly", state.githubToken, config.httpProxy);
     }).catch(async (e) => {
         log.error(e);
-        if (isInitialDownload) {
+        if (isInitialNightlyDownload) {
             await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
         }
         return;
     });
-    if (release === undefined) {
-        if (isInitialDownload) {
+    if (latestNightlyRelease === undefined) {
+        if (isInitialNightlyDownload) {
             await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
         }
         return;
     }
-    if (currentExtensionIsNightly && release.id === state.nightlyReleaseId) return;
+    if (config.currentExtensionIsNightly && latestNightlyRelease.id === state.nightlyReleaseId) return;
 
     const userResponse = await vscode.window.showInformationMessage(
         "New version of rust-analyzer (nightly) is available (requires reload).",
@@ -214,8 +213,8 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
     );
     if (userResponse !== "Update") return;
 
-    const artifact = release.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
-    assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
+    const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
+    assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
 
     const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
 
@@ -231,7 +230,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
     await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
     await fs.unlink(dest);
 
-    await state.updateNightlyReleaseId(release.id);
+    await state.updateNightlyReleaseId(latestNightlyRelease.id);
     await state.updateLastCheck(now);
     await vscode.commands.executeCommand("workbench.action.reloadWindow");
 }