vscode: add version and storage parameters to github binary source
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user