diff options
Diffstat (limited to 'editors/code/src/installation/extension.ts')
-rw-r--r-- | editors/code/src/installation/extension.ts | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/editors/code/src/installation/extension.ts b/editors/code/src/installation/extension.ts index eea6fded2..a1db96f05 100644 --- a/editors/code/src/installation/extension.ts +++ b/editors/code/src/installation/extension.ts | |||
@@ -7,6 +7,7 @@ import { Config, UpdatesChannel } from "../config"; | |||
7 | import { ArtifactReleaseInfo, ArtifactSource } from "./interfaces"; | 7 | import { ArtifactReleaseInfo, ArtifactSource } from "./interfaces"; |
8 | import { downloadArtifactWithProgressUi } from "./downloads"; | 8 | import { downloadArtifactWithProgressUi } from "./downloads"; |
9 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; | 9 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; |
10 | import { PersistentState } from "../persistent_state"; | ||
10 | 11 | ||
11 | const HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS = 25; | 12 | const HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS = 25; |
12 | 13 | ||
@@ -14,7 +15,7 @@ const HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS = 25; | |||
14 | * Installs `stable` or latest `nightly` version or does nothing if the current | 15 | * Installs `stable` or latest `nightly` version or does nothing if the current |
15 | * extension version is what's needed according to `desiredUpdateChannel`. | 16 | * extension version is what's needed according to `desiredUpdateChannel`. |
16 | */ | 17 | */ |
17 | export async function ensureProperExtensionVersion(config: Config): Promise<never | void> { | 18 | export async function ensureProperExtensionVersion(config: Config, state: PersistentState): Promise<never | void> { |
18 | // User has built lsp server from sources, she should manage updates manually | 19 | // User has built lsp server from sources, she should manage updates manually |
19 | if (config.serverSource?.type === ArtifactSource.Type.ExplicitPath) return; | 20 | if (config.serverSource?.type === ArtifactSource.Type.ExplicitPath) return; |
20 | 21 | ||
@@ -23,7 +24,7 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve | |||
23 | 24 | ||
24 | if (currentUpdChannel === UpdatesChannel.Stable) { | 25 | if (currentUpdChannel === UpdatesChannel.Stable) { |
25 | // Release date is present only when we are on nightly | 26 | // Release date is present only when we are on nightly |
26 | await config.installedNightlyExtensionReleaseDate.set(null); | 27 | await state.installedNightlyExtensionReleaseDate.set(null); |
27 | } | 28 | } |
28 | 29 | ||
29 | if (desiredUpdChannel === UpdatesChannel.Stable) { | 30 | if (desiredUpdChannel === UpdatesChannel.Stable) { |
@@ -39,10 +40,10 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve | |||
39 | if (currentUpdChannel === UpdatesChannel.Stable) { | 40 | if (currentUpdChannel === UpdatesChannel.Stable) { |
40 | if (!await askToDownloadProperExtensionVersion(config)) return; | 41 | if (!await askToDownloadProperExtensionVersion(config)) return; |
41 | 42 | ||
42 | return await tryDownloadNightlyExtension(config); | 43 | return await tryDownloadNightlyExtension(config, state); |
43 | } | 44 | } |
44 | 45 | ||
45 | const currentExtReleaseDate = config.installedNightlyExtensionReleaseDate.get(); | 46 | const currentExtReleaseDate = state.installedNightlyExtensionReleaseDate.get(); |
46 | 47 | ||
47 | if (currentExtReleaseDate === null) { | 48 | if (currentExtReleaseDate === null) { |
48 | void vscode.window.showErrorMessage( | 49 | void vscode.window.showErrorMessage( |
@@ -66,9 +67,9 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve | |||
66 | return; | 67 | return; |
67 | } | 68 | } |
68 | 69 | ||
69 | await tryDownloadNightlyExtension(config, releaseInfo => { | 70 | await tryDownloadNightlyExtension(config, state, releaseInfo => { |
70 | assert( | 71 | assert( |
71 | currentExtReleaseDate.getTime() === config.installedNightlyExtensionReleaseDate.get()?.getTime(), | 72 | currentExtReleaseDate.getTime() === state.installedNightlyExtensionReleaseDate.get()?.getTime(), |
72 | "Other active VSCode instance has reinstalled the extension" | 73 | "Other active VSCode instance has reinstalled the extension" |
73 | ); | 74 | ); |
74 | 75 | ||
@@ -111,6 +112,7 @@ async function askToDownloadProperExtensionVersion(config: Config, reason = "") | |||
111 | */ | 112 | */ |
112 | const tryDownloadNightlyExtension = notReentrant(async ( | 113 | const tryDownloadNightlyExtension = notReentrant(async ( |
113 | config: Config, | 114 | config: Config, |
115 | state: PersistentState, | ||
114 | shouldDownload: (releaseInfo: ArtifactReleaseInfo) => boolean = () => true | 116 | shouldDownload: (releaseInfo: ArtifactReleaseInfo) => boolean = () => true |
115 | ): Promise<never | void> => { | 117 | ): Promise<never | void> => { |
116 | const vsixSource = config.nightlyVsixSource; | 118 | const vsixSource = config.nightlyVsixSource; |
@@ -124,7 +126,7 @@ const tryDownloadNightlyExtension = notReentrant(async ( | |||
124 | const vsixPath = path.join(vsixSource.dir, vsixSource.file); | 126 | const vsixPath = path.join(vsixSource.dir, vsixSource.file); |
125 | 127 | ||
126 | await vscodeInstallExtensionFromVsix(vsixPath); | 128 | await vscodeInstallExtensionFromVsix(vsixPath); |
127 | await config.installedNightlyExtensionReleaseDate.set(releaseInfo.releaseDate); | 129 | await state.installedNightlyExtensionReleaseDate.set(releaseInfo.releaseDate); |
128 | await fs.unlink(vsixPath); | 130 | await fs.unlink(vsixPath); |
129 | 131 | ||
130 | await vscodeReloadWindow(); // never returns | 132 | await vscodeReloadWindow(); // never returns |