Skip to content

Commit

Permalink
Simplify slice logic, add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed Mar 2, 2022
1 parent 3f7ac61 commit 6c21194
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,7 @@ class PhpDebugSession extends vscode.DebugSession {
response.body = { stackFrames: [{ id, name, source, line, column: 1 }] }
} else {
const totalFrames = stack.length
if (args.levels !== undefined && args.levels > 0) {
stack = stack.filter(
stackFrame =>
stackFrame.level >= (args.startFrame ?? 0) &&
stackFrame.level < (args.startFrame ?? 0) + args.levels!
)
}
stack = stack.slice(args.startFrame, args.levels ? (args.startFrame ?? 0) + args.levels : undefined)
response.body = {
totalFrames,
stackFrames: stack.map((stackFrame): VSCodeDebugProtocol.StackFrame => {
Expand Down
19 changes: 19 additions & 0 deletions src/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,5 +817,24 @@ describe('PHP Debug Adapter', () => {
s1.end()
})
})
it('stack depth', async () => {
const program = path.join(TEST_PROJECT, 'stack.php')

await Promise.all([client.launch({ program }), client.configurationSequence()])
const event = (await client.waitForEvent('stopped')) as DebugProtocol.StoppedEvent
assert.propertyVal(event.body, 'reason', 'breakpoint')
const threadId = event.body.threadId!

const response = await client.stackTraceRequest({ threadId, levels: 1 })
assert.lengthOf(response.body.stackFrames, 1)
assert.equal(response.body.totalFrames, 4)
assert.equal(response.body.stackFrames[0].name, 'depth3')
const response2 = await client.stackTraceRequest({ threadId, startFrame: 1 /*, levels: 3*/ })
assert.lengthOf(response2.body.stackFrames, 3)
assert.equal(response2.body.totalFrames, 4)
assert.equal(response2.body.stackFrames[0].name, 'depth2')
assert.equal(response2.body.stackFrames[1].name, 'depth1')
assert.equal(response2.body.stackFrames[2].name, '{main}')
})
})
})
17 changes: 17 additions & 0 deletions testproject/stack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

// Test stack depth.

function depth1() {
depth2();
}

function depth2() {
depth3();
}

function depth3() {
xdebug_break();
}

depth1();

0 comments on commit 6c21194

Please sign in to comment.