Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ In your project, go to the debugger and hit the little gear icon and choose _PHP
- `localSourceRoot`: The path to the folder that is being served by your webserver and maps to `serverSourceRoot` (for example `"${workspaceRoot}/public"`)
- `serverSourceRoot`: The path on the remote host where your webroot is located (for example `"/var/www"`)
- `log`: Wether to log all communication between VS Code and the adapter to the debug console. See _Troubleshooting_ further down.
- `ignore`: An optional array of glob patterns that errors should be ignored from (for example `**/vendor/**/*.php`)
- `xdebugSettings`: Allows you to override XDebug's remote debugging settings to fine tuning XDebug to your needs. For example, you can play with `max_children` and `max_depth` to change the max number of array and object children that are retrieved and the max depth in structures like arrays and objects. This can speed up the debugger on slow machines.
For a full list of feature names that can be set please refer to the [XDebug documentation](https://xdebug.org/docs-dbgp.php#feature-names).
- `max_children`: max number of array or object children to initially retrieve
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"file-url": "^2.0.0",
"iconv-lite": "^0.4.15",
"minimatch": "^3.0.3",
"moment": "2.17.1",
"url-relative": "^1.0.0",
"urlencode": "^1.1.0",
Expand Down Expand Up @@ -149,6 +150,14 @@
"type": "string",
"description": "The source root on this machine that is the equivalent to the serverSourceRoot on the server."
},
"ignore": {
"type": "array",
"items": "string",
"description": "Array of glob patterns that errors should be ignored from",
"default": [
"**/vendor/**/*.php"
]
},
"log": {
"type": "boolean",
"description": "If true, will log all communication between VS Code and the adapter"
Expand Down
11 changes: 10 additions & 1 deletion src/phpDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as util from 'util';
import * as fs from 'fs';
import {Terminal} from './terminal';
import {isSameUri, convertClientPathToDebugger, convertDebuggerPathToClient} from './paths';
import minimatch = require('minimatch');

if (process.env['VSCODE_NLS_CONFIG']) {
try {
Expand Down Expand Up @@ -59,6 +60,8 @@ interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArgume
localSourceRoot?: string;
/** If true, will log all communication between VS Code and the adapter to the console */
log?: boolean;
/** Array of glob patterns that errors should be ignored from */
ignore?: string[];
/** XDebug configuration */
xdebugSettings?: { [featureName: string]: string | number; };

Expand Down Expand Up @@ -286,7 +289,7 @@ class PhpDebugSession extends vscode.DebugSession {
* Checks the status of a StatusResponse and notifies VS Code accordingly
* @param {xdebug.StatusResponse} response
*/
private async _checkStatus(response: xdebug.StatusResponse) {
private async _checkStatus(response: xdebug.StatusResponse): Promise<void> {
const connection = response.connection;
this._statuses.set(connection, response);
if (response.status === 'stopping') {
Expand All @@ -301,6 +304,12 @@ class PhpDebugSession extends vscode.DebugSession {
let stoppedEventReason: 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry';
let exceptionText: string | undefined;
if (response.exception) {
// If one of the ignore patterns matches, ignore this exception
if (this._args.ignore && this._args.ignore.some(glob => minimatch(convertDebuggerPathToClient(response.fileUri).replace(/\\/g, '/'), glob))) {
const response = await connection.sendRunCommand();
await this._checkStatus(response);
return;
}
stoppedEventReason = 'exception';
exceptionText = response.exception.name + ': ' + response.exception.message; // this seems to be ignored currently by VS Code
} else if (this._args.stopOnEntry) {
Expand Down
35 changes: 31 additions & 4 deletions src/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,23 @@ describe('PHP Debug Adapter', () => {

const program = path.join(TEST_PROJECT, 'error.php');

beforeEach(() => Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]));
it('should not break on anything if the file matches the ignore pattern', async () => {
await Promise.all([
client.launch({program, ignore: ['**/*.*']}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['*']});
await Promise.all([
client.configurationDoneRequest(),
client.waitForEvent('terminated')
]);
});

it('should support stopping only on a notice', async () => {
await Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['Notice']});
const [, {threadId}] = await Promise.all([
client.configurationDoneRequest(),
Expand All @@ -184,6 +195,10 @@ describe('PHP Debug Adapter', () => {
});

it('should support stopping only on a warning', async () => {
await Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['Warning']});
const [{threadId}] = await Promise.all([
assertStoppedLocation('exception', program, 9),
Expand All @@ -198,6 +213,10 @@ describe('PHP Debug Adapter', () => {
it('should support stopping only on an error');

it('should support stopping only on an exception', async () => {
await Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['Exception']});
const [, {threadId}] = await Promise.all([
client.configurationDoneRequest(),
Expand All @@ -213,6 +232,10 @@ describe('PHP Debug Adapter', () => {
if (!process.env['XDEBUG_VERSION'] || semver.gte(process.env['XDEBUG_VERSION'], '2.3.0')) {

it('should support stopping on everything', async () => {
await Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['*']});
// Notice
const [, {threadId}] = await Promise.all([
Expand Down Expand Up @@ -243,6 +266,10 @@ describe('PHP Debug Adapter', () => {

it.skip('should report the error in a virtual error scope', async () => {

await Promise.all([
client.launch({program}),
client.waitForEvent('initialized')
]);
await client.setExceptionBreakpointsRequest({filters: ['Notice', 'Warning', 'Exception']});
const [{body: {threadId}}] = await Promise.all([
client.waitForEvent('stopped') as Promise<DebugProtocol.StoppedEvent>,
Expand Down
1 change: 1 addition & 0 deletions typings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "php-debug",
"version": false,
"dependencies": {
"minimatch": "registry:npm/minimatch#3.0.0+20160723033700",
"semver": "registry:npm/semver#5.0.0+20160723033700"
},
"globalDependencies": {
Expand Down