31i73 / atom-dbg

An Atom package - An interactive debugger frontend
https://atom.io/packages/dbg
MIT License
30 stars 4 forks source link

Property name can be expanded #21

Closed pablomayobre closed 7 years ago

pablomayobre commented 7 years ago

I have a slight issue, I'm working on a debugger for Lua, and in Lua the most used type is tables which are basically groups of key-value pairs, where both keys and values can be any value, even functions or tables.

So not only values can be expanded but keys too... Take this following example

key   = { 1, 2, 3 } --table: 0x018A3983
value = { 4, 5, 6 } --table: 0x018A3989

tab = {}
tab[key] = value

for k, v in pairs(tab) do
   print(k[1], k[2], k[3]) --prints: 1, 2, 3
   print(v[1], v[2], v[3]) --prints: 4, 5, 6
end

When I call getVariableChildren function on the tab variable it returns:

[{
  "name": "table: 0x018A3983",
  "type": "Table",
  "value": "table: 0x018A389",
  "expandable": true
}]

And when I call getVariableChildren on this it returns:

[
  {
    "name": 1,
    "type": "Number",
    "value": 4
  },
  {
    "name": 2,
    "type": "Number",
    "value": 5
  },
  {
    "name": 3,
    "type": "Number",
    "value": 6
  },
]

Which are the values inside of the value table. But there is no way to get the values inside of the key table. The proposal would be to have something like expandableName: true and somehow display that in the UI.

Also variables should have a nameType property that differentiates them, so for example I can have:

local t = {
   [1] = "A",
   ["1"] = "B"
}

And they would be represented like:

[
  {
    "name": 1,
    "nameType": "Number",
    "expandableName": false,

    "value": "A",
    "type": "String",
    "expandable": false
  },
  {
    "name": "1",
    "nameType": "String",
    "expandableName": false,

    "value": "B",
    "type": "String",
    "expandable": false
  }
]

And I should be able to get this information in getVariableChildren somehow instead of only the path to the variable separated by dots (since for the cases above they would both be the table.1)

pablomayobre commented 7 years ago

If this issue is fixed I'll be able to finish my Lua debuger!

vanossj commented 7 years ago

I think it would be great if there was a better way to display some basic programming structures (ex. arrays/lists, map/dict/tables). Its been mentioned before but no one has made them yet.

But to prevent this from being a blocking issue, would it make any sense to list the children of a table as a key value pair? Each pair would be expandable with a key and value children, which in turn are also expandable.

pablomayobre commented 7 years ago

Sounds really good @vanossj hadn't thought of that! I'll implement it that way for now, but this is for sure an enhancement to be done

ProPuke commented 7 years ago

As @vanossj said, I'd suggest supplying these to the debugger as key/value pairs, so they appear similar to:

image

So the children to the table would be a list of expandable rows, with a brief summary of the key and value as the name and value of each. Then each of the rows would have 2 children, "Key" and "Value", each holding the appropriate data.

I'm not how else you'd possibly display a structure like this (at least using a treeview); So it seems to me this isn't a missing feature, it just requires thinking about things differently.

But if I have missed something, or there's a better suggestion on how to display this kinda stuff then I'm all ears.

pablomayobre commented 7 years ago

This is the way to go yeah. Please close it if needed, or keep it around/add it to documentation for information's sake hahaha