mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-23 10:25:06 +00:00
b93ced6f63
This change allows to use a authorization token provided by Github in order to fetch metadata for a RA release. Using an authorization token prevents to get rate-limited in environments where lots of RA users use a shared client IP (e.g. behind a company NAT). The auth token is stored in `ExtensionContext.globalState`. As far as I could observe through testing with a local WSL2 environment that state is synced between an extension installed locally and a remote version. The change provides no explicit command to query for an auth token. However in case a download fails it will provide a retry option as well as an option to enter the auth token. This should be more discoverable for most users. Closes #3688
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import * as vscode from 'vscode';
|
|
import { log } from './util';
|
|
|
|
export class PersistentState {
|
|
constructor(private readonly globalState: vscode.Memento) {
|
|
const { lastCheck, releaseId, serverVersion } = this;
|
|
log.info("PersistentState:", { lastCheck, releaseId, serverVersion });
|
|
}
|
|
|
|
/**
|
|
* Used to check for *nightly* updates once an hour.
|
|
*/
|
|
get lastCheck(): number | undefined {
|
|
return this.globalState.get("lastCheck");
|
|
}
|
|
async updateLastCheck(value: number) {
|
|
await this.globalState.update("lastCheck", value);
|
|
}
|
|
|
|
/**
|
|
* Release id of the *nightly* extension.
|
|
* Used to check if we should update.
|
|
*/
|
|
get releaseId(): number | undefined {
|
|
return this.globalState.get("releaseId");
|
|
}
|
|
async updateReleaseId(value: number) {
|
|
await this.globalState.update("releaseId", value);
|
|
}
|
|
|
|
/**
|
|
* Version of the extension that installed the server.
|
|
* Used to check if we need to update the server.
|
|
*/
|
|
get serverVersion(): string | undefined {
|
|
return this.globalState.get("serverVersion");
|
|
}
|
|
async updateServerVersion(value: string | undefined) {
|
|
await this.globalState.update("serverVersion", value);
|
|
}
|
|
|
|
/**
|
|
* Github authorization token.
|
|
* This is used for API requests against the Github API.
|
|
*/
|
|
get githubToken(): string | undefined {
|
|
return this.globalState.get("githubToken");
|
|
}
|
|
async updateGithubToken(value: string | undefined) {
|
|
await this.globalState.update("githubToken", value);
|
|
}
|
|
}
|