diff options
-rw-r--r-- | docs/user/readme.adoc | 19 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 11 | ||||
-rw-r--r-- | editors/code/src/installation/interfaces.ts | 15 | ||||
-rw-r--r-- | editors/code/src/installation/server.ts | 28 |
5 files changed, 54 insertions, 24 deletions
diff --git a/docs/user/readme.adoc b/docs/user/readme.adoc index f1386a8f9..e5843ed70 100644 --- a/docs/user/readme.adoc +++ b/docs/user/readme.adoc | |||
@@ -2,6 +2,13 @@ | |||
2 | :toc: preamble | 2 | :toc: preamble |
3 | :sectanchors: | 3 | :sectanchors: |
4 | :page-layout: post | 4 | :page-layout: post |
5 | // https://gist.github.com/dcode/0cfbf2699a1fe9b46ff04c41721dda74#admonitions | ||
6 | :tip-caption: :bulb: | ||
7 | :note-caption: :information_source: | ||
8 | :important-caption: :heavy_exclamation_mark: | ||
9 | :caution-caption: :fire: | ||
10 | :warning-caption: :warning: | ||
11 | |||
5 | 12 | ||
6 | 13 | ||
7 | // Master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository | 14 | // Master copy of this document lives in the https://github.com/rust-analyzer/rust-analyzer repository |
@@ -30,7 +37,7 @@ $ rustup component add rust-src | |||
30 | 37 | ||
31 | === VS Code | 38 | === VS Code |
32 | 39 | ||
33 | This the best supported editor at the moment. | 40 | This is the best supported editor at the moment. |
34 | rust-analyzer plugin for VS Code is maintained | 41 | rust-analyzer plugin for VS Code is maintained |
35 | https://github.com/rust-analyzer/rust-analyzer/tree/master/editors/code[in tree]. | 42 | https://github.com/rust-analyzer/rust-analyzer/tree/master/editors/code[in tree]. |
36 | 43 | ||
@@ -40,6 +47,16 @@ By default, the plugin will prompt you to download the matching version of the s | |||
40 | 47 | ||
41 | image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[] | 48 | image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[] |
42 | 49 | ||
50 | [NOTE] | ||
51 | ==== | ||
52 | To disable this notification put the following to `settings.json` | ||
53 | |||
54 | [source,json] | ||
55 | ---- | ||
56 | { "rust-analyzer.updates.askBeforeDownload": false } | ||
57 | ---- | ||
58 | ==== | ||
59 | |||
43 | The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer`. | 60 | The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer`. |
44 | 61 | ||
45 | Note that we only support the latest version of VS Code. | 62 | Note that we only support the latest version of VS Code. |
diff --git a/editors/code/package.json b/editors/code/package.json index fd44d2bd5..7a4a93e30 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -219,6 +219,11 @@ | |||
219 | } | 219 | } |
220 | } | 220 | } |
221 | }, | 221 | }, |
222 | "rust-analyzer.updates.askBeforeDownload": { | ||
223 | "type": "boolean", | ||
224 | "default": true, | ||
225 | "description": "Whether to ask for permission before downloading any files from the Internet" | ||
226 | }, | ||
222 | "rust-analyzer.serverPath": { | 227 | "rust-analyzer.serverPath": { |
223 | "type": [ | 228 | "type": [ |
224 | "null", | 229 | "null", |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index bf915102c..b72206d3c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as os from "os"; | 1 | import * as os from "os"; |
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import { BinarySource } from "./installation/interfaces"; | 3 | import { ArtifactSource } from "./installation/interfaces"; |
4 | import { log } from "./util"; | 4 | import { log } from "./util"; |
5 | 5 | ||
6 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 6 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
@@ -114,12 +114,12 @@ export class Config { | |||
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | get serverSource(): null | BinarySource { | 117 | get serverSource(): null | ArtifactSource { |
118 | const serverPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("serverPath"); | 118 | const serverPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("serverPath"); |
119 | 119 | ||
120 | if (serverPath) { | 120 | if (serverPath) { |
121 | return { | 121 | return { |
122 | type: BinarySource.Type.ExplicitPath, | 122 | type: ArtifactSource.Type.ExplicitPath, |
123 | path: Config.replaceTildeWithHomeDir(serverPath) | 123 | path: Config.replaceTildeWithHomeDir(serverPath) |
124 | }; | 124 | }; |
125 | } | 125 | } |
@@ -129,11 +129,12 @@ export class Config { | |||
129 | if (!prebuiltBinaryName) return null; | 129 | if (!prebuiltBinaryName) return null; |
130 | 130 | ||
131 | return { | 131 | return { |
132 | type: BinarySource.Type.GithubRelease, | 132 | type: ArtifactSource.Type.GithubRelease, |
133 | dir: this.ctx.globalStoragePath, | 133 | dir: this.ctx.globalStoragePath, |
134 | file: prebuiltBinaryName, | 134 | file: prebuiltBinaryName, |
135 | storage: this.ctx.globalState, | 135 | storage: this.ctx.globalState, |
136 | version: Config.extensionVersion, | 136 | tag: Config.extensionVersion, |
137 | askBeforeDownload: this.cfg.get("updates.askBeforeDownload") as boolean, | ||
137 | repo: { | 138 | repo: { |
138 | name: "rust-analyzer", | 139 | name: "rust-analyzer", |
139 | owner: "rust-analyzer", | 140 | owner: "rust-analyzer", |
diff --git a/editors/code/src/installation/interfaces.ts b/editors/code/src/installation/interfaces.ts index e40839e4b..50b635921 100644 --- a/editors/code/src/installation/interfaces.ts +++ b/editors/code/src/installation/interfaces.ts | |||
@@ -14,14 +14,14 @@ export interface ArtifactReleaseInfo { | |||
14 | } | 14 | } |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * Represents the source of a binary artifact which is either specified by the user | 17 | * Represents the source of a an artifact which is either specified by the user |
18 | * explicitly, or bundled by this extension from GitHub releases. | 18 | * explicitly, or bundled by this extension from GitHub releases. |
19 | */ | 19 | */ |
20 | export type BinarySource = BinarySource.ExplicitPath | BinarySource.GithubRelease; | 20 | export type ArtifactSource = ArtifactSource.ExplicitPath | ArtifactSource.GithubRelease; |
21 | 21 | ||
22 | export namespace BinarySource { | 22 | export namespace ArtifactSource { |
23 | /** | 23 | /** |
24 | * Type tag for `BinarySource` discriminated union. | 24 | * Type tag for `ArtifactSource` discriminated union. |
25 | */ | 25 | */ |
26 | export const enum Type { ExplicitPath, GithubRelease } | 26 | export const enum Type { ExplicitPath, GithubRelease } |
27 | 27 | ||
@@ -56,13 +56,18 @@ export namespace BinarySource { | |||
56 | /** | 56 | /** |
57 | * Tag of github release that denotes a version required by this extension. | 57 | * Tag of github release that denotes a version required by this extension. |
58 | */ | 58 | */ |
59 | version: string; | 59 | tag: string; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Object that provides `get()/update()` operations to store metadata | 62 | * Object that provides `get()/update()` operations to store metadata |
63 | * about the actual binary, e.g. its actual version. | 63 | * about the actual binary, e.g. its actual version. |
64 | */ | 64 | */ |
65 | storage: vscode.Memento; | 65 | storage: vscode.Memento; |
66 | |||
67 | /** | ||
68 | * Ask for the user permission before downloading the artifact. | ||
69 | */ | ||
70 | askBeforeDownload: boolean; | ||
66 | } | 71 | } |
67 | 72 | ||
68 | } | 73 | } |
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); |