Skip to content

Commit 57eedd9

Browse files
bors[bot]SomeoneToIgnorematklad
authored
Merge #8936 #8939
8936: fix: Improve nightly downloads with better local state management r=matklad a=SomeoneToIgnore When any nightly is downloaded, we store its GitHub release id in the local cache and never invalidate that cache. Due to this, it was possible to do the following sequence: * have the nightly locally * downgrade the extension to any stable version * observe that despite the `"rust-analyzer.updates.channel": "nightly",` setting, no nightly updates are happening * on the next day, the actual update happens (given the new nightly is released) Since it's impossible to install nightly version directly through the VSCode marketplace, any fiddling with dev version results in the same situation: one have to wait for the next nightly release to happen in order to restore the nightly. This PR * invalidates the cache eagerly during bootstrap if the current plugin is not nightly * enforces the release id check for nightly versions only * fixes the `ctx.globalStoragePath` deprecated API usage Hopefully, it also helps mysterious non-updated plugins that we encounter from time to time, but hard to tell for sure. 8939: internal: disable debug symbols due to failing windows build r=matklad a=matklad bors r+ 🤖 Co-authored-by: Kirill Bulatov <mail4score@gmail.com> Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 parents 0ec4ce1 + daedcc2 + 9f9c4bf commit 57eedd9

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

editors/code/src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { log } from "./util";
44

55
export type UpdatesChannel = "stable" | "nightly";
66

7-
export const NIGHTLY_TAG = "nightly";
7+
const NIGHTLY_TAG = "nightly";
88

99
export type RunnableEnvCfg = undefined | Record<string, string> | { mask?: string; env: Record<string, string> }[];
1010

@@ -34,7 +34,7 @@ export class Config {
3434
readonly globalStoragePath: string;
3535

3636
constructor(ctx: vscode.ExtensionContext) {
37-
this.globalStoragePath = ctx.globalStoragePath;
37+
this.globalStoragePath = ctx.globalStorageUri.path;
3838
vscode.workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, ctx.subscriptions);
3939
this.refreshLogging();
4040
}
@@ -170,4 +170,8 @@ export class Config {
170170
gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
171171
};
172172
}
173+
174+
get currentExtensionIsNightly() {
175+
return this.package.releaseTag === NIGHTLY_TAG;
176+
}
173177
}

editors/code/src/main.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { promises as fs, PathLike } from "fs";
66
import * as commands from './commands';
77
import { activateInlayHints } from './inlay_hints';
88
import { Ctx } from './ctx';
9-
import { Config, NIGHTLY_TAG } from './config';
9+
import { Config } from './config';
1010
import { log, assert, isValidExecutable } from './util';
1111
import { PersistentState } from './persistent_state';
1212
import { fetchRelease, download } from './net';
@@ -156,16 +156,18 @@ export async function deactivate() {
156156
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
157157
await fs.mkdir(config.globalStoragePath, { recursive: true });
158158

159+
if (!config.currentExtensionIsNightly) {
160+
await state.updateNightlyReleaseId(undefined);
161+
}
159162
await bootstrapExtension(config, state);
160163
const path = await bootstrapServer(config, state);
161-
162164
return path;
163165
}
164166

165167
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
166168
if (config.package.releaseTag === null) return;
167169
if (config.channel === "stable") {
168-
if (config.package.releaseTag === NIGHTLY_TAG) {
170+
if (config.currentExtensionIsNightly) {
169171
void vscode.window.showWarningMessage(
170172
`You are running a nightly version of rust-analyzer extension. ` +
171173
`To switch to stable, uninstall the extension and re-install it from the marketplace`
@@ -176,36 +178,43 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
176178
if (serverPath(config)) return;
177179

178180
const now = Date.now();
179-
if (config.package.releaseTag === NIGHTLY_TAG) {
181+
const isInitialNightlyDownload = state.nightlyReleaseId === undefined;
182+
if (config.currentExtensionIsNightly) {
180183
// Check if we should poll github api for the new nightly version
181184
// if we haven't done it during the past hour
182185
const lastCheck = state.lastCheck;
183186

184187
const anHour = 60 * 60 * 1000;
185-
const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour;
188+
const shouldCheckForNewNightly = isInitialNightlyDownload || (now - (lastCheck ?? 0)) > anHour;
186189

187190
if (!shouldCheckForNewNightly) return;
188191
}
189192

190-
const release = await downloadWithRetryDialog(state, async () => {
193+
const latestNightlyRelease = await downloadWithRetryDialog(state, async () => {
191194
return await fetchRelease("nightly", state.githubToken, config.httpProxy);
192195
}).catch(async (e) => {
193196
log.error(e);
194-
if (state.releaseId === undefined) { // Show error only for the initial download
195-
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
197+
if (isInitialNightlyDownload) {
198+
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
196199
}
197-
return undefined;
200+
return;
198201
});
199-
if (release === undefined || release.id === state.releaseId) return;
202+
if (latestNightlyRelease === undefined) {
203+
if (isInitialNightlyDownload) {
204+
await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
205+
}
206+
return;
207+
}
208+
if (config.currentExtensionIsNightly && latestNightlyRelease.id === state.nightlyReleaseId) return;
200209

201210
const userResponse = await vscode.window.showInformationMessage(
202211
"New version of rust-analyzer (nightly) is available (requires reload).",
203212
"Update"
204213
);
205214
if (userResponse !== "Update") return;
206215

207-
const artifact = release.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
208-
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
216+
const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
217+
assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
209218

210219
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
211220

@@ -221,7 +230,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
221230
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
222231
await fs.unlink(dest);
223232

224-
await state.updateReleaseId(release.id);
233+
await state.updateNightlyReleaseId(latestNightlyRelease.id);
225234
await state.updateLastCheck(now);
226235
await vscode.commands.executeCommand("workbench.action.reloadWindow");
227236
}

editors/code/src/persistent_state.ts

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

44
export class PersistentState {
55
constructor(private readonly globalState: vscode.Memento) {
6-
const { lastCheck, releaseId, serverVersion } = this;
7-
log.info("PersistentState:", { lastCheck, releaseId, serverVersion });
6+
const { lastCheck, nightlyReleaseId, serverVersion } = this;
7+
log.info("PersistentState:", { lastCheck, nightlyReleaseId, serverVersion });
88
}
99

1010
/**
@@ -21,10 +21,10 @@ export class PersistentState {
2121
* Release id of the *nightly* extension.
2222
* Used to check if we should update.
2323
*/
24-
get releaseId(): number | undefined {
24+
get nightlyReleaseId(): number | undefined {
2525
return this.globalState.get("releaseId");
2626
}
27-
async updateReleaseId(value: number) {
27+
async updateNightlyReleaseId(value: number | undefined) {
2828
await this.globalState.update("releaseId", value);
2929
}
3030

xtask/src/dist.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
6767
fn dist_server(release_channel: &str) -> Result<()> {
6868
let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel);
6969
let _e = pushenv("CARGO_PROFILE_RELEASE_LTO", "true");
70-
let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
70+
71+
// We want do enable debug symbols, but this causes our windows CI to fail:
72+
// https://github.com/rust-lang/rust/issues/85598
73+
//
74+
// let _e = pushenv("CARGO_PROFILE_RELEASE_DEBUG", "1");
75+
7176
let target = get_target();
7277
if target.contains("-linux-gnu") || target.contains("-linux-musl") {
7378
env::set_var("CC", "clang");

0 commit comments

Comments
 (0)