Skip to content

Commit 291181c

Browse files
authored
fix: Editor title run/debug icon did not work anymore (#928)
* docs: Update CHANGELOG. * Fixing the "Debug PHP" button and implementing run and debug php file like Mock Debug example. * Changelog.
1 parent b07f71b commit 291181c

File tree

3 files changed

+81
-18
lines changed

3 files changed

+81
-18
lines changed

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.33.1]
8+
9+
- Fix editor title run/debug button.
10+
711
## [1.33.0]
812

913
- Add skipEntryPaths to immediately detach a debug session depending on entry path.

package.json

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@
154154
"main": "./out/extension.js",
155155
"activationEvents": [
156156
"onDebugResolve:php",
157-
"onCommand:php.debug.debugPhpFile",
158-
"onCommand:php.debug.startWithStopOnEntry"
157+
"onCommand:extension.php-debug.startWithStopOnEntry",
158+
"onCommand:extension.php-debug.debugEditorContents",
159+
"onCommand:extension.php-debug.runEditorContents"
159160
],
160161
"capabilities": {
161162
"untrustedWorkspaces": {
@@ -525,32 +526,56 @@
525526
"menus": {
526527
"editor/title/run": [
527528
{
528-
"command": "php.debug.debugPhpFile",
529+
"command": "extension.php-debug.runEditorContents",
530+
"when": "resourceLangId == php && !inDiffEditor",
531+
"group": "navigation@1"
532+
},
533+
{
534+
"command": "extension.php-debug.debugEditorContents",
535+
"when": "resourceLangId == php && !inDiffEditor",
536+
"group": "navigation@2"
537+
}
538+
],
539+
"commandPalette": [
540+
{
541+
"command": "extension.php-debug.debugEditorContents",
542+
"when": "resourceLangId == php && !inDiffEditor"
543+
},
544+
{
545+
"command": "extension.php-debug.runEditorContents",
529546
"when": "resourceLangId == php && !inDiffEditor"
530547
}
531548
]
532549
},
533550
"commands": [
534551
{
535-
"command": "php.debug.debugPhpFile",
536-
"title": "Debug PHP",
537-
"icon": "$(debug-alt-small)",
538-
"enablement": "resourceLangId == php"
539-
},
540-
{
541-
"command": "php.debug.startWithStopOnEntry",
552+
"command": "extension.php-debug.startWithStopOnEntry",
542553
"title": "Start Debugging and Stop on Entry",
543554
"category": "Debug"
555+
},
556+
{
557+
"command": "extension.php-debug.debugEditorContents",
558+
"title": "Debug PHP File",
559+
"category": "PHP Debug",
560+
"enablement": "!inDebugMode",
561+
"icon": "$(debug-alt)"
562+
},
563+
{
564+
"command": "extension.php-debug.runEditorContents",
565+
"title": "Run PHP File",
566+
"category": "PHP Debug",
567+
"enablement": "!inDebugMode",
568+
"icon": "$(play)"
544569
}
545570
],
546571
"keybindings": [
547572
{
548-
"command": "php.debug.startWithStopOnEntry",
573+
"command": "extension.php-debug.startWithStopOnEntry",
549574
"key": "F10",
550575
"when": "!inDebugMode && debugConfigurationType == 'php'"
551576
},
552577
{
553-
"command": "php.debug.startWithStopOnEntry",
578+
"command": "extension.php-debug.startWithStopOnEntry",
554579
"key": "F11",
555580
"when": "!inDebugMode && debugConfigurationType == 'php'"
556581
}

src/extension.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import { WorkspaceFolder, DebugConfiguration, ProviderResult, CancellationToken } from 'vscode'
33
import { LaunchRequestArguments } from './phpDebug'
44
import * as which from 'which'
5+
import * as path from 'path'
56

67
export function activate(context: vscode.ExtensionContext) {
78
context.subscriptions.push(
@@ -11,14 +12,18 @@ export function activate(context: vscode.ExtensionContext) {
1112
debugConfiguration: DebugConfiguration & LaunchRequestArguments,
1213
token?: CancellationToken
1314
): Promise<ProviderResult<DebugConfiguration>> {
14-
if (!debugConfiguration.type && !debugConfiguration.request && !debugConfiguration.name) {
15+
const isDynamic =
16+
(!debugConfiguration.type || debugConfiguration.type === 'php') &&
17+
!debugConfiguration.request &&
18+
!debugConfiguration.name
19+
if (isDynamic) {
1520
const editor = vscode.window.activeTextEditor
1621
if (editor && editor.document.languageId === 'php') {
1722
debugConfiguration.type = 'php'
1823
debugConfiguration.name = 'Launch (dynamic)'
1924
debugConfiguration.request = 'launch'
20-
debugConfiguration.program = '${file}'
21-
debugConfiguration.cwd = '${fileDirname}'
25+
debugConfiguration.program = debugConfiguration.program || '${file}'
26+
debugConfiguration.cwd = debugConfiguration.cwd || '${fileDirname}'
2227
debugConfiguration.port = 0
2328
debugConfiguration.runtimeArgs = ['-dxdebug.start_with_request=yes']
2429
debugConfiguration.env = {
@@ -72,13 +77,42 @@ export function activate(context: vscode.ExtensionContext) {
7277
)
7378

7479
context.subscriptions.push(
75-
vscode.commands.registerCommand('php.debug.debugPhpFile', async (uri: vscode.Uri) => {
76-
await vscode.debug.startDebugging(undefined, { type: '', name: '', request: '' })
80+
vscode.commands.registerCommand('extension.php-debug.runEditorContents', (resource: vscode.Uri) => {
81+
let targetResource = resource
82+
if (!targetResource && vscode.window.activeTextEditor) {
83+
targetResource = vscode.window.activeTextEditor.document.uri
84+
}
85+
if (targetResource) {
86+
void vscode.debug.startDebugging(undefined, {
87+
type: 'php',
88+
name: '',
89+
request: '',
90+
noDebug: true,
91+
program: targetResource.fsPath,
92+
cwd: path.dirname(targetResource.fsPath),
93+
})
94+
}
95+
}),
96+
vscode.commands.registerCommand('extension.php-debug.debugEditorContents', (resource: vscode.Uri) => {
97+
let targetResource = resource
98+
if (!targetResource && vscode.window.activeTextEditor) {
99+
targetResource = vscode.window.activeTextEditor.document.uri
100+
}
101+
if (targetResource) {
102+
void vscode.debug.startDebugging(undefined, {
103+
type: 'php',
104+
name: '',
105+
request: '',
106+
stopOnEntry: true,
107+
program: targetResource.fsPath,
108+
cwd: path.dirname(targetResource.fsPath),
109+
})
110+
}
77111
})
78112
)
79113

80114
context.subscriptions.push(
81-
vscode.commands.registerCommand('php.debug.startWithStopOnEntry', async (uri: vscode.Uri) => {
115+
vscode.commands.registerCommand('extension.php-debug.startWithStopOnEntry', async (uri: vscode.Uri) => {
82116
await vscode.commands.executeCommand('workbench.action.debug.start', {
83117
config: {
84118
stopOnEntry: true,

0 commit comments

Comments
 (0)