From 8533fc437b7619e1c289fa7913fdafda533903b8 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 16 Feb 2020 03:08:36 +0200 Subject: vscode: add version and storage parameters to github binary source --- editors/code/package.json | 2 +- editors/code/src/client.ts | 2 +- editors/code/src/config.ts | 17 ++++++++++++++++- editors/code/src/ctx.ts | 4 ++++ editors/code/src/installation/interfaces.ts | 13 +++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/editors/code/package.json b/editors/code/package.json index a607c2148..96b8e9eb0 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -6,7 +6,7 @@ "private": true, "icon": "icon.png", "//": "The real version is in release.yaml, this one just needs to be bigger", - "version": "0.2.0-dev", + "version": "0.2.20200211-dev", "publisher": "matklad", "repository": { "url": "https://github.com/rust-analyzer/rust-analyzer.git", diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 12c97be2f..efef820ab 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -11,7 +11,7 @@ export async function createClient(config: Config): Promise `${Config.rootSection}.${opt}`); + private static readonly extensionVersion: string = (() => { + const packageJsonVersion = vscode + .extensions + .getExtension("matklad.rust-analyzer")! + .packageJSON + .version as string; // n.n.YYYYMMDD + + const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; + const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!; + + return `${yyyy}-${mm}-${dd}`; + })(); + private cfg!: vscode.WorkspaceConfiguration; constructor(private readonly ctx: vscode.ExtensionContext) { @@ -98,7 +111,7 @@ export class Config { } } - get serverBinarySource(): null | BinarySource { + get serverSource(): null | BinarySource { const serverPath = RA_LSP_DEBUG ?? this.cfg.get("raLspServerPath"); if (serverPath) { @@ -116,6 +129,8 @@ export class Config { type: BinarySource.Type.GithubRelease, dir: this.ctx.globalStoragePath, file: prebuiltBinaryName, + storage: this.ctx.globalState, + version: Config.extensionVersion, repo: { name: "rust-analyzer", owner: "rust-analyzer", diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 70042a479..9fcf2ec38 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -60,6 +60,10 @@ export class Ctx { this.pushCleanup(d); } + get globalState(): vscode.Memento { + return this.extCtx.globalState; + } + get subscriptions(): Disposable[] { return this.extCtx.subscriptions; } diff --git a/editors/code/src/installation/interfaces.ts b/editors/code/src/installation/interfaces.ts index 93ea577d4..e40839e4b 100644 --- a/editors/code/src/installation/interfaces.ts +++ b/editors/code/src/installation/interfaces.ts @@ -1,3 +1,5 @@ +import * as vscode from "vscode"; + export interface GithubRepo { name: string; owner: string; @@ -50,6 +52,17 @@ export namespace BinarySource { * and in local `.dir`. */ file: string; + + /** + * Tag of github release that denotes a version required by this extension. + */ + version: string; + + /** + * Object that provides `get()/update()` operations to store metadata + * about the actual binary, e.g. its actual version. + */ + storage: vscode.Memento; } } -- cgit v1.2.3