Skip to content

Commit 88074fa

Browse files
authored
Merge pull request #2722 from codefori/feature/debug_version_check
Show warning for unsupported minimum debug version
2 parents 2d51ff2 + f9b6ae9 commit 88074fa

File tree

4 files changed

+73
-41
lines changed

4 files changed

+73
-41
lines changed

src/api/configuration/DebugConfiguration.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ export function resetDebugServiceDetails() {
102102
export async function getDebugServiceDetails(connection: IBMi): Promise<DebugServiceDetails> {
103103
if (!debugServiceDetails) {
104104
let details = {
105-
version: `1.0.0`,
106-
java: `8`,
105+
version: `0.0.0`,
106+
java: ``,
107107
semanticVersion: () => ({
108-
major: 1,
108+
major: 0,
109109
minor: 0,
110110
patch: 0
111111
})
@@ -129,17 +129,6 @@ export async function getDebugServiceDetails(connection: IBMi): Promise<DebugSer
129129
}
130130
}
131131
}
132-
else {
133-
details = {
134-
version: `1.0.0`,
135-
java: `8`,
136-
semanticVersion: () => ({
137-
major: 1,
138-
minor: 0,
139-
patch: 0
140-
})
141-
};
142-
}
143132

144133
debugServiceDetails = details;
145134
}

src/api/configuration/storage/ConnectionStorage.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const LAST_PROFILE_KEY = `currentProfile`;
66
const SOURCE_LIST_KEY = `sourceList`;
77
const DEPLOYMENT_KEY = `deployment`;
88
const DEBUG_KEY = `debug`;
9+
const MESSAGE_SHOWN_KEY = `messageShown`;
910

1011
const RECENTLY_OPENED_FILES_KEY = `recentlyOpenedFiles`;
1112
const AUTHORISED_EXTENSIONS_KEY = `authorisedExtensions`
@@ -128,4 +129,17 @@ export class ConnectionStorage {
128129
const newExtensions = this.getAuthorisedExtensions().filter(ext => !extensions.includes(ext));
129130
return this.internalStorage.set(AUTHORISED_EXTENSIONS_KEY, newExtensions);
130131
}
132+
133+
hasMessageBeenShown(messageId: string): boolean {
134+
const shownMessages = this.internalStorage.get<string[]>(MESSAGE_SHOWN_KEY) || [];
135+
return shownMessages.includes(messageId);
136+
}
137+
138+
async markMessageAsShown(messageId: string): Promise<void> {
139+
const shownMessages = this.internalStorage.get<string[]>(MESSAGE_SHOWN_KEY) || [];
140+
if (!shownMessages.includes(messageId)) {
141+
shownMessages.push(messageId);
142+
await this.internalStorage.set(MESSAGE_SHOWN_KEY, shownMessages);
143+
}
144+
}
131145
}

src/debug/index.ts

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { ExtensionContext, Uri } from "vscode";
1+
import { env, ExtensionContext, Uri } from "vscode";
22
import Instance from "../Instance";
33

44
import path from "path";
55
import * as vscode from 'vscode';
66

7-
import { instance } from "../instantiate";
8-
import { ObjectItem } from "../typings";
97
import { ILELibrarySettings } from "../api/CompileTools";
8+
import { getDebugServiceDetails, ORIGINAL_DEBUG_CONFIG_FILE, resetDebugServiceDetails } from "../api/configuration/DebugConfiguration";
9+
import IBMi from "../api/IBMi";
10+
import { getStoredPassword } from "../config/passwords";
1011
import { Env, getEnvConfig } from "../filesystems/local/env";
12+
import { instance } from "../instantiate";
13+
import { ObjectItem } from "../typings";
14+
import { VscodeTools } from "../ui/Tools";
1115
import * as certificates from "./certificates";
12-
import { DebugConfiguration, getDebugServiceDetails, ORIGINAL_DEBUG_CONFIG_FILE, resetDebugServiceDetails } from "../api/configuration/DebugConfiguration";
1316
import * as server from "./server";
14-
import { VscodeTools } from "../ui/Tools";
15-
import { getStoredPassword } from "../config/passwords";
16-
import IBMi from "../api/IBMi";
1717

1818
const debugExtensionId = `IBM.ibmidebug`;
1919

