Skip to content

[Xdebug Bridge] Correct error related to unresolved promises in bridge #2422

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

Merged
merged 5 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 10 additions & 14 deletions packages/php-wasm/xdebug-bridge/src/lib/start-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type StartBridgeConfig = {
localRoot?: string;

phpInstance?: PHP;
getPHPFile?: (path: string) => Promise<string>;
getPHPFile?: (path: string) => string | Promise<string>;
};

export async function startBridge(config: StartBridgeConfig) {
Expand Down Expand Up @@ -58,21 +58,17 @@ export async function startBridge(config: StartBridgeConfig) {
}

const getPHPFile = config.phpInstance
? (path: string) =>
new Promise<string>(() =>
config.phpInstance!.readFileAsText(path)
)
? (path: string) => config.phpInstance!.readFileAsText(path)
: config.getPHPFile
? config.getPHPFile
: (path: string) =>
new Promise<string>(() => {
// Default implementation: read from filesystem
// Convert file:/// URLs to local paths
const localPath = path.startsWith('file://')
? path.replace('file://', '')
: path;
return readFileSync(localPath, 'utf-8');
});
: (path: string) => {
// Default implementation: read from filesystem
// Convert file:/// URLs to local paths
const localPath = path.startsWith('file://')
? path.replace('file://', '')
: path;
return readFileSync(localPath, 'utf-8');
};

const phpFiles = getPhpFiles(phpRoot);
return new XdebugCDPBridge(dbgpSession, cdpServer, {
Expand Down
4 changes: 2 additions & 2 deletions packages/php-wasm/xdebug-bridge/src/lib/xdebug-cdp-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface XdebugCDPBridgeConfig {
knownScriptUrls: string[];
remoteRoot?: string;
localRoot?: string;
getPHPFile(path: string): Promise<string>;
getPHPFile(path: string): string | Promise<string>;
}

export class XdebugCDPBridge {
Expand All @@ -45,7 +45,7 @@ export class XdebugCDPBridge {
private xdebugConnected = false;
private xdebugStatus = 'starting';
private initFileUri: string | null = null;
private readPHPFile: (path: string) => Promise<string>;
private readPHPFile: (path: string) => string | Promise<string>;
private remoteRoot: string;
private localRoot: string;

Expand Down
Loading