Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fec8f3c

Browse files
authored
feat: Add skipEntryPaths to immediately detach a debug session depending on entry path (#911)
* feat: Add skipEntryPaths to immediately detach a debug session depending on entry file * Document skipEntryPaths. * Handle invalid init packet. * Test case for skip entry paths and fix for old max conn test.
1 parent 1d76e1f commit fec8f3c

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ More general information on debugging with VS Code can be found on https://code.
7878
- `ignore`: An optional array of glob patterns that errors should be ignored from (for example `**/vendor/**/*.php`)
7979
- `ignoreExceptions`: An optional array of exception class names that should be ignored (for example `BaseException`, `\NS1\Exception`, `\*\Exception` or `\**\Exception*`)
8080
- `skipFiles`: An array of glob patterns, to skip when debugging. Star patterns and negations are allowed, for example, `**/vendor/**` or `!**/vendor/my-module/**`.
81+
- `skipEntryPaths`: An array of glob patterns, to immediately detach from and ignore for debugging if the entry script matches (example `**/ajax.php`).
8182
- `maxConnections`: Accept only this number of parallel debugging sessions. Additional connections will be dropped and their execution will continue without debugging.
8283
- `proxy`: DBGp Proxy settings
8384
- `enable`: To enable proxy registration set to `true` (default is `false).

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@
283283
"items": "string",
284284
"description": "An array of exception class names that should be ignored."
285285
},
286+
"skipEntryPaths": {
287+
"type": "array",
288+
"items": "string",
289+
"description": "An array of glob pattern to skip if the initial entry file is matched."
290+
},
286291
"log": {
287292
"type": "boolean",
288293
"description": "If true, will log all communication between VS Code and the adapter"

src/phpDebug.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ export interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchReques
7979
ignore?: string[]
8080
/** Array of glob patterns that exceptions should be ignored from */
8181
ignoreExceptions?: string[]
82+
/** An array of glob pattern to skip if the initial entry file is matched. */
83+
skipEntryPaths?: string[]
8284
/** Array of glob patterns that debugger should not step in */
8385
skipFiles?: string[]
8486
/** Xdebug configuration */
@@ -487,6 +489,26 @@ class PhpDebugSession extends vscode.DebugSession {
487489
private async initializeConnection(connection: xdebug.Connection): Promise<void> {
488490
const initPacket = await connection.waitForInitPacket()
489491

492+
// check if this connection should be skipped
493+
if (
494+
this._args.skipEntryPaths &&
495+
isPositiveMatchInGlobs(
496+
convertDebuggerPathToClient(initPacket.fileUri).replace(/\\/g, '/'),
497+
this._args.skipEntryPaths
498+
)
499+
) {
500+
this.sendEvent(
501+
new vscode.OutputEvent(
502+
`skipping entry point ${convertDebuggerPathToClient(initPacket.fileUri).replace(
503+
/\\/g,
504+
'/'
505+
)} on connection ${connection.id}\n`
506+
)
507+
)
508+
this.disposeConnection(connection)
509+
return
510+
}
511+
490512
// support for breakpoints
491513
let feat: xdebug.FeatureGetResponse
492514
const supportedEngine =

src/test/adapter.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,12 @@ describe('PHP Debug Adapter', () => {
827827
await Promise.all([client.launch({ maxConnections: 1, log: true }), client.configurationSequence()])
828828

829829
const s1 = net.createConnection({ port: 9003 })
830-
await client.assertOutput('console', 'new connection 1 from ')
830+
const o1 = await client.assertOutput('console', 'new connection')
831+
assert.match(
832+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
833+
o1.body.output as string,
834+
/^new connection \d+ from/
835+
)
831836
net.createConnection({ port: 9003 })
832837
const o = await client.waitForEvent('output')
833838
assert.match(
@@ -860,5 +865,14 @@ describe('PHP Debug Adapter', () => {
860865
assert.equal(response2.body.stackFrames[1].name, 'depth1')
861866
assert.equal(response2.body.stackFrames[2].name, '{main}')
862867
})
868+
it('skip entry paths', async () => {
869+
const program = path.join(TEST_PROJECT, 'variables.php')
870+
871+
await client.launch({ program, skipEntryPaths: ['**/variables.php'] })
872+
await client.setBreakpointsRequest({ source: { path: program }, breakpoints: [{ line: 19 }] })
873+
await client.configurationDoneRequest()
874+
875+
await client.assertOutput('console', 'skipping entry point')
876+
})
863877
})
864878
})

src/xdebugConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class InitPacket {
2828
this.language = documentElement.getAttribute('language')!
2929
this.protocolVersion = documentElement.getAttribute('protocol_version')!
3030
this.ideKey = documentElement.getAttribute('idekey')!
31-
this.engineVersion = documentElement.getElementsByTagName('engine')[0].getAttribute('version')!
32-
this.engineName = documentElement.getElementsByTagName('engine')[0].textContent ?? ''
31+
this.engineVersion = documentElement.getElementsByTagName('engine').item(0)?.getAttribute('version') ?? ''
32+
this.engineName = documentElement.getElementsByTagName('engine').item(0)?.textContent ?? ''
3333
this.connection = connection
3434
}
3535
}

0 commit comments

Comments
 (0)