Skip to content

Commit 01e2673

Browse files
committed
Add new log setting, add troubleshooting section to readme
The new settings allows to log all communication between the adapter and VS Code to the debug console without having the extension run in server mode.
1 parent 7168f8b commit 01e2673

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Example:
5858
Both paths are normalized, so you can use slashes or backslashes no matter of the OS you're running.
5959
If no `localSourceRoot` is specified, the project root is assumed.
6060

61+
Troubleshooting
62+
---------------
63+
When you are facing problems, please don't send me private emails, instead ask on
64+
[Gitter](https://gitter.im/felixfbecker/vscode-php-debug) or if you think there is a bug in the adapter, [open an issue](https://github.com/felixfbecker/vscode-php-debug/issues).
65+
If it fails with your ultra-awesome MVC app, please first try it on a dead-simple test.php (like the one in the [testproject](https://github.com/felixfbecker/vscode-php-debug/tree/master/testproject)). Please provide some info by setting `xdebug.remote_log = /path/to/logfile` in your php.ini (you will need to restart your webserver), `"log": true` in your launch.json and posting the two logs.
66+
6167
FAQ
6268
---
6369

@@ -81,7 +87,7 @@ PS C:\Users\felix\github\vscode-php-debug> code .\testproject\ --extensionDevelo
8187
```
8288

8389
VS Code will open an "Extension Development Host" with the debug adapter running. Open `.vscode/launch.json` and
84-
uncomment the `debugServer` configuration line. Hit `F5` to start a debugging session.
90+
uncomment the `debugServer` configuration line. Hit `F5` to start a debugging session.
8591
Now, you can debug the testproject like specified above and set breakpoints inside your first VS Code instance to step through the adapter code.
8692

8793
[![Gitter](https://badges.gitter.im/felixfbecker/vscode-php-debug.svg)](https://gitter.im/felixfbecker/vscode-php-debug?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
"cwd": {
8989
"type": "string",
9090
"description": "The current working directory, by default the project root"
91+
},
92+
"log": {
93+
"type": "boolean",
94+
"description": "If true, will log all communication between VS Code and the adapter"
9195
}
9296
}
9397
}

src/phpDebug.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArgume
4848
localSourceRoot?: string;
4949
/** The current working directory, by default the project root */
5050
cwd?: string;
51+
/** If true, will log all communication between VS Code and the adapter to the console */
52+
log: boolean;
5153
}
5254

5355
class PhpDebugSession extends vscode.DebugSession {
@@ -238,20 +240,29 @@ class PhpDebugSession extends vscode.DebugSession {
238240

239241
/** Logs all requests before dispatching */
240242
protected dispatchRequest(request: VSCodeDebugProtocol.Request) {
241-
console.log(`\n\n-> ${request.command}Request`);
242-
console.log(util.inspect(request, {depth: null}));
243+
const log = `-> ${request.command}Request\n${util.inspect(request, {depth: null})}\n\n`;
244+
console.log(log);
245+
if (this._args && this._args.log) {
246+
this.sendEvent(new vscode.OutputEvent(log));
247+
}
243248
super.dispatchRequest(request);
244249
}
245250

246251
public sendEvent(event: VSCodeDebugProtocol.Event): void {
247-
console.log(`\n\n<- ${event.event}Event`)
248-
console.log(util.inspect(event, {depth: null}));
252+
const log = `-> ${event.event}Event\n${util.inspect(event, {depth: null})}\n\n`;
253+
console.log(log);
254+
if (this._args && this._args.log && !(event instanceof vscode.OutputEvent)) {
255+
this.sendEvent(new vscode.OutputEvent(log));
256+
}
249257
super.sendEvent(event);
250258
}
251259

252260
public sendResponse(response: VSCodeDebugProtocol.Response) {
253-
console[response.success ? 'log' : 'error'](`\n\n<- ${response.command}Response`)
254-
console[response.success ? 'log' : 'error'](util.inspect(response, {depth: null}));
261+
const log = `-> ${response.command}Response\n${util.inspect(response, {depth: null})}\n\n`;
262+
console[response.success ? 'log' : 'error'](log);
263+
if (this._args && this._args.log) {
264+
this.sendEvent(new vscode.OutputEvent(log, response.success ? 'stdout' : 'stderr'));
265+
}
255266
super.sendResponse(response);
256267
}
257268

testproject/.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"name": "Listen for XDebug",
77
"type": "php",
88
"request": "launch",
9-
"port": 9000
9+
"port": 9000,
10+
"log": true
1011
}
1112
]
1213
}

0 commit comments

Comments
 (0)