From b03cb725e35dea9a34b9e65cb67feac4befcfc09 Mon Sep 17 00:00:00 2001 From: Brett Saviano Date: Wed, 4 Sep 2024 08:30:30 -0400 Subject: [PATCH] Store server version in workspace state --- src/api/index.ts | 13 +++++++++++++ src/extension.ts | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/api/index.ts b/src/api/index.ts index e128e35e..6879b28f 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -5,6 +5,7 @@ import * as httpModule from "http"; import * as httpsModule from "https"; import * as vscode from "vscode"; import * as Cache from "vscode-cache"; +import * as semver from "semver"; import { getResolvedConnectionSpec, config, @@ -18,6 +19,7 @@ import { import { currentWorkspaceFolder, outputChannel, outputConsole } from "../utils"; const DEFAULT_API_VERSION = 1; +const DEFAULT_SERVER_VERSION = "2016.2.0"; import * as Atelier from "./atelier"; // Map of the authRequest promises for each username@host:port target to avoid concurrency issues @@ -27,6 +29,7 @@ export interface ConnectionSettings { serverName: string; active: boolean; apiVersion: number; + serverVersion: string; https: boolean; host: string; port: number; @@ -61,12 +64,14 @@ export class AtelierAPI { const port = this.externalServer ? this._config.port : workspaceState.get(wsKey + ":port", this._config.port); const password = workspaceState.get(wsKey + ":password", this._config.password); const apiVersion = workspaceState.get(wsKey + ":apiVersion", DEFAULT_API_VERSION); + const serverVersion = workspaceState.get(wsKey + ":serverVersion", DEFAULT_SERVER_VERSION); const docker = workspaceState.get(wsKey + ":docker", false); const dockerService = workspaceState.get(wsKey + ":dockerService"); return { serverName, active, apiVersion, + serverVersion, https, host, port, @@ -200,6 +205,7 @@ export class AtelierAPI { serverName, active: this.externalServer || conn.active, apiVersion: workspaceState.get(this.configName.toLowerCase() + ":apiVersion", DEFAULT_API_VERSION), + serverVersion: workspaceState.get(this.configName.toLowerCase() + ":serverVersion", DEFAULT_SERVER_VERSION), https: scheme === "https", ns, host, @@ -466,6 +472,12 @@ export class AtelierAPI { if (info && info.result && info.result.content && info.result.content.api > 0) { const data = info.result.content; const apiVersion = data.api; + const serverVersion = semver.coerce( + data.version + .slice(data.version.indexOf(") ") + 2) + .split(" ") + .shift() + ).version; if (this.ns && this.ns.length && !data.namespaces.includes(this.ns) && checkNs) { throw { code: "WrongNamespace", @@ -476,6 +488,7 @@ export class AtelierAPI { } return Promise.all([ workspaceState.update(this.configName.toLowerCase() + ":apiVersion", apiVersion), + workspaceState.update(this.configName.toLowerCase() + ":serverVersion", serverVersion), workspaceState.update(this.configName.toLowerCase() + ":iris", data.version.startsWith("IRIS")), ]).then(() => info); } diff --git a/src/extension.ts b/src/extension.ts index 240af4fc..339e6cc3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -274,6 +274,7 @@ export async function checkConnection( await workspaceState.update(wsKey + ":port", undefined); await workspaceState.update(wsKey + ":password", undefined); await workspaceState.update(wsKey + ":apiVersion", undefined); + await workspaceState.update(wsKey + ":serverVersion", undefined); await workspaceState.update(wsKey + ":docker", undefined); _onDidChangeConnection.fire(); } @@ -1528,6 +1529,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { password, ns = "", apiVersion, + serverVersion, } = api.config; return { serverName, @@ -1545,6 +1547,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { .get("password"), namespace: ns, apiVersion: active ? apiVersion : undefined, + serverVersion: active ? serverVersion : undefined, }; }, serverDocumentUriForUri(uri: vscode.Uri): vscode.Uri {