From fcc3b39337f41723a06e54cac510b53e8c595317 Mon Sep 17 00:00:00 2001 From: mho22 Date: Fri, 25 Jul 2025 11:31:30 +0200 Subject: [PATCH 1/2] Add a excludedPaths option in start bridge --- .../xdebug-bridge/src/lib/start-bridge.ts | 2 + .../src/lib/xdebug-cdp-bridge.ts | 65 ++++++++++++------- packages/playground/cli/src/run-cli.ts | 1 + 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts b/packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts index c042356534..6927f97014 100644 --- a/packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts +++ b/packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts @@ -12,6 +12,7 @@ export type StartBridgeConfig = { phpRoot?: string; remoteRoot?: string; localRoot?: string; + excludedPaths?: string[]; phpInstance?: PHP; getPHPFile?: (path: string) => Promise; @@ -80,5 +81,6 @@ export async function startBridge(config: StartBridgeConfig) { remoteRoot: config.remoteRoot, localRoot: config.localRoot, getPHPFile, + excludedPaths: config.excludedPaths, }); } diff --git a/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts b/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts index 5eed4e5816..b6df10ca33 100644 --- a/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts +++ b/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts @@ -28,6 +28,7 @@ export interface XdebugCDPBridgeConfig { knownScriptUrls: string[]; remoteRoot?: string; localRoot?: string; + excludedPaths?: string[]; getPHPFile(path: string): Promise; } @@ -48,6 +49,7 @@ export class XdebugCDPBridge { private readPHPFile: (path: string) => Promise; private remoteRoot: string; private localRoot: string; + private excludedPaths: string[]; constructor( dbgp: DbgpSession, @@ -59,6 +61,7 @@ export class XdebugCDPBridge { this.readPHPFile = config.getPHPFile; this.remoteRoot = config.remoteRoot || ''; this.localRoot = config.localRoot || ''; + this.excludedPaths = config.excludedPaths || []; for (const url of config.knownScriptUrls) { this.scriptIdByUrl.set(url, this.getOrCreateScriptId(url)); } @@ -138,7 +141,11 @@ export class XdebugCDPBridge { private sendInitialScripts() { // Send scriptParsed for the main file if not already sent - if (this.initFileUri && !this.scriptIdByUrl.has(this.initFileUri)) { + if ( + this.initFileUri && + !this.scriptIdByUrl.has(this.initFileUri) && + !this.isExcludedPath(this.initFileUri) + ) { const scriptId = this.getOrCreateScriptId(this.initFileUri); this.cdp.sendMessage({ method: 'Debugger.scriptParsed', @@ -155,19 +162,27 @@ export class XdebugCDPBridge { // Send every script we already know about for (const [url, scriptId] of this.scriptIdByUrl.entries()) { - this.cdp.sendMessage({ - method: 'Debugger.scriptParsed', - params: { - scriptId, - url, - startLine: 0, - startColumn: 0, - executionContextId: 1, - }, - }); + if (!this.isExcludedPath(url)) { + this.cdp.sendMessage({ + method: 'Debugger.scriptParsed', + params: { + scriptId, + url, + startLine: 0, + startColumn: 0, + executionContextId: 1, + }, + }); + } } } + private isExcludedPath(fileUri: string): boolean { + return this.excludedPaths.some((prefix) => + this.uriToRemotePath(fileUri).startsWith(prefix) + ); + } + private getOrCreateScriptId(fileUri: string): string { let scriptId = this.scriptIdByUrl.get(fileUri); if (!scriptId) { @@ -544,17 +559,23 @@ export class XdebugCDPBridge { if (response['xdebug:message']) { const fileUri = response['xdebug:message'].$.filename; if (fileUri && !this.scriptIdByUrl.has(fileUri)) { - const scriptId = this.getOrCreateScriptId(fileUri); - this.cdp.sendMessage({ - method: 'Debugger.scriptParsed', - params: { - scriptId, - url: fileUri, - startLine: 0, - startColumn: 0, - executionContextId: 1, - }, - }); + if (this.isExcludedPath(fileUri)) { + this.sendDbgpCommand('step_over'); + break; + } else { + const scriptId = + this.getOrCreateScriptId(fileUri); + this.cdp.sendMessage({ + method: 'Debugger.scriptParsed', + params: { + scriptId, + url: fileUri, + startLine: 0, + startColumn: 0, + executionContextId: 1, + }, + }); + } } } if (status === 'break') { diff --git a/packages/playground/cli/src/run-cli.ts b/packages/playground/cli/src/run-cli.ts index 10e4efb32c..12f94817fc 100644 --- a/packages/playground/cli/src/run-cli.ts +++ b/packages/playground/cli/src/run-cli.ts @@ -546,6 +546,7 @@ export async function runCLI(args: RunCLIArgs): Promise { const bridge = await startBridge({ getPHPFile: async (path: string) => await playground!.readFileAsText(path), + excludedPaths: ['/internal'], }); bridge.start(); From 71d2a2ea0773656fd1dfa0a0dd667a2798d95f6a Mon Sep 17 00:00:00 2001 From: mho22 Date: Fri, 25 Jul 2025 11:47:24 +0200 Subject: [PATCH 2/2] Typecheck --- packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts b/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts index 7f16840b95..83f27c885e 100644 --- a/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts +++ b/packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts @@ -29,7 +29,7 @@ export interface XdebugCDPBridgeConfig { remoteRoot?: string; localRoot?: string; excludedPaths?: string[]; - getPHPFile(path: string): Promise; + getPHPFile(path: string): string | Promise; } export class XdebugCDPBridge {