@@ -296,29 +296,56 @@ export async function initialize(context: ExtensionContext) {
296296
async () => {
297297
activateDebugExtension();
298298
const connection = instance.getConnection();
299-
if (connection && (await server.isDebugSupported(connection))) {
300-
vscode.commands.executeCommand(`setContext`, ptfContext, true);
299+
if (connection) {
300+
const debuggerInstalled = server.debugPTFInstalled(connection);
301+
const debugDetails = await getDebugServiceDetails(connection);
302+
if (debuggerInstalled) {
303+
if (debugDetails.semanticVersion().major >= server.MIN_DEBUG_VERSION) {
304+
vscode.commands.executeCommand(`setContext`, ptfContext, true);
301305

302-
//Enable debug related commands
303-
vscode.commands.executeCommand(`setContext`, debugContext, true);
306+
//Enable debug related commands
307+
vscode.commands.executeCommand(`setContext`, debugContext, true);
304308

305-
//Enable service entry points related commands
306-
vscode.commands.executeCommand(`setContext`, debugSEPContext, true);
309+
//Enable service entry points related commands
310+
vscode.commands.executeCommand(`setContext`, debugSEPContext, true);
307311

308-
const isDebugManaged = isManaged();
309-
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:debugManaged`, isDebugManaged);
310-
if (!isDebugManaged) {
311-
if (validateIPv4address(connection.currentHost)) {
312-
vscode.window.showWarningMessage(`You are using an IPv4 address to connect to this system. This may cause issues with debugging. Please use a hostname in the Login Settings instead.`);
313-
}
312+
const isDebugManaged = isManaged();
313+
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:debugManaged`, isDebugManaged);
314314

315-
// Set the debug environment variables early to be safe
316-
setCertEnv(true, connection);
315+
if (!isDebugManaged) {
316+
if (validateIPv4address(connection.currentHost)) {
317+
vscode.window.showWarningMessage(`You are using an IPv4 address to connect to this system. This may cause issues with debugging. Please use a hostname in the Login Settings instead.`);
318+
}
317319

318-
// Download the client certificate if it doesn't exist.
319-
certificates.checkClientCertificate(connection).catch(() => {
320-
vscode.commands.executeCommand(`code-for-ibmi.debug.setup.local`);
321-
});
320+
// Set the debug environment variables early to be safe
321+
setCertEnv(true, connection);
322+
323+
// Download the client certificate if it doesn't exist.
324+
certificates.checkClientCertificate(connection).catch(() => {
325+
vscode.commands.executeCommand(`code-for-ibmi.debug.setup.local`);
326+
});
327+
}
328+
}
329+
else {
330+
const storage = instance.getStorage();
331+
if (storage && debugDetails.semanticVersion().major < server.MIN_DEBUG_VERSION) {
332+
const debugUpdateMessageId = `debugUpdateRequired-${server.MIN_DEBUG_VERSION}`;
333+
const showMessage = !storage.hasMessageBeenShown(debugUpdateMessageId);
334+
335+
if (showMessage) {
336+
vscode.window.showWarningMessage(`Debug service version ${debugDetails.version} is below the minimum required version ${server.MIN_DEBUG_VERSION}.0.0. Please update the debug service PTF.`, `Open docs`, `Dismiss`).then(selected => {
337+
switch (selected) {
338+
case `Open docs`:
339+
env.openExternal(Uri.parse(`https://codefori.github.io/docs/developing/debug/`));
340+
break;
341+
case `Dismiss`:
342+
storage.markMessageAsShown(debugUpdateMessageId);
343+
break;
344+
}
345+
});
346+
}
347+
}
348+
}
322349
}
323350
}
324351
});
@@ -372,7 +399,7 @@ export async function startDebug(instance: Instance, options: DebugOptions) {
372399
secure = setCertEnv(secure, connection);
373400

374401
if (options.sep) {
375-
if (serviceDetails.version === `1.0.0`) {
402+
if (serviceDetails.semanticVersion().major < 2) {
376403
vscode.window.showErrorMessage(`The debug service on this system, version ${serviceDetails.version}, does not support service entry points.`);
377404
return;
378405
}

src/debug/server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ export type DebugJob = {
1010
ports: number[]
1111
}
1212

13+
export const MIN_DEBUG_VERSION = 3;
14+
1315
export function debugPTFInstalled(connection: IBMi) {
1416
return connection.debugPTFInstalled()
1517
}
1618

1719
export async function isDebugSupported(connection: IBMi) {
18-
return debugPTFInstalled(connection) && (await getDebugServiceDetails(connection)).semanticVersion().major >= 3;
20+
return debugPTFInstalled(connection) && (await getDebugServiceDetails(connection)).semanticVersion().major >= MIN_DEBUG_VERSION;
1921
}
2022

2123
export async function startService(connection: IBMi) {

0 commit comments

Comments
 (0)