Skip to content

Commit 01bbe4a

Browse files
committed
Hide debug commands and SEP commands based on the debug PTF and debugger version
Signed-off-by: Seb Julliand <sebjulliand@gmail.com>
1 parent de6f6ba commit 01bbe4a

5 files changed

Lines changed: 94 additions & 26 deletions

File tree

package.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@
16161616
"title": "Toggle hidden files",
16171617
"enablement": "code-for-ibmi:connected",
16181618
"category": "IBM i",
1619-
"icon": "$(shield)"
1619+
"icon": "$(shield)"
16201620
},
16211621
{
16221622
"command": "code-for-ibmi.openDebugStatus",
@@ -1803,10 +1803,12 @@
18031803
],
18041804
"code-for-ibmi.debug.group": [
18051805
{
1806-
"command": "code-for-ibmi.debug.batch"
1806+
"command": "code-for-ibmi.debug.batch",
1807+
"when": "code-for-ibmi:debug"
18071808
},
18081809
{
1809-
"command": "code-for-ibmi.debug.sep"
1810+
"command": "code-for-ibmi.debug.sep",
1811+
"when": "code-for-ibmi:debug.SEP"
18101812
}
18111813
],
18121814
"commandPalette": [
@@ -2137,6 +2139,26 @@
21372139
{
21382140
"command": "code-for-ibmi.openDebugStatus",
21392141
"when": "never"
2142+
},
2143+
{
2144+
"command": "code-for-ibmi.debug.setup.remote",
2145+
"when": "code-for-ibmi:debug"
2146+
},
2147+
{
2148+
"command": "code-for-ibmi.debug.setup.local",
2149+
"when": "code-for-ibmi:debug"
2150+
},
2151+
{
2152+
"command": "code-for-ibmi.debug.start",
2153+
"when": "code-for-ibmi:debug"
2154+
},
2155+
{
2156+
"command": "code-for-ibmi.debug.stop",
2157+
"when": "code-for-ibmi:debug"
2158+
},
2159+
{
2160+
"command": "code-for-ibmi.debug.endDebug",
2161+
"when": "code-for-ibmi:debug"
21402162
}
21412163
],
21422164
"view/title": [
@@ -2748,4 +2770,4 @@
27482770
"HalcyonTechLtd.vscode-ibmi-walkthroughs",
27492771
"vscode.git"
27502772
]
2751-
}
2773+
}

src/api/debug/index.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import * as server from "./server";
1515

1616
const debugExtensionId = `IBM.ibmidebug`;
1717

18+
const debugContext = 'code-for-ibmi:debug';
19+
const debugSEPContext = 'code-for-ibmi:debug.SEP';
20+
1821
// These context values are used for walkthroughs only
1922
const ptfContext = `code-for-ibmi:debug.ptf`;
2023
const remoteCertContext = `code-for-ibmi:debug.remote`;
@@ -203,12 +206,7 @@ export async function initialize(context: ExtensionContext) {
203206
}
204207

205208
return password;
206-
}
207-
208-
const debugPTFInstalled = () => {
209-
const connection = instance.getConnection();
210-
return connection?.remoteFeatures[`startDebugService.sh`] !== undefined;
211-
}
209+
}
212210

