Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug action on programs in Object Browser #1421

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,12 @@
"icon": "$(debug-alt)",
"enablement": "code-for-ibmi:connected"
},
{
"command": "code-for-ibmi.debug.program",
"title": "Debug Program",
"category": "IBM i",
"enablement": "code-for-ibmi:connected"
},
{
"command": "code-for-ibmi.debug.endDebug",
"title": "Stop Debugging",
Expand Down Expand Up @@ -1974,6 +1980,11 @@
"when": "view == objectBrowser && viewItem =~ /^member.*$/",
"group": "1_workspace@1"
},
{
"command": "code-for-ibmi.debug.program",
"when": "view == objectBrowser && viewItem =~ /^object.pgm.*/",
SanjulaGanepola marked this conversation as resolved.
Show resolved Hide resolved
"group": "2_debug@1"
},
{
"command": "code-for-ibmi.updateMemberText",
"when": "view == objectBrowser && viewItem == member",
Expand Down
87 changes: 48 additions & 39 deletions src/api/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,40 @@ export async function initialize(context: ExtensionContext) {
return debugclient !== undefined;
}

const startDebugging = (options: DebugOptions) => {
startDebug(instance, options);
const startDebugging = async (library: string, object: string) => {
if (debugExtensionAvailable()) {
const connection = instance.getConnection();
if (connection) {
if (connection.remoteFeatures[`startDebugService.sh`]) {
const password = await getPassword();

if (password) {
const debugOpts: DebugOptions = {
password,
library: library,
object: object
};

startDebug(instance, debugOpts);
}
} else {
const openTut = await vscode.window.showInformationMessage(`Looks like you do not have the debug PTF installed. Do you want to see the Walkthrough to set it up?`, `Take me there`);
if (openTut === `Take me there`) {
vscode.commands.executeCommand(`workbench.action.openWalkthrough`, `halcyontechltd.vscode-ibmi-walkthroughs#code-ibmi-debug`);
}
}
}

} else {
vscode.window.showInformationMessage(`Debug extension missing`, {
detail: `The IBM i Debug extension is not installed. It can be installed from the Marketplace.`,
modal: true
}, `Go to Marketplace`).then(result => {
if (result === `Go to Marketplace`) {
vscode.commands.executeCommand('code-for-ibmi.debug.extension');
}
});
}
}

const getObjectFromUri = (uri: Uri) => {
Expand Down Expand Up @@ -119,43 +151,20 @@ export async function initialize(context: ExtensionContext) {
}),

vscode.commands.registerCommand(`code-for-ibmi.debug.activeEditor`, async () => {
if (debugExtensionAvailable()) {
const connection = instance.getConnection();
if (connection) {
if (connection.remoteFeatures[`startDebugService.sh`]) {
const activeEditor = vscode.window.activeTextEditor;

if (activeEditor) {
const qualifiedObject = getObjectFromUri(activeEditor.document.uri);
const password = await getPassword();

if (password && qualifiedObject.library && qualifiedObject.object) {
const debugOpts: DebugOptions = {
password,
library: qualifiedObject.library,
object: qualifiedObject.object
};

startDebugging(debugOpts);
}
}
} else {
const openTut = await vscode.window.showInformationMessage(`Looks like you do not have the debug PTF installed. Do you want to see the Walkthrough to set it up?`, `Take me there`);
if (openTut === `Take me there`) {
vscode.commands.executeCommand(`workbench.action.openWalkthrough`, `halcyontechltd.vscode-ibmi-walkthroughs#code-ibmi-debug`);
}
}
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
const qualifiedObject = getObjectFromUri(activeEditor.document.uri);

if (qualifiedObject.library && qualifiedObject.object) {
startDebugging(qualifiedObject.library, qualifiedObject.object);
}
}
}),

} else {
vscode.window.showInformationMessage(`Debug extension missing`, {
detail: `The IBM i Debug extension is not installed. It can be installed from the Marketplace.`,
modal: true
}, `Go to Marketplace`).then(result => {
if (result === `Go to Marketplace`) {
vscode.commands.executeCommand('code-for-ibmi.debug.extension');
}
});
vscode.commands.registerCommand(`code-for-ibmi.debug.program`, async (node) => {
const [library, object] = node.path.split(`/`);
if (library && object) {
startDebugging(library, object);
}
}),

Expand Down Expand Up @@ -320,8 +329,8 @@ export async function initialize(context: ExtensionContext) {
if (connection) {
const ptfInstalled = debugPTFInstalled();
if (ptfInstalled) {
vscode.window.withProgress({location: vscode.ProgressLocation.Notification}, async (progress) => {
progress.report({message: `Ending Debug Service`});
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
progress.report({ message: `Ending Debug Service` });
await server.stop(connection);
});
}
Expand Down