Skip to content

Commit 5ca50f3

Browse files
authored
Support command stepping in debugger (#1385)
1 parent e770ec8 commit 5ca50f3

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,19 @@
16041604
],
16051605
"default": "//",
16061606
"scope": "machine"
1607+
},
1608+
"objectscript.debug.stepGranularity": {
1609+
"markdownDescription": "Controls the granularity of the debugger's [step action buttons](https://code.visualstudio.com/docs/editor/debugging#_debug-actions). Changing this setting while a debugging session is active will not change the behavior of the active session. **NOTE:** Only supported on IRIS 2023.1.5, 2024.1.1+, 2024.2 and subsequent versions! On all other versions, line stepping will be used.",
1610+
"type": "string",
1611+
"enum": [
1612+
"command",
1613+
"line"
1614+
],
1615+
"enumDescriptions": [
1616+
"The step buttons execute a single command.",
1617+
"The step buttons execute an entire line."
1618+
],
1619+
"default": "command"
16071620
}
16081621
}
16091622
},

src/debug/debugSession.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
205205
await this._connection.sendFeatureSetCommand("max_children", 32);
206206
await this._connection.sendFeatureSetCommand("max_depth", 2);
207207
await this._connection.sendFeatureSetCommand("notify_ok", 1);
208+
await this._connection.sendFeatureSetCommand(
209+
"step_granularity",
210+
vscode.workspace.getConfiguration("objectscript.debug").get<string>("stepGranularity")
211+
);
208212

209213
this.sendResponse(response);
210214

@@ -599,6 +603,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
599603
const place = `${stackFrame.method}+${stackFrame.methodOffset}`;
600604
const stackFrameId = this._stackFrameIdCounter++;
601605
const fileText: string | undefined = await getFileText(fileUri).catch(() => undefined);
606+
const hasCmdLoc = typeof stackFrame.cmdBeginLine == "number";
602607
if (fileText == undefined) {
603608
// Can't get the source for the document
604609
this._stackFrames.set(stackFrameId, stackFrame);
@@ -611,7 +616,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
611616
presentationHint: "deemphasize",
612617
},
613618
line,
614-
column: 1,
619+
column: 0,
615620
};
616621
}
617622
let noSource = false;
@@ -656,12 +661,20 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
656661
} catch (ex) {
657662
noSource = true;
658663
}
664+
const lineDiff = line - stackFrame.line;
659665
return {
660666
id: stackFrameId,
661667
name: place,
662668
source: noSource ? null : source,
663669
line,
664-
column: 1,
670+
column: hasCmdLoc ? stackFrame.cmdBeginPos + 1 : 0,
671+
endLine: hasCmdLoc ? stackFrame.cmdEndLine + lineDiff : undefined,
672+
endColumn: hasCmdLoc
673+
? (stackFrame.cmdEndPos == 0
674+
? // A command that ends at position zero means "rest of this line"
675+
fileText.split(/\r?\n/)[stackFrame.cmdEndLine + lineDiff - 1].length
676+
: stackFrame.cmdEndPos) + 1
677+
: undefined,
665678
};
666679
})
667680
);

src/debug/xdebugConnection.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ export class StackFrame {
391391
public line: number;
392392
/** The line number inside of method of class */
393393
public methodOffset: number;
394+
/** The start line number of the current command */
395+
public cmdBeginLine?: number;
396+
/** The start position of the current command within the line */
397+
public cmdBeginPos?: number;
398+
/** The end line number of the current command */
399+
public cmdEndLine?: number;
400+
/** The end position of the current command within the line */
401+
public cmdEndPos?: number;
394402
/** The level (index) inside the stack trace at which the stack frame receides */
395403
public level: number;
396404
/** The connection this stackframe belongs to */
@@ -406,6 +414,16 @@ export class StackFrame {
406414
this.line = parseInt(stackFrameNode.getAttribute("lineno"), 10);
407415
this.methodOffset = parseInt(stackFrameNode.getAttribute("methodoffset"), 10);
408416
this.level = parseInt(stackFrameNode.getAttribute("level"), 10);
417+
const cmdBegin = stackFrameNode.getAttribute("cmdbegin");
418+
const cmdEnd = stackFrameNode.getAttribute("cmdend");
419+
if (cmdBegin && cmdEnd) {
420+
const [cmdBeginLine, cmdBeginPos] = cmdBegin.split(":");
421+
const [cmdEndLine, cmdEndPos] = cmdEnd.split(":");
422+
this.cmdBeginLine = parseInt(cmdBeginLine, 10);
423+
this.cmdBeginPos = parseInt(cmdBeginPos, 10);
424+
this.cmdEndLine = parseInt(cmdEndLine, 10);
425+
this.cmdEndPos = parseInt(cmdEndPos, 10);
426+
}
409427
this.connection = connection;
410428
}
411429
/** Returns the available contexts (scopes, such as "Local" and "Superglobals") by doing a context_names command */

0 commit comments

Comments
 (0)