@@ -32,7 +32,7 @@ if (process.env['VSCODE_NLS_CONFIG']) {
3232}
3333
3434/** formats a xdebug property value for VS Code */
35- function formatPropertyValue ( property : xdebug . BaseProperty ) : string {
35+ function formatPropertyValue ( property : xdebug . BaseProperty , quoteString : boolean = true ) : string {
3636 let displayValue : string
3737 if ( property . hasChildren || property . type === 'array' || property . type === 'object' ) {
3838 if ( property . type === 'array' ) {
@@ -48,7 +48,7 @@ function formatPropertyValue(property: xdebug.BaseProperty): string {
4848 } else {
4949 // for null, uninitialized, resource, etc. show the type
5050 displayValue = property . value || property . type === 'string' ? property . value : property . type
51- if ( property . type === 'string' ) {
51+ if ( property . type === 'string' && quoteString ) {
5252 displayValue = `"${ displayValue } "`
5353 } else if ( property . type === 'bool' ) {
5454 displayValue = Boolean ( parseInt ( displayValue , 10 ) ) . toString ( )
@@ -1525,56 +1525,54 @@ class PhpDebugSession extends vscode.DebugSession {
15251525 const stackFrame = this . _stackFrames . get ( args . frameId ) !
15261526 const connection = stackFrame . connection
15271527 let result : xdebug . BaseProperty | null = null
1528+
15281529 if ( args . context === 'hover' ) {
15291530 // try to get variable from property_get
15301531 const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
15311532 const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
15321533 if ( res . property ) {
15331534 result = res . property
15341535 }
1535- } else if ( args . context === 'repl' ) {
1536- const uuid = randomUUID ( )
1537- await connection . sendEvalCommand ( `$GLOBALS['eval_cache']['${ uuid } ']=${ args . expression } ` )
1538- const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1539- const res = await connection . sendPropertyGetNameCommand ( `$eval_cache['${ uuid } ']` , ctx [ 1 ] )
1540- if ( res . property ) {
1541- result = res . property
1542- }
1543- } else if ( args . context === 'clipboard-var_export' ) {
1544- const property =
1545- this . getPropertyFromReference ( args . variablesReference ) ??
1546- ( await ( async ( ) => {
1547- const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1536+ } else {
1537+ let property = this . getPropertyFromReference ( args . variablesReference )
1538+ let ctx
1539+ if ( ! property ) {
1540+ // try to get variable
1541+ ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1542+ try {
1543+ // we might need to try other contexts too?
15481544 const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
1549- return res . property
1550- } ) ( ) )
1551- response . body = { result : await varExportProperty ( property ) , variablesReference : 0 }
1545+ property = res . property
1546+ } catch {
1547+ // ignore we failed, lets try evaling
1548+ }
1549+ }
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 ] )
1554+ property = res . property
1555+ }
1556+ result = property
1557+ }
1558+
1559+ if ( result && args . context === 'clipboard-var_export' ) {
1560+ response . body = { result : await varExportProperty ( result as xdebug . Property ) , variablesReference : 0 }
15521561 this . sendResponse ( response )
15531562 return
1554- } else if ( args . context === 'clipboard-json' ) {
1555- const property =
1556- this . getPropertyFromReference ( args . variablesReference ) ??
1557- ( await ( async ( ) => {
1558- const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1559- const res = await connection . sendPropertyGetNameCommand ( args . expression , ctx [ 0 ] )
1560- return res . property
1561- } ) ( ) )
1562- response . body = { result : await varJsonProperty ( property ) , variablesReference : 0 }
1563+ } else if ( result && args . context === 'clipboard-json' ) {
1564+ response . body = { result : await varJsonProperty ( result as xdebug . Property ) , variablesReference : 0 }
1565+ this . sendResponse ( response )
1566+ return
1567+ } else if ( result && args . context === 'clipboard-raw' ) {
1568+ response . body = { result : formatPropertyValue ( result , false ) , variablesReference : 0 }
1569+ this . sendResponse ( response )
1570+ return
1571+ } else if ( result && this . _initializeArgs . clientID !== 'vscode' && args . context === 'clipboard' ) {
1572+ // 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 }
15631574 this . sendResponse ( response )
15641575 return
1565- } else if ( args . context === 'watch' ) {
1566- const uuid = randomUUID ( )
1567- await connection . sendEvalCommand ( `$GLOBALS['eval_cache']['watch']['${ uuid } ']=${ args . expression } ` )
1568- const ctx = await stackFrame . getContexts ( ) // TODO CACHE THIS
1569- const res = await connection . sendPropertyGetNameCommand ( `$eval_cache['watch']['${ uuid } ']` , ctx [ 1 ] )
1570- if ( res . property ) {
1571- result = res . property
1572- }
1573- } else {
1574- const res = await connection . sendEvalCommand ( args . expression )
1575- if ( res . result ) {
1576- result = res . result
1577- }
15781576 }
15791577
15801578 if ( result ) {
0 commit comments