213211
context.subscriptions.push(
214212
vscode.commands.registerCommand(`code-for-ibmi.debug.extension`, () => {
@@ -271,7 +269,7 @@ export async function initialize(context: ExtensionContext) {
271269
vscode.commands.registerCommand(`code-for-ibmi.debug.setup.remote`, async () => {
272270
const connection = instance.getConnection();
273271
if (connection) {
274-
const ptfInstalled = debugPTFInstalled();
272+
const ptfInstalled = server.debugPTFInstalled();
275273

276274
if (ptfInstalled) {
277275
const remoteCertExists = await certificates.remoteServerCertificateExists(connection);
@@ -320,7 +318,7 @@ export async function initialize(context: ExtensionContext) {
320318
const connection = instance.getConnection();
321319

322320
if (connection) {
323-
const ptfInstalled = debugPTFInstalled();
321+
const ptfInstalled = server.debugPTFInstalled();
324322

325323
if (ptfInstalled) {
326324
let localCertsOk = false;
@@ -381,7 +379,7 @@ export async function initialize(context: ExtensionContext) {
381379
vscode.commands.registerCommand(`code-for-ibmi.debug.start`, async () => {
382380
const connection = instance.getConnection();
383381
if (connection) {
384-
const ptfInstalled = debugPTFInstalled();
382+
const ptfInstalled = server.debugPTFInstalled();
385383
if (ptfInstalled) {
386384
const remoteExists = await certificates.remoteServerCertificateExists(connection);
387385
if (remoteExists) {
@@ -425,7 +423,7 @@ export async function initialize(context: ExtensionContext) {
425423
vscode.commands.registerCommand(`code-for-ibmi.debug.stop`, async () => {
426424
const connection = instance.getConnection();
427425
if (connection) {
428-
const ptfInstalled = debugPTFInstalled();
426+
const ptfInstalled = server.debugPTFInstalled();
429427
if (ptfInstalled) {
430428
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
431429
progress.report({ message: `Ending Debug Service` });
@@ -444,9 +442,15 @@ export async function initialize(context: ExtensionContext) {
444442
server.resetDebugServiceDetails()
445443
const connection = instance.getConnection();
446444
const content = instance.getContent();
447-
if (connection && content && debugPTFInstalled()) {
445+
if (connection && content && server.debugPTFInstalled()) {
448446
vscode.commands.executeCommand(`setContext`, ptfContext, true);
449447

448+
//Enable debug related commands
449+
vscode.commands.executeCommand(`setContext`, debugContext, true);
450+
451+
//Enable service entry points related commands
452+
vscode.commands.executeCommand(`setContext`, debugSEPContext, await server.isSEPSupported());
453+
450454
if (!isManaged()) {
451455
const isSecure = connection.config!.debugIsSecure;
452456

@@ -486,6 +490,11 @@ export async function initialize(context: ExtensionContext) {
486490
}
487491
});
488492

493+
instance.onEvent("disconnected", () => {
494+
vscode.commands.executeCommand(`setContext`, debugContext, false);
495+
vscode.commands.executeCommand(`setContext`, debugSEPContext, false);
496+
});
497+
489498
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:debugManaged`, isManaged());
490499
}
491500

src/api/debug/server.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ const JavaPaths: { [version: string]: string } = {
1717
}
1818

1919
interface DebugServiceDetails {
20-
version: string;
21-
java: string;
20+
version: string
21+
java: string
22+
semanticVersion: () => {
23+
major: number
24+
minor: number
25+
patch: number
26+
}
2227
}
2328

2429

@@ -40,23 +45,47 @@ export async function getDebugServiceDetails(): Promise<DebugServiceDetails> {
4045

4146
debugServiceDetails = {
4247
version: `1.0.0`,
43-
java: `8`
48+
java: `8`,
49+
semanticVersion: () => ({
50+
major: 1,
51+
minor: 0,
52+
patch: 0
53+
})
4454
};
4555

4656
const detailFilePath = path.posix.join(directory, detailFile);
4757
const detailExists = await content.testStreamFile(detailFile, "r");
4858
if (detailExists) {
4959
try {
5060
const fileContents = (await content.downloadStreamfileRaw(detailFilePath)).toString("utf-8");
51-
debugServiceDetails = JSON.parse(fileContents);
61+
const parsed = JSON.parse(fileContents);
62+
debugServiceDetails = {
63+
...parsed as DebugServiceDetails,
64+
semanticVersion: () => {
65+
const parts = (parsed.version ? String(parsed.version).split('.') : []).map(Number);
66+
return {
67+
major: parts[0],
68+
minor: parts[1],
69+
patch: parts[2]
70+
};
71+
}
72+
}
5273
} catch (e) {
5374
// Something very very bad has happened
5475
window.showErrorMessage(t('detail.reading.error', detailFilePath, e));
5576
console.log(e);
5677
}
5778
}
5879

59-
return debugServiceDetails!;
80+
return debugServiceDetails;
81+
}
82+
83+
export function debugPTFInstalled() {
84+
return instance.getConnection()?.remoteFeatures[`startDebugService.sh`] !== undefined;
85+
}
86+
87+
export async function isSEPSupported(){
88+
return (await getDebugServiceDetails()).semanticVersion().major > 1;
6089
}
6190

6291
export async function startService(connection: IBMi) {

src/instantiate.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ConnectionConfiguration, DefaultOpenMode, GlobalConfiguration, onCodeFo
77
import Instance from "./api/Instance";
88
import { Search } from "./api/Search";
99
import { Terminal } from './api/Terminal';
10-
import { getDebugServiceDetails, isDebugEngineRunning } from './api/debug/server';
10+
import { debugPTFInstalled, getDebugServiceDetails, isDebugEngineRunning } from './api/debug/server';
1111
import { refreshDiagnosticsFromServer } from './api/errors/diagnostics';
1212
import { setupGitEventHandler } from './api/local/git';
1313
import { QSysFS, getUriFromPath, parseFSOptions } from "./filesystems/qsys/QSysFs";
@@ -745,7 +745,10 @@ async function updateConnectedBar() {
745745
`[$(settings-gear) Settings](command:code-for-ibmi.showAdditionalSettings)`,
746746
`[$(file-binary) Actions](command:code-for-ibmi.showActionsMaintenance)`,
747747
`[$(terminal) Terminals](command:code-for-ibmi.launchTerminalPicker)`,
748-
`[$(${debugRunning ? "bug" : "debug"}) Debugger ${((await getDebugServiceDetails()).version)} (${debugRunning ? "on" : "off"})](command:code-for-ibmi.openDebugStatus)`,
748+
debugPTFInstalled() ?
749+
`[$(${debugRunning ? "bug" : "debug"}) Debugger ${((await getDebugServiceDetails()).version)} (${debugRunning ? "on" : "off"})](command:code-for-ibmi.openDebugStatus)`
750+
:
751+
`[$(debug) No debug PTF](https://codefori.github.io/docs/developing/debug/#required-ptfs)`
749752
].join(`\n\n---\n\n`), true);
750753
connectedBarItem.tooltip.isTrusted = true;
751754
}

src/webviews/settings/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { GlobalStorage } from '../../api/Storage';
55
import { Tools } from "../../api/Tools";
66
import { isManaged } from "../../api/debug";
77
import * as certificates from "../../api/debug/certificates";
8+
import { isSEPSupported } from "../../api/debug/server";
89
import { instance } from "../../instantiate";
9-
import { ConnectionData, Server } from '../../typings';
1010
import { t } from "../../locale";
11+
import { ConnectionData, Server } from '../../typings';
1112

1213
const ENCODINGS = [`37`, `256`, `273`, `277`, `278`, `280`, `284`, `285`, `297`, `500`, `871`, `870`, `905`, `880`, `420`, `875`, `424`, `1026`, `290`, `win37`, `win256`, `win273`, `win277`, `win278`, `win280`, `win284`, `win285`, `win297`, `win500`, `win871`, `win870`, `win905`, `win880`, `win420`, `win875`, `win424`, `win1026`];
1314

@@ -175,9 +176,13 @@ export class SettingsUI {
175176
const debuggerTab = new Section();
176177
if (connection && connection.remoteFeatures[`startDebugService.sh`]) {
177178
debuggerTab
178-
.addInput(`debugPort`, `Debug port`, `Default secure port is <code>8005</code>. Tells the client which port the debug service is running on.`, { default: config.debugPort, minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
179-
.addInput(`debugSepPort`, `SEP debug port`, `Default secure port is <code>8008</code>. Tells the client which port the debug service for SEP is running on.`, { default: config.debugSepPort, minlength: 1, maxlength: 5, regexTest: `^\\d+$` })
180-
.addCheckbox(`debugUpdateProductionFiles`, `Update production files`, `Determines whether the job being debugged can update objects in production (<code>*PROD</code>) libraries.`, config.debugUpdateProductionFiles)
179+
.addInput(`debugPort`, `Debug port`, `Default secure port is <code>8005</code>. Tells the client which port the debug service is running on.`, { default: config.debugPort, minlength: 1, maxlength: 5, regexTest: `^\\d+$` });
180+
181+
if (await isSEPSupported()) {
182+
debuggerTab.addInput(`debugSepPort`, `SEP debug port`, `Default secure port is <code>8008</code>. Tells the client which port the debug service for SEP is running on.`, { default: config.debugSepPort, minlength: 1, maxlength: 5, regexTest: `^\\d+$` });
183+
}
184+
185+
debuggerTab.addCheckbox(`debugUpdateProductionFiles`, `Update production files`, `Determines whether the job being debugged can update objects in production (<code>*PROD</code>) libraries.`, config.debugUpdateProductionFiles)
181186
.addCheckbox(`debugEnableDebugTracing`, `Debug trace`, `Tells the debug service to send more data to the client. Only useful for debugging issues in the service. Not recommended for general debugging.`, config.debugEnableDebugTracing);
182187

183188
if (!isManaged()) {

0 commit comments

Comments
 (0)