diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-09 09:05:45 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-09 09:05:45 +0000 |
commit | fcaab594518bb097e207e94453cfe11ef5413c39 (patch) | |
tree | 83a8d0f856feb789047a2af2b60d342d98084a81 /editors/code/src/installation/server.ts | |
parent | beb4f4954179998e317db33e47a48a9bb7374977 (diff) | |
parent | ce65cc949f9e183c7c166212b4f3d7d4abd102b0 (diff) |
Merge #3514
3514: vscode: askBeforeDownload option r=matklad a=Veetaha
This is a small step towards #3402, also implements my proposal stated in #3403
Also renamed `BinarySource` to `ArtifactSource` in anticipation of nightlies installation that requires downloading not a binary itself but `.vsix` package, thus generalized to `artifact` term.
@matklad @lnicola
Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'editors/code/src/installation/server.ts')
-rw-r--r-- | editors/code/src/installation/server.ts | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/editors/code/src/installation/server.ts b/editors/code/src/installation/server.ts index 6a6cf4f8c..ef1c45ff6 100644 --- a/editors/code/src/installation/server.ts +++ b/editors/code/src/installation/server.ts | |||
@@ -3,12 +3,12 @@ import * as path from "path"; | |||
3 | import { promises as dns } from "dns"; | 3 | import { promises as dns } from "dns"; |
4 | import { spawnSync } from "child_process"; | 4 | import { spawnSync } from "child_process"; |
5 | 5 | ||
6 | import { BinarySource } from "./interfaces"; | 6 | import { ArtifactSource } from "./interfaces"; |
7 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; | 7 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; |
8 | import { downloadArtifact } from "./download_artifact"; | 8 | import { downloadArtifact } from "./download_artifact"; |
9 | import { log, assert } from "../util"; | 9 | import { log, assert } from "../util"; |
10 | 10 | ||
11 | export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { | 11 | export async function ensureServerBinary(source: null | ArtifactSource): Promise<null | string> { |
12 | if (!source) { | 12 | if (!source) { |
13 | vscode.window.showErrorMessage( | 13 | vscode.window.showErrorMessage( |
14 | "Unfortunately we don't ship binaries for your platform yet. " + | 14 | "Unfortunately we don't ship binaries for your platform yet. " + |
@@ -22,7 +22,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n | |||
22 | } | 22 | } |
23 | 23 | ||
24 | switch (source.type) { | 24 | switch (source.type) { |
25 | case BinarySource.Type.ExplicitPath: { | 25 | case ArtifactSource.Type.ExplicitPath: { |
26 | if (isBinaryAvailable(source.path)) { | 26 | if (isBinaryAvailable(source.path)) { |
27 | return source.path; | 27 | return source.path; |
28 | } | 28 | } |
@@ -34,11 +34,11 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n | |||
34 | ); | 34 | ); |
35 | return null; | 35 | return null; |
36 | } | 36 | } |
37 | case BinarySource.Type.GithubRelease: { | 37 | case ArtifactSource.Type.GithubRelease: { |
38 | const prebuiltBinaryPath = path.join(source.dir, source.file); | 38 | const prebuiltBinaryPath = path.join(source.dir, source.file); |
39 | 39 | ||
40 | const installedVersion: null | string = getServerVersion(source.storage); | 40 | const installedVersion: null | string = getServerVersion(source.storage); |
41 | const requiredVersion: string = source.version; | 41 | const requiredVersion: string = source.tag; |
42 | 42 | ||
43 | log.debug("Installed version:", installedVersion, "required:", requiredVersion); | 43 | log.debug("Installed version:", installedVersion, "required:", requiredVersion); |
44 | 44 | ||
@@ -46,12 +46,14 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n | |||
46 | return prebuiltBinaryPath; | 46 | return prebuiltBinaryPath; |
47 | } | 47 | } |
48 | 48 | ||
49 | const userResponse = await vscode.window.showInformationMessage( | 49 | if (source.askBeforeDownload) { |
50 | `Language server version ${source.version} for rust-analyzer is not installed. ` + | 50 | const userResponse = await vscode.window.showInformationMessage( |
51 | "Do you want to download it now?", | 51 | `Language server version ${source.tag} for rust-analyzer is not installed. ` + |
52 | "Download now", "Cancel" | 52 | "Do you want to download it now?", |
53 | ); | 53 | "Download now", "Cancel" |
54 | if (userResponse !== "Download now") return null; | 54 | ); |
55 | if (userResponse !== "Download now") return null; | ||
56 | } | ||
55 | 57 | ||
56 | if (!await downloadServer(source)) return null; | 58 | if (!await downloadServer(source)) return null; |
57 | 59 | ||
@@ -60,9 +62,9 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n | |||
60 | } | 62 | } |
61 | } | 63 | } |
62 | 64 | ||
63 | async function downloadServer(source: BinarySource.GithubRelease): Promise<boolean> { | 65 | async function downloadServer(source: ArtifactSource.GithubRelease): Promise<boolean> { |
64 | try { | 66 | try { |
65 | const releaseInfo = await fetchArtifactReleaseInfo(source.repo, source.file, source.version); | 67 | const releaseInfo = await fetchArtifactReleaseInfo(source.repo, source.file, source.tag); |
66 | 68 | ||
67 | await downloadArtifact(releaseInfo, source.file, source.dir, "language server"); | 69 | await downloadArtifact(releaseInfo, source.file, source.dir, "language server"); |
68 | await setServerVersion(source.storage, releaseInfo.releaseName); | 70 | await setServerVersion(source.storage, releaseInfo.releaseName); |