@@ -195,6 +195,7 @@ class PhpDebugSession extends vscode.DebugSession {
195195 supportsFunctionBreakpoints : true ,
196196 supportsLogPoints : true ,
197197 supportsHitConditionalBreakpoints : true ,
198+ supportsCompletionsRequest : true ,
198199 exceptionBreakpointFilters : [
199200 {
200201 filter : 'Notice' ,
@@ -993,106 +994,124 @@ class PhpDebugSession extends vscode.DebugSession {
993994 this . sendResponse ( response )
994995 }
995996
996- protected async completionsRequest ( response : VSCodeDebugProtocol . CompletionsResponse , args : VSCodeDebugProtocol . CompletionsArguments ) {
997+ protected async completionsRequest (
998+ response : VSCodeDebugProtocol . CompletionsResponse ,
999+ args : VSCodeDebugProtocol . CompletionsArguments
1000+ ) {
9971001 try {
9981002 if ( ! args . frameId ) {
999- throw new Error ( 'No stack frame given' ) ;
1003+ throw new Error ( 'No stack frame given' )
10001004 }
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' )
10031007 /** 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
10091016 while ( true ) {
1010- const substr = typed . substring ( 0 , i ) ;
1017+ const substr = typed . substring ( 0 , i )
10111018 if ( / \[ $ / . test ( substr ) ) {
10121019 // Numeric array index
1013- operator = '[' ;
1020+ operator = '['
10141021 } else if ( / \[ ' $ / . test ( substr ) ) {
10151022 // String array index
1016- operator = `['` ;
1023+ operator = `['`
10171024 } else if ( / - > $ / . test ( substr ) ) {
1018- operator = '->' ;
1025+ operator = '->'
10191026 } else if ( i > 0 ) {
1020- i -- ;
1021- continue ;
1027+ i --
1028+ continue
10221029 }
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
10261033 }
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 [ ] = [ ]
10301037 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 ( ) ) )
10321039 for ( const properties of responses ) {
10331040 for ( const property of properties ) {
10341041 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+ } )
10371050 }
10381051 }
10391052 }
10401053 } else {
10411054 // Search all contexts
10421055 for ( const context of contexts ) {
1043- let response : xdebug . PropertyGetResponse | undefined ;
1056+ let response : xdebug . PropertyGetResponse | undefined
10441057 try {
1045- response = await frame . connection . sendPropertyGetCommand ( { context, fullName : containerName } ) ;
1058+ response = await frame . connection . sendPropertyGetCommand ( { context, fullName : containerName } )
10461059 } catch ( err ) {
10471060 // ignore
10481061 }
10491062 if ( response ) {
10501063 for ( const property of response . children ) {
10511064 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
10541067 if ( operator === '->' ) {
10551068 // Object
1056- type = 'property' ;
1069+ type = 'property'
10571070 } else if ( operator [ 0 ] === '[' ) {
10581071 // Array
10591072 if ( parseInt ( property . name ) + '' === property . name ) {
10601073 // Numeric index
10611074 if ( operator [ 1 ] === `'` ) {
1062- continue ;
1075+ continue
10631076 }
1064- type = 'value' ;
1065- text += ']' ;
1077+ type = 'value'
1078+ text += ']'
10661079 } else {
10671080 // String index
10681081 if ( operator [ 1 ] !== `'` ) {
10691082 if ( query ) {
1070- continue ;
1083+ continue
10711084 } else {
1072- text = `'` + text ;
1085+ text = `'` + text
10731086 }
10741087 }
1075- type = 'text' ;
1076- text += `']` ;
1088+ type = 'text'
1089+ text += `']`
10771090 }
10781091 }
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+ } )
10801099 }
10811100 }
10821101 // If we found the variable in one context (typically Locals), abort
1083- break ;
1102+ break
10841103 }
10851104 }
10861105 }
1087- response . body = { targets} ;
1106+ console . log ( `completionsRequest ${ args . text } (${ args . column } :${ args . line } ) ${ JSON . stringify ( targets ) } ` )
1107+ response . body = { targets }
10881108 } catch ( err ) {
1089- this . sendErrorResponse ( response , err ) ;
1090- return ;
1109+ this . sendErrorResponse ( response , err )
1110+ return
10911111 }
1092- this . sendResponse ( response ) ;
1112+ this . sendResponse ( response )
10931113 }
10941114
1095-
10961115 protected async continueRequest (
10971116 response : VSCodeDebugProtocol . ContinueResponse ,
10981117 args : VSCodeDebugProtocol . ContinueArguments
0 commit comments