Skip to content

Commit 5c8e1bc

Browse files
committed
Fix sourceRequest / eval code
1 parent db1a361 commit 5c8e1bc

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/phpDebug.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,15 @@ class PhpDebugSession extends vscode.DebugSession {
376376
response.body = {
377377
stackFrames: xdebugResponse.stack.map(stackFrame => {
378378
let source: vscode.Source;
379+
let line = stackFrame.line;
379380
const urlObject = url.parse(stackFrame.fileUri);
380381
if (urlObject.protocol === 'dbgp:') {
381382
const sourceReference = this._sourceIdCounter++;
382383
this._sources.set(sourceReference, {connection, url: stackFrame.fileUri});
383-
source = new vscode.Source(stackFrame.name, stackFrame.fileUri.substr('dbgp://'.length), sourceReference, stackFrame.type);
384+
// for eval code, we need to include .php extension to get syntax highlighting
385+
source = new vscode.Source(stackFrame.type === 'eval' ? 'eval.php' : stackFrame.name, null, sourceReference, stackFrame.type);
386+
// for eval code, we add a "<?php" line at the beginning to get syntax highlighting (see sourceRequest)
387+
line++;
384388
} else {
385389
// XDebug paths are URIs, VS Code file paths
386390
const filePath = this.convertDebuggerPathToClient(urlObject);
@@ -392,7 +396,7 @@ class PhpDebugSession extends vscode.DebugSession {
392396
// save the connection this stackframe belongs to and the level of the stackframe under the stacktrace id
393397
this._stackFrames.set(stackFrameId, stackFrame);
394398
// prepare response for VS Code (column is always 1 since XDebug doesn't tell us the column)
395-
return new vscode.StackFrame(stackFrameId, stackFrame.name, source, stackFrame.line, 1);
399+
return new vscode.StackFrame(stackFrameId, stackFrame.name, source, line, 1);
396400
})
397401
}
398402
this.sendResponse(response);
@@ -405,10 +409,15 @@ class PhpDebugSession extends vscode.DebugSession {
405409
protected sourceRequest(response: VSCodeDebugProtocol.SourceResponse, args: VSCodeDebugProtocol.SourceArguments): void {
406410
const {connection, url} = this._sources.get(args.sourceReference);
407411
connection.sendSourceCommand(url).then(xdebugResponse => {
408-
response.body.content = xdebugResponse.source;
412+
let content = xdebugResponse.source;
413+
if (!/^\s*<\?(php|=)/.test(content)) {
414+
// we do this because otherwise VS Code would not show syntax highlighting for eval() code
415+
content = '<?php\n' + content;
416+
}
417+
response.body = {content};
409418
this.sendResponse(response);
410419
});
411-
}
420+
}
412421

413422
protected scopesRequest(response: VSCodeDebugProtocol.ScopesResponse, args: VSCodeDebugProtocol.ScopesArguments): void {
414423
const stackFrame = this._stackFrames.get(args.frameId);

src/xdebugConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export class SourceResponse extends Response {
299299
source: string;
300300
constructor(document: XMLDocument, connection: Connection) {
301301
super(document, connection);
302-
this.source = document.documentElement.textContent;
302+
this.source = (new Buffer(document.documentElement.textContent, 'base64')).toString();
303303
}
304304
}
305305

0 commit comments

Comments
 (0)