Skip to content

Commit 6073b57

Browse files
authored
feat: Purple no folder VS Code debugging support (#645)
* Handle configuration resolving for no folder (purple) instances falling back to launch (Xdebug 3) configuration. * When resolving debug configuration search path for php, warn user about missing executable and offer to open settings with filter. * Trigger start debug from editor title. * No folder debugging description on README.md * Use special command to trigger debugging of no-folder PHP files. * Changelog. * Ignore extension.ts from codecov. Co-authored-by: Damjan Cvetko <[email protected]>
1 parent 9de7860 commit 6073b57

File tree

9 files changed

+145
-10
lines changed

9 files changed

+145
-10
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"NODE_ENV": "development"
1313
},
1414
"sourceMaps": true,
15-
"outFiles": ["${workspaceRoot}/out/**/*.js"]
15+
"outFiles": ["${workspaceFolder}/out/**/*.js"]
1616
},
1717
{
1818
"name": "Launch Extension",
@@ -21,7 +21,7 @@
2121
"runtimeExecutable": "${execPath}",
2222
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
2323
"sourceMaps": true,
24-
"outFiles": ["${workspaceRoot}/out/**/*.js"]
24+
"outFiles": ["${workspaceFolder}/out/**/*.js"]
2525
},
2626
{
2727
"name": "Mocha",
@@ -31,7 +31,7 @@
3131
"args": ["out/test", "--no-timeouts", "--colors"],
3232
"cwd": "${workspaceRoot}",
3333
"sourceMaps": true,
34-
"outFiles": ["${workspaceRoot}/out/**/*.js"]
34+
"outFiles": ["${workspaceFolder}/out/**/*.js"]
3535
}
3636
]
3737
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
3+
"search.exclude": {
4+
"out": true // set this to false to include "out" folder in search results
5+
},
36
"javascript.validate.enable": false,
47
"eslint.enable": false,
58
"editor.insertSpaces": true,

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.20.0]
8+
9+
- Support no-folder debugging in (purple) VS Code.
10+
711
## [1.19.0]
812

913
## Added

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Manage pull requests and conduct code reviews in your IDE with full source-tree
1111

1212
### Sponsor PHP Debug Adapter for Visual Studio Code
1313

14-
If you find this extension usefull, if it helps you solve your problems and if you appreciate the support given here, consider sponsoring our work.
14+
If you find this extension useful, if it helps you solve your problems and if you appreciate the support given here, consider sponsoring our work.
1515

1616
## Installation
1717

@@ -65,6 +65,8 @@ There are also configurations for Xdebug v2 (Legacy) installations.
6565

6666
More general information on debugging with VS Code can be found on https://code.visualstudio.com/docs/editor/debugging.
6767

68+
> _Note:_ You can even debug a script without `launch.json`. If no folder is open, and the VS Code status bar is purple, pressing `F5` will start the open script with Xdebug3 specific parameters. If the php executable is not in path, you can provide it with the setting `php.executablePath` or a fallback `php.validate.executablePath`. For debugging to work, Xdebug must still be correctly installed.
69+
6870
#### Supported launch.json settings:
6971

7072
- `request`: Always `"launch"`
@@ -78,7 +80,7 @@ More general information on debugging with VS Code can be found on https://code.
7880
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).
7981
- `max_children`: max number of array or object children to initially retrieve
8082
- `max_data`: max amount of variable data to initially retrieve.
81-
- `max_depth`: maximum depth that the debugger engine may return when sending arrays, hashs or object structures to the IDE (there should be no need to change this as depth is retrieved incrementally, large value can cause IDE to hang).
83+
- `max_depth`: maximum depth that the debugger engine may return when sending arrays, hashes or object structures to the IDE (there should be no need to change this as depth is retrieved incrementally, large value can cause IDE to hang).
8284
- `show_hidden`: This feature can get set by the IDE if it wants to have more detailed internal information on properties (eg. private members of classes, etc.) Zero means that hidden members are not shown to the IDE.
8385

8486
Options specific to CLI debugging:

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore:
2+
- 'src/extension.ts'

