microsoft / vscode-debugadapter-node

Debug adapter protocol and implementation for VS Code.
Other
273 stars 79 forks source link

Clarification: namedVariables vs indexedVariables #71

Closed felixfbecker closed 8 years ago

felixfbecker commented 8 years ago

What is the exact purpose of having these separate properties? For example, in PHP arrays are both indexed by number and by string, they are always mixed. What should I use?

weinand commented 8 years ago

The VS Code UI shows "namedVariables" first and then "indexedVariables" (broken into ranges). So if you have an array with 1000 items and three named properties VS Code shows them like this:

2016-10-17_11-35-32

You can take advantage of this in any way you want.

weinand commented 8 years ago

@roblourens FYI, this example does not yet work with node2

felixfbecker commented 8 years ago

@weinand Ah, okay. I tried to implement variable paging, but I was wondering why VS Code refused to do paged requests. Am I right assuming paging only works with indexedVariables? The problem is an array in PHP can have both string and numeric indexes, but every array also has an internal key order. There is no way to get all "named"/string index items first, XDebug will report them in the order they are in the array, you can only control the page and page size. So there is also no way to get the amount of indexed variables beforehand. Does that mean I cannot use paging? Because this would result in much better performance. Or should I just use indexedVariables for string keys as well? Is that valid?

weinand commented 8 years ago

@felixfbecker currently paging is only implemented for indexedVariables. The feature request for namedVariables is https://github.com/Microsoft/vscode/issues/13878.

You can include named slots in the 'indexedVariables' as well, but then you will no longer see the named keys. Assuming that the insertion order is preserved then the array from this example:

var a = [];
a.push(0);
a.push(1);
a["foo"] = "bar";
a.push(2);
a.push(3);

shows up as follows:

a: Array[5]
   [0]: 0
   [1]: 1
   [2]: "bar"
   [3]: 2
   [4]: 3

After https://github.com/Microsoft/vscode/issues/13878 has been implemented and 'namedVariables' is used the array looks like this:

a: Array[5]
   0: 0
   1: 1
   foo: "bar"
   3: 2
   4: 3

Is this what you would expect?

felixfbecker commented 8 years ago

Yes, that's it. Also +1 for not wrapping the key in square brackets, the brackets is just the operator and language-dependent, the key name should get displayed raw.