]> git.lizzy.rs Git - rust.git/commitdiff
vscode: add version and storage parameters to github binary source
authorVeetaha <gerzoh1@gmail.com>
Sun, 16 Feb 2020 01:08:36 +0000 (03:08 +0200)
committerVeetaha <gerzoh1@gmail.com>
Sun, 16 Feb 2020 01:41:39 +0000 (03:41 +0200)
editors/code/package.json
editors/code/src/client.ts
editors/code/src/config.ts
editors/code/src/ctx.ts
editors/code/src/installation/interfaces.ts

index a607c21480053e820531f5437af8ce12b6c4a912..96b8e9eb06562a464f25830e7b3c362cc1d30353 100644 (file)
@@ -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",
index 12c97be2feeb783a5c2316fbbad560e50ec3e261..efef820abfaf609fd0497b5a7f804922d339e36b 100644 (file)
@@ -11,7 +11,7 @@ export async function createClient(config: Config): Promise<null | lc.LanguageCl
     // It might be a good idea to test if the uri points to a file.
     const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
 
-    const serverPath = await ensureServerBinary(config.serverBinarySource);
+    const serverPath = await ensureServerBinary(config.serverSource);
     if (!serverPath) return null;
 
     const run: lc.Executable = {
index 7866ed7e1b511cde60a7a892e47ea82eb4c85355..4335c3a7180d2eca7012ff5383c3712032574874 100644 (file)
@@ -24,6 +24,19 @@ export class Config {
     ]
     .map(opt => `${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<null | string>("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",
index 70042a479e9ae921523125de7042864924232ee8..9fcf2ec3826eda09743c2fcdbb910a5d7c1487b4 100644 (file)
@@ -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;
     }
index 93ea577d4a65c24874c0c3209621ac5c11ae4b0d..e40839e4b2ba4fc36cd74c73cc444f35483565d0 100644 (file)
@@ -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;
     }
 
 }