@@ -195,6 +195,7 @@ class PhpDebugSession extends vscode.DebugSession {
195
195
supportsFunctionBreakpoints : true ,
196
196
supportsLogPoints : true ,
197
197
supportsHitConditionalBreakpoints : true ,
198
+ supportsCompletionsRequest : true ,
198
199
exceptionBreakpointFilters : [
199
200
{
200
201
filter : 'Notice' ,
@@ -993,106 +994,124 @@ class PhpDebugSession extends vscode.DebugSession {
993
994
this . sendResponse ( response )
994
995
}
995
996
996
- protected async completionsRequest ( response : VSCodeDebugProtocol . CompletionsResponse , args : VSCodeDebugProtocol . CompletionsArguments ) {
997
+ protected async completionsRequest (
998
+ response : VSCodeDebugProtocol . CompletionsResponse ,
999
+ args : VSCodeDebugProtocol . CompletionsArguments
1000
+ ) {
997
1001
try {
998
1002
if ( ! args . frameId ) {
999
- throw new Error ( 'No stack frame given' ) ;
1003
+ throw new Error ( 'No stack frame given' )
1000
1004
}
1001
- const lineIndex : number = args . line ? args . line - 1 : 0 ;
1002
- const lines : string [ ] = args . text . split ( '\n' ) ;
1005
+ const lineIndex : number = args . line ? args . line - 1 : 0
1006
+ const lines : string [ ] = args . text . split ( '\n' )
1003
1007
/** The text before the cursor */
1004
- const typed : string = [ ...lines . slice ( 0 , Math . max ( lineIndex - 1 , 0 ) ) , lines [ lineIndex ] . substring ( 0 , args . column ) ] . join ( '\n' ) ;
1005
- let i = typed . length ;
1006
- let containerName : string ;
1007
- let operator : string | undefined ;
1008
- let query : string ;
1008
+ const typed : string = [
1009
+ ...lines . slice ( 0 , Math . max ( lineIndex - 1 , 0 ) ) ,
1010
+ lines [ lineIndex ] . substring ( 0 , args . column ) ,
1011
+ ] . join ( '\n' )
1012
+ let i = typed . length
1013
+ let containerName : string
1014
+ let operator : string | undefined
1015
+ let query : string
1009
1016
while ( true ) {
1010
- const substr = typed . substring ( 0 , i ) ;
1017
+ const substr = typed . substring ( 0 , i )
1011
1018
if ( / \[ $ / . test ( substr ) ) {
1012
1019
// Numeric array index
1013
- operator = '[' ;
1020
+ operator = '['
1014
1021
} else if ( / \[ ' $ / . test ( substr ) ) {
1015
1022
// String array index
1016
- operator = `['` ;
1023
+ operator = `['`
1017
1024
} else if ( / - > $ / . test ( substr ) ) {
1018
- operator = '->' ;
1025
+ operator = '->'
1019
1026
} else if ( i > 0 ) {
1020
- i -- ;
1021
- continue ;
1027
+ i --
1028
+ continue
1022
1029
}
1023
- query = typed . substr ( i ) . toLowerCase ( ) ;
1024
- containerName = typed . substring ( 0 , operator ? i - operator . length : i ) ;
1025
- break ;
1030
+ query = typed . substr ( i ) . toLowerCase ( )
1031
+ containerName = typed . substring ( 0 , operator ? i - operator . length : i )
1032
+ break
1026
1033
}
1027
- const frame = this . _stackFrames . get ( args . frameId ) ;
1028
- const contexts = await frame . getContexts ( ) ;
1029
- const targets : VSCodeDebugProtocol . CompletionItem [ ] = [ ] ;
1034
+ const frame = this . _stackFrames . get ( args . frameId ) !
1035
+ const contexts = await frame . getContexts ( )
1036
+ const targets : VSCodeDebugProtocol . CompletionItem [ ] = [ ]
1030
1037
if ( ! containerName || ! operator ) {
1031
- const responses = await Promise . all ( contexts . map ( context => context . getProperties ( ) ) ) ;
1038
+ const responses = await Promise . all ( contexts . map ( context => context . getProperties ( ) ) )
1032
1039
for ( const properties of responses ) {
1033
1040
for ( const property of properties ) {
1034
1041
if ( property . name . toLowerCase ( ) . startsWith ( query ) ) {
1035
- const text = property . name [ 0 ] === '$' ? property . name . substr ( 1 ) : property . name ;
1036
- targets . push ( { label : property . name , text, type : 'variable' , start : i , length : property . name . length } ) ;
1042
+ const text = property . name [ 0 ] === '$' ? property . name . substr ( 1 ) : property . name
1043
+ targets . push ( {
1044
+ label : property . name ,
1045
+ text,
1046
+ type : 'variable' ,
1047
+ //start: i,
1048
+ length : property . name . length ,
1049
+ } )
1037
1050
}
1038
1051
}
1039
1052
}
1040
1053
} else {
1041
1054
// Search all contexts
1042
1055
for ( const context of contexts ) {
1043
- let response : xdebug . PropertyGetResponse | undefined ;
1056
+ let response : xdebug . PropertyGetResponse | undefined
1044
1057
try {
1045
- response = await frame . connection . sendPropertyGetCommand ( { context, fullName : containerName } ) ;
1058
+ response = await frame . connection . sendPropertyGetCommand ( { context, fullName : containerName } )
1046
1059
} catch ( err ) {
1047
1060
// ignore
1048
1061
}
1049
1062
if ( response ) {
1050
1063
for ( const property of response . children ) {
1051
1064
if ( property . name . toLowerCase ( ) . startsWith ( query ) ) {
1052
- let type : VSCodeDebugProtocol . CompletionItemType | undefined ;
1053
- let text : string = property . name ;
1065
+ let type : VSCodeDebugProtocol . CompletionItemType | undefined
1066
+ let text : string = property . name
1054
1067
if ( operator === '->' ) {
1055
1068
// Object
1056
- type = 'property' ;
1069
+ type = 'property'
1057
1070
} else if ( operator [ 0 ] === '[' ) {
1058
1071
// Array
1059
1072
if ( parseInt ( property . name ) + '' === property . name ) {
1060
1073
// Numeric index
1061
1074
if ( operator [ 1 ] === `'` ) {
1062
- continue ;
1075
+ continue
1063
1076
}
1064
- type = 'value' ;
1065
- text += ']' ;
1077
+ type = 'value'
1078
+ text += ']'
1066
1079
} else {
1067
1080
// String index
1068
1081
if ( operator [ 1 ] !== `'` ) {
1069
1082
if ( query ) {
1070
- continue ;
1083
+ continue
1071
1084
} else {
1072
- text = `'` + text ;
1085
+ text = `'` + text
1073
1086
}
1074
1087
}
1075
- type = 'text' ;
1076
- text += `']` ;
1088
+ type = 'text'
1089
+ text += `']`
1077
1090
}
1078
1091
}
1079
- targets . push ( { label : property . name , text, type, start : i , length : property . name . length } ) ;
1092
+ targets . push ( {
1093
+ label : property . name ,
1094
+ text,
1095
+ type,
1096
+ //start: i,
1097
+ length : property . name . length ,
1098
+ } )
1080
1099
}
1081
1100
}
1082
1101
// If we found the variable in one context (typically Locals), abort
1083
- break ;
1102
+ break
1084
1103
}
1085
1104
}
1086
1105
}
1087
- response . body = { targets} ;
1106
+ console . log ( `completionsRequest ${ args . text } (${ args . column } :${ args . line } ) ${ JSON . stringify ( targets ) } ` )
1107
+ response . body = { targets }
1088
1108
} catch ( err ) {
1089
- this . sendErrorResponse ( response , err ) ;
1090
- return ;
1109
+ this . sendErrorResponse ( response , err )
1110
+ return
1091
1111
}
1092
- this . sendResponse ( response ) ;
1112
+ this . sendResponse ( response )
1093
1113
}
1094
1114
1095
-
1096
1115
protected async continueRequest (
1097
1116
response : VSCodeDebugProtocol . ContinueResponse ,
1098
1117
args : VSCodeDebugProtocol . ContinueArguments
0 commit comments