Skip to content

Commit

Permalink
fix: Editor title run/debug icon did not work anymore (#928)
Browse files Browse the repository at this point in the history
* docs: Update CHANGELOG.

* Fixing the "Debug PHP" button and implementing run and debug php file like Mock Debug example.

* Changelog.
  • Loading branch information
zobo authored Oct 23, 2023
1 parent b07f71b commit 291181c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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.33.1]

- Fix editor title run/debug button.

## [1.33.0]

- Add skipEntryPaths to immediately detach a debug session depending on entry path.
Expand Down
49 changes: 37 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@
"main": "./out/extension.js",
"activationEvents": [
"onDebugResolve:php",
"onCommand:php.debug.debugPhpFile",
"onCommand:php.debug.startWithStopOnEntry"
"onCommand:extension.php-debug.startWithStopOnEntry",
"onCommand:extension.php-debug.debugEditorContents",
"onCommand:extension.php-debug.runEditorContents"
],
"capabilities": {
"untrustedWorkspaces": {
Expand Down Expand Up @@ -525,32 +526,56 @@
"menus": {
"editor/title/run": [
{
"command": "php.debug.debugPhpFile",
"command": "extension.php-debug.runEditorContents",
"when": "resourceLangId == php && !inDiffEditor",
"group": "navigation@1"
},
{
"command": "extension.php-debug.debugEditorContents",
"when": "resourceLangId == php && !inDiffEditor",
"group": "navigation@2"
}
],
"commandPalette": [
{
"command": "extension.php-debug.debugEditorContents",
"when": "resourceLangId == php && !inDiffEditor"
},
{
"command": "extension.php-debug.runEditorContents",
"when": "resourceLangId == php && !inDiffEditor"
}
]
},
"commands": [
{
"command": "php.debug.debugPhpFile",
"title": "Debug PHP",
"icon": "$(debug-alt-small)",
"enablement": "resourceLangId == php"
},
{
"command": "php.debug.startWithStopOnEntry",
"command": "extension.php-debug.startWithStopOnEntry",
"title": "Start Debugging and Stop on Entry",
"category": "Debug"
},
{
"command": "extension.php-debug.debugEditorContents",
"title": "Debug PHP File",
"category": "PHP Debug",
"enablement": "!inDebugMode",
"icon": "$(debug-alt)"
},
{
"command": "extension.php-debug.runEditorContents",
"title": "Run PHP File",
"category": "PHP Debug",
"enablement": "!inDebugMode",
"icon": "$(play)"
}
],
"keybindings": [
{
"command": "php.debug.startWithStopOnEntry",
"command": "extension.php-debug.startWithStopOnEntry",
"key": "F10",
"when": "!inDebugMode && debugConfigurationType == 'php'"
},
{
"command": "php.debug.startWithStopOnEntry",
"command": "extension.php-debug.startWithStopOnEntry",
"key": "F11",
"when": "!inDebugMode && debugConfigurationType == 'php'"
}
Expand Down
46 changes: 40 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode'
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode'
import { LaunchRequestArguments } from './phpDebug'
import * as which from 'which'
import * as path from 'path'

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
Expand All @@ -11,14 +12,18 @@ export function activate(context: vscode.ExtensionContext) {
debugConfiguration: DebugConfiguration & LaunchRequestArguments,
token?: CancellationToken
): Promise<ProviderResult<DebugConfiguration>> {
if (!debugConfiguration.type && !debugConfiguration.request && !debugConfiguration.name) {
const isDynamic =
(!debugConfiguration.type || debugConfiguration.type === 'php') &&
!debugConfiguration.request &&
!debugConfiguration.name
if (isDynamic) {
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.program = debugConfiguration.program || '${file}'
debugConfiguration.cwd = debugConfiguration.cwd || '${fileDirname}'
debugConfiguration.port = 0
debugConfiguration.runtimeArgs = ['-dxdebug.start_with_request=yes']
debugConfiguration.env = {
Expand Down Expand Up @@ -72,13 +77,42 @@ export function activate(context: vscode.ExtensionContext) {
)

context.subscriptions.push(
vscode.commands.registerCommand('php.debug.debugPhpFile', async (uri: vscode.Uri) => {
await vscode.debug.startDebugging(undefined, { type: '', name: '', request: '' })
vscode.commands.registerCommand('extension.php-debug.runEditorContents', (resource: vscode.Uri) => {
let targetResource = resource
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri
}
if (targetResource) {
void vscode.debug.startDebugging(undefined, {
type: 'php',
name: '',
request: '',
noDebug: true,
program: targetResource.fsPath,
cwd: path.dirname(targetResource.fsPath),
})
}
}),
vscode.commands.registerCommand('extension.php-debug.debugEditorContents', (resource: vscode.Uri) => {
let targetResource = resource
if (!targetResource && vscode.window.activeTextEditor) {
targetResource = vscode.window.activeTextEditor.document.uri
}
if (targetResource) {
void vscode.debug.startDebugging(undefined, {
type: 'php',
name: '',
request: '',
stopOnEntry: true,
program: targetResource.fsPath,
cwd: path.dirname(targetResource.fsPath),
})
}
})
)

context.subscriptions.push(
vscode.commands.registerCommand('php.debug.startWithStopOnEntry', async (uri: vscode.Uri) => {
vscode.commands.registerCommand('extension.php-debug.startWithStopOnEntry', async (uri: vscode.Uri) => {
await vscode.commands.executeCommand('workbench.action.debug.start', {
config: {
stopOnEntry: true,
Expand Down

0 comments on commit 291181c

Please sign in to comment.