Skip to content

Commit

Permalink
feat: Purple no folder VS Code debugging support (#645)
Browse files Browse the repository at this point in the history
* 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 <damjan.cvetko@monotek.net>
  • Loading branch information
zobo and zobo committed Oct 13, 2021
1 parent 9de7860 commit 6073b57
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Expand Up @@ -12,7 +12,7 @@
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"]
"outFiles": ["${workspaceFolder}/out/**/*.js"]
},
{
"name": "Launch Extension",
Expand All @@ -21,7 +21,7 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"]
"outFiles": ["${workspaceFolder}/out/**/*.js"]
},
{
"name": "Mocha",
Expand All @@ -31,7 +31,7 @@
"args": ["out/test", "--no-timeouts", "--colors"],
"cwd": "${workspaceRoot}",
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/**/*.js"]
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -1,5 +1,8 @@
// Place your settings in this file to overwrite default and user settings.
{
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"javascript.validate.enable": false,
"eslint.enable": false,
"editor.insertSpaces": true,
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

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

## [1.20.0]

- Support no-folder debugging in (purple) VS Code.

## [1.19.0]

## Added
Expand Down
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -11,7 +11,7 @@ Manage pull requests and conduct code reviews in your IDE with full source-tree

### Sponsor PHP Debug Adapter for Visual Studio Code

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.
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.

## Installation

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

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

> _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.
#### Supported launch.json settings:

- `request`: Always `"launch"`
Expand All @@ -78,7 +80,7 @@ More general information on debugging with VS Code can be found on https://code.
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
- `max_data`: max amount of variable data to initially retrieve.
- `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).
- `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).
- `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.

Options specific to CLI debugging:
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
@@ -0,0 +1,2 @@
ignore:
- 'src/extension.ts'
16 changes: 13 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 48 additions & 1 deletion package.json
Expand Up @@ -45,12 +45,13 @@
"minimatch": "^3.0.4",
"moment": "^2.29.1",
"relateurl": "^0.2.7",
"semver": "^7.3.5",
"string-replace-async": "^2.0.0",
"url-relative": "^1.0.0",
"urlencode": "^1.1.0",
"vscode-debugadapter": "^1.47.0",
"vscode-debugprotocol": "^1.47.0",
"semver": "^7.3.5",
"which": "^2.0.2",
"xmldom": "^0.6.0"
},
"devDependencies": {
Expand All @@ -64,6 +65,8 @@
"@types/relateurl": "^0.2.29",
"@types/semver": "^7.3.8",
"@types/urlencode": "^1.1.2",
"@types/vscode": "^1.53.0",
"@types/which": "^2.0.1",
"@types/xmldom": "^0.1.31",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
Expand Down Expand Up @@ -138,6 +141,11 @@
"out/test/**/*.*"
]
},
"main": "./out/extension.js",
"activationEvents": [
"onDebugResolve:php",
"onCommand:php.debug.debugPhpFile"
],
"contributes": {
"breakpoints": [
{
Expand Down Expand Up @@ -397,6 +405,45 @@
}
]
}
],
"configuration": {
"title": "PHP",
"properties": {
"php.executablePath": {
"type": [
"string",
"null"
],
"default": null,
"description": "The path to a PHP executable.",
"scope": "machine-overridable"
}
}
},
"capabilities": {
"untrustedWorkspaces": {
"supported": "limited",
"description": "%workspaceTrust%",
"restrictedConfigurations": [
"php.executablePath"
]
}
},
"menus": {
"editor/title/run": [
{
"command": "php.debug.debugPhpFile",
"when": "resourceLangId == php"
}
]
},
"commands": [
{
"command": "php.debug.debugPhpFile",
"title": "Debug PHP",
"icon": "$(debug-alt-small)",
"enablement": "resourceLangId == php"
}
]
}
}
67 changes: 67 additions & 0 deletions src/extension.ts
@@ -0,0 +1,67 @@
import * as vscode from 'vscode'
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode'
import { LaunchRequestArguments } from './phpDebug'
import * as which from 'which'

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('php', {
async resolveDebugConfiguration(
folder: WorkspaceFolder | undefined,
debugConfiguration: DebugConfiguration & LaunchRequestArguments,
token?: CancellationToken
): Promise<ProviderResult<DebugConfiguration>> {
if (!debugConfiguration.type && !debugConfiguration.request && !debugConfiguration.name) {
const editor = vscode.window.activeTextEditor
if (editor && editor.document.languageId === 'php') {
debugConfiguration.type = 'php'
debugConfiguration.name = 'Launch (dynamic)'
debugConfiguration.request = 'launch'
debugConfiguration.program = '${file}'
debugConfiguration.cwd = '${fileDirname}'
debugConfiguration.port = 0
debugConfiguration.runtimeArgs = ['-dxdebug.start_with_request=yes']
debugConfiguration.env = {
XDEBUG_MODE: 'debug,develop',
XDEBUG_CONFIG: 'client_port=${port}',
}
// debugConfiguration.stopOnEntry = true
}
}
if (debugConfiguration.program && !debugConfiguration.runtimeExecutable) {
// See if we have runtimeExecutable configured
const conf = vscode.workspace.getConfiguration('php')
const executablePath =
conf.get<string>('executablePath') || conf.get<string>('validate.executablePath')
if (executablePath) {
debugConfiguration.runtimeExecutable = executablePath
}
// See if it's in path
if (!debugConfiguration.runtimeExecutable) {
try {
await which.default('php')
} catch (e) {
const selected = await vscode.window.showErrorMessage(
'PHP executable not found. Install PHP and add it to your PATH or set the php.executablePath setting',
'Open settings'
)
if (selected === 'Open settings') {
await vscode.commands.executeCommand('workbench.action.openGlobalSettings', {
query: 'php.executablePath',
})
return undefined
}
}
}
}
return debugConfiguration
},
})
)

context.subscriptions.push(
vscode.commands.registerCommand('php.debug.debugPhpFile', async (uri: vscode.Uri) => {
vscode.debug.startDebugging(undefined, { type: '', name: '', request: '' })
})
)
}
2 changes: 1 addition & 1 deletion src/phpDebug.ts
Expand Up @@ -52,7 +52,7 @@ function formatPropertyValue(property: xdebug.BaseProperty): string {
/**
* This interface should always match the schema found in the mock-debug extension manifest.
*/
interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArguments {
export interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchRequestArguments {
/** The address to bind to for listening for Xdebug connections (default: all IPv6 connections if available, else all IPv4 connections) */
hostname?: string
/** The port where the adapter should listen for Xdebug connections (default: 9003) */
Expand Down

0 comments on commit 6073b57

Please sign in to comment.