package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
"minimatch": "^3.0.4",
4646
"moment": "^2.29.1",
4747
"relateurl": "^0.2.7",
48+
"semver": "^7.3.5",
4849
"string-replace-async": "^2.0.0",
4950
"url-relative": "^1.0.0",
5051
"urlencode": "^1.1.0",
5152
"vscode-debugadapter": "^1.47.0",
5253
"vscode-debugprotocol": "^1.47.0",
53-
"semver": "^7.3.5",
54+
"which": "^2.0.2",
5455
"xmldom": "^0.6.0"
5556
},
5657
"devDependencies": {
@@ -64,6 +65,8 @@
6465
"@types/relateurl": "^0.2.29",
6566
"@types/semver": "^7.3.8",
6667
"@types/urlencode": "^1.1.2",
68+
"@types/vscode": "^1.53.0",
69+
"@types/which": "^2.0.1",
6770
"@types/xmldom": "^0.1.31",
6871
"chai": "^4.3.4",
6972
"chai-as-promised": "^7.1.1",
@@ -138,6 +141,11 @@
138141
"out/test/**/*.*"
139142
]
140143
},
144+
"main": "./out/extension.js",
145+
"activationEvents": [
146+
"onDebugResolve:php",
147+
"onCommand:php.debug.debugPhpFile"
148+
],
141149
"contributes": {
142150
"breakpoints": [
143151
{
@@ -397,6 +405,45 @@
397405
}
398406
]
399407
}
408+
],
409+
"configuration": {
410+
"title": "PHP",
411+
"properties": {
412+
"php.executablePath": {
413+
"type": [
414+
"string",
415+
"null"
416+
],
417+
"default": null,
418+
"description": "The path to a PHP executable.",
419+
"scope": "machine-overridable"
420+
}
421+
}
422+
},
423+
"capabilities": {
424+
"untrustedWorkspaces": {
425+
"supported": "limited",
426+
"description": "%workspaceTrust%",
427+
"restrictedConfigurations": [
428+
"php.executablePath"
429+
]
430+
}
431+
},
432+
"menus": {
433+
"editor/title/run": [
434+
{
435+
"command": "php.debug.debugPhpFile",
436+
"when": "resourceLangId == php"
437+
}
438+
]
439+
},
440+
"commands": [
441+
{
442+
"command": "php.debug.debugPhpFile",
443+
"title": "Debug PHP",
444+
"icon": "$(debug-alt-small)",
445+
"enablement": "resourceLangId == php"
446+
}
400447
]
401448
}
402449
}

src/extension.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as vscode from 'vscode'
2+
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode'
3+
import { LaunchRequestArguments } from './phpDebug'
4+
import * as which from 'which'
5+
6+
export function activate(context: vscode.ExtensionContext) {
7+
context.subscriptions.push(
8+
vscode.debug.registerDebugConfigurationProvider('php', {
9+
async resolveDebugConfiguration(
10+
folder: WorkspaceFolder | undefined,
11+
debugConfiguration: DebugConfiguration & LaunchRequestArguments,
12+
token?: CancellationToken
13+
): Promise<ProviderResult<DebugConfiguration>> {
14+
if (!debugConfiguration.type && !debugConfiguration.request && !debugConfiguration.name) {
15+
const editor = vscode.window.activeTextEditor
16+
if (editor && editor.document.languageId === 'php') {
17+
debugConfiguration.type = 'php'
18+
debugConfiguration.name = 'Launch (dynamic)'
19+
debugConfiguration.request = 'launch'
20+
debugConfiguration.program = '${file}'
21+
debugConfiguration.cwd = '${fileDirname}'
22+
debugConfiguration.port = 0
23+
debugConfiguration.runtimeArgs = ['-dxdebug.start_with_request=yes']
24+
debugConfiguration.env = {
25+
XDEBUG_MODE: 'debug,develop',
26+
XDEBUG_CONFIG: 'client_port=${port}',
27+
}
28+
// debugConfiguration.stopOnEntry = true
29+
}
30+
}
31+
if (debugConfiguration.program && !debugConfiguration.runtimeExecutable) {
32+
// See if we have runtimeExecutable configured
33+
const conf = vscode.workspace.getConfiguration('php')
34+
const executablePath =
35+
conf.get<string>('executablePath') || conf.get<string>('validate.executablePath')
36+
if (executablePath) {
37+
debugConfiguration.runtimeExecutable = executablePath
38+
}
39+
// See if it's in path
40+
if (!debugConfiguration.runtimeExecutable) {
41+
try {
42+
await which.default('php')
43+
} catch (e) {
44+
const selected = await vscode.window.showErrorMessage(
45+
'PHP executable not found. Install PHP and add it to your PATH or set the php.executablePath setting',
46+
'Open settings'
47+
)
48+
if (selected === 'Open settings') {
49+
await vscode.commands.executeCommand('workbench.action.openGlobalSettings', {
50+
query: 'php.executablePath',
51+
})
52+
return undefined
53+
}
54+
}
55+
}
56+
}
57+
return debugConfiguration
58+
},
59+
})
60+
)
61+
62+
context.subscriptions.push(
63+
vscode.commands.registerCommand('php.debug.debugPhpFile', async (uri: vscode.Uri) => {
64+
vscode.debug.startDebugging(undefined, { type: '', name: '', request: '' })
65+
})
66+
)
67+
}

src/phpDebug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function formatPropertyValue(property: xdebug.BaseProperty): string {
5252
/**
5353
* This interface should always match the schema found in the mock-debug extension manifest.
5454
*/
55-
interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArguments {
55+
export interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArguments {
5656
/** The address to bind to for listening for Xdebug connections (default: all IPv6 connections if available, else all IPv4 connections) */
5757
hostname?: string
5858
/** The port where the adapter should listen for Xdebug connections (default: 9003) */

0 commit comments

Comments
 (0)