Skip to content

Commit d5b4aa3

Browse files
committed
Remove server download and update checks
1 parent 45d2262 commit d5b4aa3

File tree

2 files changed

+2
-230
lines changed

2 files changed

+2
-230
lines changed

editors/code/src/main.ts

Lines changed: 2 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import * as commands from './commands';
55
import { activateInlayHints } from './inlay_hints';
66
import { Ctx } from './ctx';
77
import { Config } from './config';
8-
import { log, assert, isValidExecutable, isRustDocument } from './util';
8+
import { log, isValidExecutable, isRustDocument } from './util';
99
import { PersistentState } from './persistent_state';
10-
import { fetchRelease, download } from './net';
1110
import { activateTaskProvider } from './tasks';
1211
import { setContextValue } from './util';
1312
import { exec, spawnSync } from 'child_process';
@@ -111,10 +110,6 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
111110
await activate(context).catch(log.error);
112111
});
113112

114-
ctx.registerCommand('updateGithubToken', ctx => async () => {
115-
await queryForGithubToken(new PersistentState(ctx.globalState));
116-
});
117-
118113
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
119114
ctx.registerCommand('memoryUsage', commands.memoryUsage);
120115
ctx.registerCommand('shuffleCrateGraph', commands.shuffleCrateGraph);
@@ -163,95 +158,10 @@ export async function deactivate() {
163158

164159
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
165160
await vscode.workspace.fs.createDirectory(config.globalStorageUri).then();
166-
167-
if (!config.currentExtensionIsNightly) {
168-
await state.updateNightlyReleaseId(undefined);
169-
}
170-
await bootstrapExtension(config, state);
171161
const path = await bootstrapServer(config, state);
172162
return path;
173163
}
174164

