Skip to content

Commit fcaab59

Browse files
bors[bot]Veetaha
andauthored
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 <gerzoh1@gmail.com>
2 parents beb4f49 + ce65cc9 commit fcaab59

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

docs/user/readme.adoc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
:toc: preamble
33
:sectanchors:
44
: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+
512

613

714
// 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
3037

3138
=== VS Code
3239

33-
This the best supported editor at the moment.
40+
This is the best supported editor at the moment.
3441
rust-analyzer plugin for VS Code is maintained
3542
https://github.com/rust-analyzer/rust-analyzer/tree/master/editors/code[in tree].
3643

@@ -40,6 +47,16 @@ By default, the plugin will prompt you to download the matching version of the s
4047

4148
image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[]
4249

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+
4360
The server binary is stored in `~/.config/Code/User/globalStorage/matklad.rust-analyzer`.
4461

4562
Note that we only support the latest version of VS Code.

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@
219219
}
220220
}
221221
},
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+
},
222227
"rust-analyzer.serverPath": {
223228
"type": [
224229
"null",

editors/code/src/config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as os from "os";
22
import * as vscode from 'vscode';
3-
import { BinarySource } from "./installation/interfaces";
3+
import { ArtifactSource } from "./installation/interfaces";
44
import { log } from "./util";
55

66
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
@@ -114,12 +114,12 @@ export class Config {
114114
}
115115
}
116116

117-
get serverSource(): null | BinarySource {
117+
get serverSource(): null | ArtifactSource {
118118
const serverPath = RA_LSP_DEBUG ?? this.cfg.get<null | string>("serverPath");
119119

120120
if (serverPath) {
121121
return {
122-
type: BinarySource.Type.ExplicitPath,
122+
type: ArtifactSource.Type.ExplicitPath,
123123
path: Config.replaceTildeWithHomeDir(serverPath)
124124
};
125125
}
@@ -129,11 +129,12 @@ export class Config {
129129
if (!prebuiltBinaryName) return null;
130130

131131
return {
132-
type: BinarySource.Type.GithubRelease,
132+
type: ArtifactSource.Type.GithubRelease,
133133
dir: this.ctx.globalStoragePath,
134134
file: prebuiltBinaryName,
135135
storage: this.ctx.globalState,
136-
version: Config.extensionVersion,
136+
tag: Config.extensionVersion,
137+
askBeforeDownload: this.cfg.get("updates.askBeforeDownload") as boolean,
137138
repo: {
138139
name: "rust-analyzer",
139140
owner: "rust-analyzer",

editors/code/src/installation/interfaces.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export interface ArtifactReleaseInfo {
1414
}
1515

1616
/**
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
1818
* explicitly, or bundled by this extension from GitHub releases.
1919
*/
20-
export type BinarySource = BinarySource.ExplicitPath | BinarySource.GithubRelease;
20+
export type ArtifactSource = ArtifactSource.ExplicitPath | ArtifactSource.GithubRelease;
2121

22-
export namespace BinarySource {
22+
export namespace ArtifactSource {
2323
/**
24-
* Type tag for `BinarySource` discriminated union.
24+
* Type tag for `ArtifactSource` discriminated union.
2525
*/
2626
export const enum Type { ExplicitPath, GithubRelease }
2727

@@ -56,13 +56,18 @@ export namespace BinarySource {
5656
/**
5757
* Tag of github release that denotes a version required by this extension.
5858
*/
59-
version: string;
59+
tag: string;
6060

6161
/**
6262
* Object that provides `get()/update()` operations to store metadata
6363
* about the actual binary, e.g. its actual version.
6464
*/
6565
storage: vscode.Memento;
66+
67+
/**
68+
* Ask for the user permission before downloading the artifact.
69+
*/
70+
askBeforeDownload: boolean;
6671
}
6772

6873
}

editors/code/src/installation/server.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import * as path from "path";
33
import { promises as dns } from "dns";
44
import { spawnSync } from "child_process";
55

6-
import { BinarySource } from "./interfaces";
6+
import { ArtifactSource } from "./interfaces";
77
import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info";
88
import { downloadArtifact } from "./download_artifact";
99
import { log, assert } from "../util";
1010

11-
export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> {
11+
export async function ensureServerBinary(source: null | ArtifactSource): Promise<null | string> {
1212
if (!source) {
1313
vscode.window.showErrorMessage(
1414
"Unfortunately we don't ship binaries for your platform yet. " +
@@ -22,7 +22,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n
2222
}
2323

2424
switch (source.type) {
25-
case BinarySource.Type.ExplicitPath: {
25+
case ArtifactSource.Type.ExplicitPath: {
2626
if (isBinaryAvailable(source.path)) {
2727
return source.path;
2828
}
@@ -34,24 +34,26 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n
3434
);
3535
return null;
3636
}
37-
case BinarySource.Type.GithubRelease: {
37+
case ArtifactSource.Type.GithubRelease: {
3838
const prebuiltBinaryPath = path.join(source.dir, source.file);
3939

4040
const installedVersion: null | string = getServerVersion(source.storage);
41-
const requiredVersion: string = source.version;
41+
const requiredVersion: string = source.tag;
4242

4343
log.debug("Installed version:", installedVersion, "required:", requiredVersion);
4444

4545
if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) {
4646
return prebuiltBinaryPath;
4747
}
4848

49-
const userResponse = await vscode.window.showInformationMessage(
50-
`Language server version ${source.version} for rust-analyzer is not installed. ` +
51-
"Do you want to download it now?",
52-
"Download now", "Cancel"
53-
);
54-
if (userResponse !== "Download now") return null;
49+
if (source.askBeforeDownload) {
50+
const userResponse = await vscode.window.showInformationMessage(
51+
`Language server version ${source.tag} for rust-analyzer is not installed. ` +
52+
"Do you want to download it now?",
53+
"Download now", "Cancel"
54+
);
55+
if (userResponse !== "Download now") return null;
56+
}
5557

5658
if (!await downloadServer(source)) return null;
5759

@@ -60,9 +62,9 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n
6062
}
6163
}
6264

63-
async function downloadServer(source: BinarySource.GithubRelease): Promise<boolean> {
65+
async function downloadServer(source: ArtifactSource.GithubRelease): Promise<boolean> {
6466
try {
65-
const releaseInfo = await fetchArtifactReleaseInfo(source.repo, source.file, source.version);
67+
const releaseInfo = await fetchArtifactReleaseInfo(source.repo, source.file, source.tag);
6668

6769
await downloadArtifact(releaseInfo, source.file, source.dir, "language server");
6870
await setServerVersion(source.storage, releaseInfo.releaseName);

0 commit comments

Comments
 (0)