Skip to content

Commit 95e0764

Browse files
committed
Rebase and fix code changes.
1 parent 98bd782 commit 95e0764

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Options specific to CLI debugging:
114114
- Stack traces, scope variables, superglobals, user defined constants
115115
- Arrays & objects (including classname, private and static properties)
116116
- Debug console
117-
- Autocompletion in debug console for variables, array indexes, object properties (even nested)
117+
- Autocompletion in debug console for variables, array indexes, object properties (even nested)
118118
- Watches
119119
- Run as CLI
120120
- Run without debugging

src/phpDebug.ts

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/test/adapter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ describe('PHP Debug Adapter', () => {
679679
})
680680

681681
describe('completion', () => {
682-
it('should provide completion for local variables');
683-
it('should provide completion for superglobals');
684-
it('should provide completion for object properties');
685-
it('should provide completion for numeric array indexes');
686-
it('should provide completion for string array indexes');
687-
});
682+
it('should provide completion for local variables')
683+
it('should provide completion for superglobals')
684+
it('should provide completion for object properties')
685+
it('should provide completion for numeric array indexes')
686+
it('should provide completion for string array indexes')
687+
})
688688

689689
describe.skip('output events', () => {
690690
const program = path.join(TEST_PROJECT, 'output.php')

src/xdebugConnection.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,12 @@ export class PropertyGetResponse extends Response {
632632
children: Property[]
633633
/**
634634
* @param {XMLDocument} document
635-
* @param {Property} property
635+
* @param {Context} context
636636
*/
637-
constructor(document: XMLDocument, property: Property) {
638-
super(document, property.context.stackFrame.connection)
637+
constructor(document: XMLDocument, context: Context) {
638+
super(document, context.stackFrame.connection)
639639
this.children = Array.from(document.documentElement.firstChild!.childNodes).map(
640-
(propertyNode: Element) => new Property(propertyNode, property.context)
640+
(propertyNode: Element) => new Property(propertyNode, context)
641641
)
642642
}
643643
}
@@ -1022,14 +1022,14 @@ export class Connection extends DbgpConnection {
10221022
}
10231023

10241024
/** Sends a property_get command */
1025-
public async sendPropertyGetCommand(property: Property): Promise<PropertyGetResponse> {
1025+
public async sendPropertyGetCommand(property: {context: Context, fullName: string}): Promise<PropertyGetResponse> {
10261026
const escapedFullName = '"' + property.fullName.replace(/("|\\)/g, '\\$1') + '"'
10271027
return new PropertyGetResponse(
10281028
await this._enqueueCommand(
10291029
'property_get',
10301030
`-d ${property.context.stackFrame.level} -c ${property.context.id} -n ${escapedFullName}`
10311031
),
1032-
property
1032+
property.context
10331033
)
10341034
}
10351035

0 commit comments

Comments
 (0)