175-
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
176-
if (config.package.releaseTag === null) return;
177-
if (config.channel === "stable") {
178-
if (config.currentExtensionIsNightly) {
179-
void vscode.window.showWarningMessage(
180-
`You are running a nightly version of rust-analyzer extension. ` +
181-
`To switch to stable, uninstall the extension and re-install it from the marketplace`
182-
);
183-
}
184-
return;
185-
};
186-
if (serverPath(config)) return;
187-
188-
const now = Date.now();
189-
const isInitialNightlyDownload = state.nightlyReleaseId === undefined;
190-
if (config.currentExtensionIsNightly) {
191-
// Check if we should poll github api for the new nightly version
192-
// if we haven't done it during the past hour
193-
const lastCheck = state.lastCheck;
194-
195-
const anHour = 60 * 60 * 1000;
196-
const shouldCheckForNewNightly = isInitialNightlyDownload || (now - (lastCheck ?? 0)) > anHour;
197-
198-
if (!shouldCheckForNewNightly) return;
199-
}
200-
201-
const latestNightlyRelease = await downloadWithRetryDialog(state, async () => {
202-
return await fetchRelease("nightly", state.githubToken, config.proxySettings);
203-
}).catch(async (e) => {
204-
log.error(e);
205-
if (isInitialNightlyDownload) {
206-
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
207-
}
208-
return;
209-
});
210-
if (latestNightlyRelease === undefined) {
211-
if (isInitialNightlyDownload) {
212-
await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
213-
}
214-
return;
215-
}
216-
if (config.currentExtensionIsNightly && latestNightlyRelease.id === state.nightlyReleaseId) return;
217-
218-
const userResponse = await vscode.window.showInformationMessage(
219-
"New version of rust-analyzer (nightly) is available (requires reload).",
220-
"Update"
221-
);
222-
if (userResponse !== "Update") return;
223-
224-
let arch = process.arch;
225-
if (arch === "ia32") {
226-
arch = "x64";
227-
}
228-
let platform = process.platform as string;
229-
if (platform === "linux" && isMusl()) {
230-
platform = "alpine";
231-
}
232-
const artifactName = `rust-analyzer-${platform}-${arch}.vsix`;
233-
234-
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === artifactName);
235-
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
236-
const dest = vscode.Uri.joinPath(config.globalStorageUri, "rust-analyzer.vsix");
237-
238-
await downloadWithRetryDialog(state, async () => {
239-
await download({
240-
url: artifact.browser_download_url,
241-
dest,
242-
progressTitle: "Downloading rust-analyzer extension",
243-
proxySettings: config.proxySettings,
244-
});
245-
});
246-
247-
await vscode.commands.executeCommand("workbench.extensions.installExtension", dest);
248-
await vscode.workspace.fs.delete(dest);
249-
250-
await state.updateNightlyReleaseId(latestNightlyRelease.id);
251-
await state.updateLastCheck(now);
252-
await vscode.commands.executeCommand("workbench.action.reloadWindow");
253-
}
254-
255165
async function bootstrapServer(config: Config, state: PersistentState): Promise<string> {
256166
const path = await getServer(config, state);
257167
if (!path) {
@@ -356,56 +266,16 @@ async function getServer(config: Config, state: PersistentState): Promise<string
356266
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`);
357267
const bundled = vscode.Uri.joinPath(config.installUri, "server", `rust-analyzer${ext}`);
358268
const bundledExists = await vscode.workspace.fs.stat(bundled).then(() => true, () => false);
359-
let exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
269+
const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false);
360270
if (bundledExists) {
361-
await state.updateServerVersion(config.package.version);
362271
if (!await isNixOs()) {
363272
return bundled.fsPath;
364273
}
365274
if (!exists) {
366275
await vscode.workspace.fs.copy(bundled, dest);
367276
await patchelf(dest);
368-
exists = true;
369277
}
370278
}
371-
if (!exists) {
372-
await state.updateServerVersion(undefined);
373-
}
374-
375-
if (state.serverVersion === config.package.version) return dest.fsPath;
376-
377-
if (config.askBeforeDownload) {
378-
const userResponse = await vscode.window.showInformationMessage(
379-
`Language server version ${config.package.version} for rust-analyzer is not installed.`,
380-
"Download now"
381-
);
382-
if (userResponse !== "Download now") return dest.fsPath;
383-
}
384-
385-
const releaseTag = config.package.releaseTag;
386-
const release = await downloadWithRetryDialog(state, async () => {
387-
return await fetchRelease(releaseTag, state.githubToken, config.proxySettings);
388-
});
389-
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
390-
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
391-
392-
await downloadWithRetryDialog(state, async () => {
393-
await download({
394-
url: artifact.browser_download_url,
395-
dest,
396-
progressTitle: "Downloading rust-analyzer server",
397-
gunzip: true,
398-
mode: 0o755,
399-
proxySettings: config.proxySettings,
400-
});
401-
});
402-
403-
// Patching executable if that's NixOS.
404-
if (await isNixOs()) {
405-
await patchelf(dest);
406-
}
407-
408-
await state.updateServerVersion(config.package.version);
409279
return dest.fsPath;
410280
}
411281

@@ -429,59 +299,6 @@ function isMusl(): boolean {
429299
return res.stderr != null && res.stderr.indexOf("musl libc") >= 0;
430300
}
431301

432-
async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
433-
while (true) {
434-
try {
435-
return await downloadFunc();
436-
} catch (e) {
437-
const selected = await vscode.window.showErrorMessage("Failed to download: " + e.message, {}, {
438-
title: "Update Github Auth Token",
439-
updateToken: true,
440-
}, {
441-
title: "Retry download",
442-
retry: true,
443-
}, {
444-
title: "Dismiss",
445-
});
446-
447-
if (selected?.updateToken) {
448-
await queryForGithubToken(state);
449-
continue;
450-
} else if (selected?.retry) {
451-
continue;
452-
}
453-
throw e;
454-
};
455-
}
456-
}
457-
458-
async function queryForGithubToken(state: PersistentState): Promise<void> {
459-
const githubTokenOptions: vscode.InputBoxOptions = {
460-
value: state.githubToken,
461-
password: true,
462-
prompt: `
463-
This dialog allows to store a Github authorization token.
464-
The usage of an authorization token will increase the rate
465-
limit on the use of Github APIs and can thereby prevent getting
466-
throttled.
467-
Auth tokens can be created at https://github.com/settings/tokens`,
468-
};
469-
470-
const newToken = await vscode.window.showInputBox(githubTokenOptions);
471-
if (newToken === undefined) {
472-
// The user aborted the dialog => Do not update the stored token
473-
return;
474-
}
475-
476-
if (newToken === "") {
477-
log.info("Clearing github token");
478-
await state.updateGithubToken(undefined);
479-
} else {
480-
log.info("Storing new github token");
481-
await state.updateGithubToken(newToken);
482-
}
483-
}
484-
485302
function warnAboutExtensionConflicts() {
486303
const conflicting = [
487304
["rust-analyzer", "matklad.rust-analyzer"],

editors/code/src/persistent_state.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,5 @@ import { log } from './util';
33

44
export class PersistentState {
55
constructor(private readonly globalState: vscode.Memento) {
6-
const { lastCheck, nightlyReleaseId, serverVersion } = this;
7-
log.info("PersistentState:", { lastCheck, nightlyReleaseId, serverVersion });
8-
}
9-
10-
/**
11-
* Used to check for *nightly* updates once an hour.
12-
*/
13-
get lastCheck(): number | undefined {
14-
return this.globalState.get("lastCheck");
15-
}
16-
async updateLastCheck(value: number) {
17-
await this.globalState.update("lastCheck", value);
18-
}
19-
20-
/**
21-
* Release id of the *nightly* extension.
22-
* Used to check if we should update.
23-
*/
24-
get nightlyReleaseId(): number | undefined {
25-
return this.globalState.get("releaseId");
26-
}
27-
async updateNightlyReleaseId(value: number | undefined) {
28-
await this.globalState.update("releaseId", value);
29-
}
30-
31-
/**
32-
* Version of the extension that installed the server.
33-
* Used to check if we need to update the server.
34-
*/
35-
get serverVersion(): string | undefined {
36-
return this.globalState.get("serverVersion");
37-
}
38-
async updateServerVersion(value: string | undefined) {
39-
await this.globalState.update("serverVersion", value);
40-
}
41-
42-
/**
43-
* Github authorization token.
44-
* This is used for API requests against the Github API.
45-
*/
46-
get githubToken(): string | undefined {
47-
return this.globalState.get("githubToken");
48-
}
49-
async updateGithubToken(value: string | undefined) {
50-
await this.globalState.update("githubToken", value);
516
}
527
}

0 commit comments

Comments
 (0)