@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22import { WorkspaceFolder , DebugConfiguration , ProviderResult , CancellationToken } from 'vscode'
33import { LaunchRequestArguments } from './phpDebug'
44import * as which from 'which'
5+ import * as path from 'path'
56
67export 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