@@ -1524,44 +1524,75 @@ class PhpDebugSession extends vscode.DebugSession {
15241524 }
15251525 const stackFrame = this . _stackFrames . get ( args . frameId ) !
15261526 const connection = stackFrame . connection
1527- let result : xdebug . BaseProperty | null = null
1527+
1528+ let tryPropertyGet = false
1529+ let tryPropertyGetGlobal = false
1530+ let tryEval = true
15281531
15291532 if ( args . context === 'hover' ) {
1530- // try to get variable from property_get
1531- const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1532- const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
1533- if ( res . property ) {
1534- result = res . property
1535- }
1533+ tryPropertyGet = tryPropertyGetGlobal = true
1534+ tryEval = false
1535+ } else if ( args . context === 'repl' ) {
1536+ tryPropertyGet = tryPropertyGetGlobal = false
1537+ tryEval = true
1538+ } else if ( args . context === 'watch' ) {
1539+ tryPropertyGet = tryPropertyGetGlobal = true
1540+ tryEval = true
1541+ } else if ( args . context ?. startsWith ( 'clipboard' ) ) {
1542+ tryPropertyGet = tryPropertyGetGlobal = true
1543+ tryEval = true
15361544 } else {
1537- let property = this . getPropertyFromReference ( args . variablesReference )
1538- let ctx : xdebug . Context [ ]
1539- if ( ! property ) {
1540- // try to get variable
1545+ // fallback
1546+ tryPropertyGet = tryPropertyGetGlobal = false
1547+ tryEval = true
1548+ }
1549+
1550+ // TODO, we need to parse the expression to avoid using propery for things like
1551+ // - $arr[$key]
1552+ // - $x->$key
1553+ // - $$var
1554+
1555+ let property = this . getPropertyFromReference ( args . variablesReference )
1556+ let ctx : xdebug . Context [ ] | undefined
1557+ if ( ! property && tryPropertyGet ) {
1558+ if ( ! ctx ) {
15411559 ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1542- try {
1543- // we might need to try other contexts too?
1544- const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
1545- property = res . property
1546- } catch {
1547- // ignore we failed, lets try evaling
1548- }
15491560 }
1550- if ( ! property ) {
1551- const uuid = randomUUID ( )
1552- await connection . sendEvalCommand ( `$GLOBALS['eval_cache']['${ uuid } ']=${ args . expression } ` )
1553- const res = await connection . sendPropertyGetNameCommand ( `$eval_cache['${ uuid } ']` , ctx ! [ 1 ] )
1561+ try {
1562+ const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
15541563 property = res . property
1564+ } catch {
1565+ // ignore we failed, lets try next option
1566+ }
1567+ }
1568+ if ( ! property && tryPropertyGetGlobal ) {
1569+ if ( ! ctx ) {
1570+ ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1571+ }
1572+ try {
1573+ const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 1 ] )
1574+ property = res . property
1575+ } catch {
1576+ // ignore we failed, lets try next option
1577+ }
1578+ }
1579+ if ( ! property && tryEval ) {
1580+ if ( ! ctx ) {
1581+ ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
15551582 }
1556- result = property
1583+ const uuid = randomUUID ( )
1584+ await connection . sendEvalCommand ( `$GLOBALS['eval_cache']['${ uuid } ']=${ args . expression } ` )
1585+ const res = await connection . sendPropertyGetNameCommand ( `$eval_cache['${ uuid } ']` , ctx [ 1 ] )
1586+ property = res . property
15571587 }
15581588
1589+ const result = property
15591590 if ( result && args . context === 'clipboard-var_export' ) {
1560- response . body = { result : await varExportProperty ( result as xdebug . Property ) , variablesReference : 0 }
1591+ response . body = { result : await varExportProperty ( result ) , variablesReference : 0 }
15611592 this . sendResponse ( response )
15621593 return
15631594 } else if ( result && args . context === 'clipboard-json' ) {
1564- response . body = { result : await varJsonProperty ( result as xdebug . Property ) , variablesReference : 0 }
1595+ response . body = { result : await varJsonProperty ( result ) , variablesReference : 0 }
15651596 this . sendResponse ( response )
15661597 return
15671598 } else if ( result && args . context === 'clipboard-raw' ) {
@@ -1570,7 +1601,7 @@ class PhpDebugSession extends vscode.DebugSession {
15701601 return
15711602 } else if ( result && this . _initializeArgs . clientID !== 'vscode' && args . context === 'clipboard' ) {
15721603 // special case for NON-vscode clients where we cant add extra clipboard related contexts and var_export should be the default
1573- response . body = { result : await varExportProperty ( result as xdebug . Property ) , variablesReference : 0 }
1604+ response . body = { result : await varExportProperty ( result ) , variablesReference : 0 }
15741605 this . sendResponse ( response )
15751606 return
15761607 }
0 commit comments