Skip to content

Commit a53daf7

Browse files
authored
Store server version in workspace state (#1426)
1 parent 01c9c91 commit a53daf7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/api/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as httpModule from "http";
55
import * as httpsModule from "https";
66
import * as vscode from "vscode";
77
import * as Cache from "vscode-cache";
8+
import * as semver from "semver";
89
import {
910
getResolvedConnectionSpec,
1011
config,
@@ -18,6 +19,7 @@ import {
1819
import { currentWorkspaceFolder, outputChannel, outputConsole } from "../utils";
1920

2021
const DEFAULT_API_VERSION = 1;
22+
const DEFAULT_SERVER_VERSION = "2016.2.0";
2123
import * as Atelier from "./atelier";
2224

2325
// Map of the authRequest promises for each username@host:port target to avoid concurrency issues
@@ -27,6 +29,7 @@ export interface ConnectionSettings {
2729
serverName: string;
2830
active: boolean;
2931
apiVersion: number;
32+
serverVersion: string;
3033
https: boolean;
3134
host: string;
3235
port: number;
@@ -61,12 +64,14 @@ export class AtelierAPI {
6164
const port = this.externalServer ? this._config.port : workspaceState.get(wsKey + ":port", this._config.port);
6265
const password = workspaceState.get(wsKey + ":password", this._config.password);
6366
const apiVersion = workspaceState.get(wsKey + ":apiVersion", DEFAULT_API_VERSION);
67+
const serverVersion = workspaceState.get(wsKey + ":serverVersion", DEFAULT_SERVER_VERSION);
6468
const docker = workspaceState.get(wsKey + ":docker", false);
6569
const dockerService = workspaceState.get<string>(wsKey + ":dockerService");
6670
return {
6771
serverName,
6872
active,
6973
apiVersion,
74+
serverVersion,
7075
https,
7176
host,
7277
port,
@@ -200,6 +205,7 @@ export class AtelierAPI {
200205
serverName,
201206
active: this.externalServer || conn.active,
202207
apiVersion: workspaceState.get(this.configName.toLowerCase() + ":apiVersion", DEFAULT_API_VERSION),
208+
serverVersion: workspaceState.get(this.configName.toLowerCase() + ":serverVersion", DEFAULT_SERVER_VERSION),
203209
https: scheme === "https",
204210
ns,
205211
host,
@@ -466,6 +472,12 @@ export class AtelierAPI {
466472
if (info && info.result && info.result.content && info.result.content.api > 0) {
467473
const data = info.result.content;
468474
const apiVersion = data.api;
475+
const serverVersion = semver.coerce(
476+
data.version
477+
.slice(data.version.indexOf(") ") + 2)
478+
.split(" ")
479+
.shift()
480+
).version;
469481
if (this.ns && this.ns.length && !data.namespaces.includes(this.ns) && checkNs) {
470482
throw {
471483
code: "WrongNamespace",
@@ -476,6 +488,7 @@ export class AtelierAPI {
476488
}
477489
return Promise.all([
478490
workspaceState.update(this.configName.toLowerCase() + ":apiVersion", apiVersion),
491+
workspaceState.update(this.configName.toLowerCase() + ":serverVersion", serverVersion),
479492
workspaceState.update(this.configName.toLowerCase() + ":iris", data.version.startsWith("IRIS")),
480493
]).then(() => info);
481494
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export async function checkConnection(
274274
await workspaceState.update(wsKey + ":port", undefined);
275275
await workspaceState.update(wsKey + ":password", undefined);
276276
await workspaceState.update(wsKey + ":apiVersion", undefined);
277+
await workspaceState.update(wsKey + ":serverVersion", undefined);
277278
await workspaceState.update(wsKey + ":docker", undefined);
278279
_onDidChangeConnection.fire();
279280
}
@@ -1528,6 +1529,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
15281529
password,
15291530
ns = "",
15301531
apiVersion,
1532+
serverVersion,
15311533
} = api.config;
15321534
return {
15331535
serverName,
@@ -1545,6 +1547,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
15451547
.get("password"),
15461548
namespace: ns,
15471549
apiVersion: active ? apiVersion : undefined,
1550+
serverVersion: active ? serverVersion : undefined,
15481551
};
15491552
},
15501553
serverDocumentUriForUri(uri: vscode.Uri): vscode.Uri {

0 commit comments

Comments
 (0)