From 6d2d75367763686286779dd4b595a575c6ea689e Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 9 Mar 2020 19:57:13 +0200 Subject: vscode: prepare config for nightlies --- editors/code/src/config.ts | 111 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 15 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 6db073bec..e2b0f6f84 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -23,22 +23,36 @@ export interface CargoFeatures { allFeatures: boolean; features: string[]; } + +export const enum UpdatesChannel { + Stable = "stable", + Nightly = "nightly" +} + +export const NIGHTLY_TAG = "nightly"; export class Config { - private static readonly rootSection = "rust-analyzer"; - private static readonly requiresReloadOpts = [ + readonly extensionId = "matklad.rust-analyzer"; + + private readonly rootSection = "rust-analyzer"; + private readonly requiresReloadOpts = [ "cargoFeatures", "cargo-watch", "highlighting.semanticTokens", "inlayHints", ] - .map(opt => `${Config.rootSection}.${opt}`); + .map(opt => `${this.rootSection}.${opt}`); - private static readonly extensionVersion: string = (() => { + /** + * Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release) + */ + private readonly extensionVersion: string = (() => { const packageJsonVersion = vscode .extensions - .getExtension("matklad.rust-analyzer")! + .getExtension(this.extensionId)! .packageJSON - .version as string; // n.n.YYYYMMDD + .version as string; + + if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!; @@ -54,7 +68,7 @@ export class Config { } private refreshConfig() { - this.cfg = vscode.workspace.getConfiguration(Config.rootSection); + this.cfg = vscode.workspace.getConfiguration(this.rootSection); const enableLogging = this.cfg.get("trace.extension") as boolean; log.setEnabled(enableLogging); log.debug("Using configuration:", this.cfg); @@ -63,7 +77,7 @@ export class Config { private async onConfigChange(event: vscode.ConfigurationChangeEvent) { this.refreshConfig(); - const requiresReloadOpt = Config.requiresReloadOpts.find( + const requiresReloadOpt = this.requiresReloadOpts.find( opt => event.affectsConfiguration(opt) ); @@ -121,8 +135,16 @@ export class Config { } } + get installedExtensionUpdateChannel() { + if (this.serverPath !== null) return null; + + return this.extensionVersion === NIGHTLY_TAG + ? UpdatesChannel.Nightly + : UpdatesChannel.Stable; + } + get serverSource(): null | ArtifactSource { - const serverPath = RA_LSP_DEBUG ?? this.cfg.get("serverPath"); + const serverPath = RA_LSP_DEBUG ?? this.serverPath; if (serverPath) { return { @@ -135,23 +157,47 @@ export class Config { if (!prebuiltBinaryName) return null; + return this.createGithubReleaseSource( + prebuiltBinaryName, + this.extensionVersion + ); + } + + private createGithubReleaseSource(file: string, tag: string): ArtifactSource.GithubRelease { return { type: ArtifactSource.Type.GithubRelease, + file, + tag, dir: this.ctx.globalStoragePath, - file: prebuiltBinaryName, - storage: this.ctx.globalState, - tag: Config.extensionVersion, - askBeforeDownload: this.cfg.get("updates.askBeforeDownload") as boolean, repo: { name: "rust-analyzer", - owner: "rust-analyzer", + owner: "rust-analyzer" } - }; + } } + get nightlyVsixSource(): ArtifactSource.GithubRelease { + return this.createGithubReleaseSource("rust-analyzer.vsix", NIGHTLY_TAG); + } + + readonly installedNightlyExtensionReleaseDate = new DateStorage( + "rust-analyzer-installed-nightly-extension-release-date", + this.ctx.globalState + ); + readonly serverReleaseDate = new DateStorage( + "rust-analyzer-server-release-date", + this.ctx.globalState + ); + readonly serverReleaseTag = new StringStorage( + "rust-analyzer-release-tag", this.ctx.globalState + ); + // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension + private get serverPath() { return this.cfg.get("serverPath") as null | string; } + get updatesChannel() { return this.cfg.get("updates.channel") as UpdatesChannel; } + get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } get highlightingOn() { return this.cfg.get("highlightingOn") as boolean; } get rainbowHighlightingOn() { return this.cfg.get("rainbowHighlightingOn") as boolean; } @@ -189,3 +235,38 @@ export class Config { // for internal use get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; } } + +export class StringStorage { + constructor( + private readonly key: string, + private readonly storage: vscode.Memento + ) {} + + get(): null | string { + const tag = this.storage.get(this.key, null); + log.debug(this.key, "==", tag); + return tag; + } + async set(tag: string) { + log.debug(this.key, "=", tag); + await this.storage.update(this.key, tag); + } +} +export class DateStorage { + + constructor( + private readonly key: string, + private readonly storage: vscode.Memento + ) {} + + get(): null | Date { + const date = this.storage.get(this.key, null); + log.debug(this.key, "==", date); + return date ? new Date(date) : null; + } + + async set(date: null | Date) { + log.debug(this.key, "=", date); + await this.storage.update(this.key, date); + } +} -- cgit v1.2.3 From 7e6b1a60c3d7b20e1b4cee2ab210b617e359a002 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 9 Mar 2020 20:04:11 +0200 Subject: vscode: npm run fix --- editors/code/src/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index e2b0f6f84..b5c07876b 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -173,7 +173,7 @@ export class Config { name: "rust-analyzer", owner: "rust-analyzer" } - } + }; } get nightlyVsixSource(): ArtifactSource.GithubRelease { @@ -240,7 +240,7 @@ export class StringStorage { constructor( private readonly key: string, private readonly storage: vscode.Memento - ) {} + ) { } get(): null | string { const tag = this.storage.get(this.key, null); @@ -257,7 +257,7 @@ export class DateStorage { constructor( private readonly key: string, private readonly storage: vscode.Memento - ) {} + ) { } get(): null | Date { const date = this.storage.get(this.key, null); -- cgit v1.2.3 From 4d17152b31b27a8c851b4b1abaff359044ee9d96 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 9 Mar 2020 20:14:55 +0200 Subject: vscode: make bailing out on custom serverPath more evident --- editors/code/src/config.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index b5c07876b..345c9e21a 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -45,7 +45,7 @@ export class Config { /** * Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release) */ - private readonly extensionVersion: string = (() => { + readonly extensionReleaseTag: string = (() => { const packageJsonVersion = vscode .extensions .getExtension(this.extensionId)! @@ -135,10 +135,8 @@ export class Config { } } - get installedExtensionUpdateChannel() { - if (this.serverPath !== null) return null; - - return this.extensionVersion === NIGHTLY_TAG + get installedExtensionUpdateChannel(): UpdatesChannel { + return this.extensionReleaseTag === NIGHTLY_TAG ? UpdatesChannel.Nightly : UpdatesChannel.Stable; } @@ -159,7 +157,7 @@ export class Config { return this.createGithubReleaseSource( prebuiltBinaryName, - this.extensionVersion + this.extensionReleaseTag ); } @@ -195,7 +193,7 @@ export class Config { // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension - private get serverPath() { return this.cfg.get("serverPath") as null | string; } + get serverPath() { return this.cfg.get("serverPath") as null | string; } get updatesChannel() { return this.cfg.get("updates.channel") as UpdatesChannel; } get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } -- cgit v1.2.3 From 77a206e0b2614c13d296b2c36affe5d21df38aee Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 9 Mar 2020 20:17:50 +0200 Subject: vscode: put comma back --- editors/code/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 345c9e21a..a05d8ac06 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -169,7 +169,7 @@ export class Config { dir: this.ctx.globalStoragePath, repo: { name: "rust-analyzer", - owner: "rust-analyzer" + owner: "rust-analyzer", } }; } -- cgit v1.2.3 From bc87d6de86a2d67febe7e4e21347af9c92dc7552 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 9 Mar 2020 20:28:12 +0200 Subject: vscode-postrefactor: global storages --- editors/code/src/config.ts | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index a05d8ac06..5371384ba 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -186,8 +186,8 @@ export class Config { "rust-analyzer-server-release-date", this.ctx.globalState ); - readonly serverReleaseTag = new StringStorage( - "rust-analyzer-release-tag", this.ctx.globalState + readonly serverReleaseTag = new Storage( + "rust-analyzer-release-tag", this.ctx.globalState, null ); // We don't do runtime config validation here for simplicity. More on stackoverflow: @@ -234,37 +234,36 @@ export class Config { get withSysroot() { return this.cfg.get("withSysroot", true) as boolean; } } -export class StringStorage { +export class Storage { constructor( private readonly key: string, - private readonly storage: vscode.Memento + private readonly storage: vscode.Memento, + private readonly defaultVal: T ) { } - get(): null | string { - const tag = this.storage.get(this.key, null); - log.debug(this.key, "==", tag); - return tag; + get(): T { + const val = this.storage.get(this.key, this.defaultVal); + log.debug(this.key, "==", val); + return val; } - async set(tag: string) { - log.debug(this.key, "=", tag); - await this.storage.update(this.key, tag); + async set(val: T) { + log.debug(this.key, "=", val); + await this.storage.update(this.key, val); } } export class DateStorage { + inner: Storage; - constructor( - private readonly key: string, - private readonly storage: vscode.Memento - ) { } + constructor(key: string, storage: vscode.Memento) { + this.inner = new Storage(key, storage, null); + } get(): null | Date { - const date = this.storage.get(this.key, null); - log.debug(this.key, "==", date); - return date ? new Date(date) : null; + const dateStr = this.inner.get(); + return dateStr ? new Date(dateStr) : null; } async set(date: null | Date) { - log.debug(this.key, "=", date); - await this.storage.update(this.key, date); + await this.inner.set(date ? date.toString() : null); } } -- cgit v1.2.3 From 7f02d4657b796a438e441e107d4fb1906ec1ed7b Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 14 Mar 2020 02:00:34 +0200 Subject: vscode-postrefactor: minor config refactorings --- editors/code/src/config.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 5371384ba..93f72409d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -35,6 +35,7 @@ export class Config { private readonly rootSection = "rust-analyzer"; private readonly requiresReloadOpts = [ + "serverPath", "cargoFeatures", "cargo-watch", "highlighting.semanticTokens", @@ -50,7 +51,7 @@ export class Config { .extensions .getExtension(this.extensionId)! .packageJSON - .version as string; + .version as string; // n.n.YYYYMMDD[-nightly] if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; @@ -193,7 +194,7 @@ export class Config { // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension - get serverPath() { return this.cfg.get("serverPath") as null | string; } + private get serverPath() { return this.cfg.get("serverPath") as null | string; } get updatesChannel() { return this.cfg.get("updates.channel") as UpdatesChannel; } get askBeforeDownload() { return this.cfg.get("updates.askBeforeDownload") as boolean; } get highlightingSemanticTokens() { return this.cfg.get("highlighting.semanticTokens") as boolean; } -- cgit v1.2.3 From 5e32a67c83d46862db0166c263efc65b6ecd5b52 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 14 Mar 2020 03:01:14 +0200 Subject: vscode-postrefactor: more logging and better error handling --- editors/code/src/config.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'editors/code/src/config.ts') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 93f72409d..f63e1d20e 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -1,7 +1,7 @@ import * as os from "os"; import * as vscode from 'vscode'; import { ArtifactSource } from "./installation/interfaces"; -import { log } from "./util"; +import { log, vscodeReloadWindow } from "./util"; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; @@ -43,20 +43,20 @@ export class Config { ] .map(opt => `${this.rootSection}.${opt}`); + readonly packageJsonVersion = vscode + .extensions + .getExtension(this.extensionId)! + .packageJSON + .version as string; // n.n.YYYYMMDD[-nightly] + /** * Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release) */ readonly extensionReleaseTag: string = (() => { - const packageJsonVersion = vscode - .extensions - .getExtension(this.extensionId)! - .packageJSON - .version as string; // n.n.YYYYMMDD[-nightly] - - if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; + if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; - const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!; + const [, yyyy, mm, dd] = this.packageJsonVersion.match(realVersionRegexp)!; return `${yyyy}-${mm}-${dd}`; })(); @@ -72,7 +72,10 @@ export class Config { this.cfg = vscode.workspace.getConfiguration(this.rootSection); const enableLogging = this.cfg.get("trace.extension") as boolean; log.setEnabled(enableLogging); - log.debug("Using configuration:", this.cfg); + log.debug( + "Extension version:", this.packageJsonVersion, + "using configuration:", this.cfg + ); } private async onConfigChange(event: vscode.ConfigurationChangeEvent) { @@ -90,7 +93,7 @@ export class Config { ); if (userResponse === "Reload now") { - vscode.commands.executeCommand("workbench.action.reloadWindow"); + await vscodeReloadWindow(); } } @@ -180,16 +183,11 @@ export class Config { } readonly installedNightlyExtensionReleaseDate = new DateStorage( - "rust-analyzer-installed-nightly-extension-release-date", + "installed-nightly-extension-release-date", this.ctx.globalState ); - readonly serverReleaseDate = new DateStorage( - "rust-analyzer-server-release-date", - this.ctx.globalState - ); - readonly serverReleaseTag = new Storage( - "rust-analyzer-release-tag", this.ctx.globalState, null - ); + readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState); + readonly serverReleaseTag = new Storage("server-release-tag", this.ctx.globalState, null); // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension -- cgit v1.2.3