Made value arrays parsable by vscode

This commit is contained in:
WebFreak001 2016-02-27 20:08:28 +01:00
commit 2cb16e2b9e
2 changed files with 62 additions and 28 deletions

View file

@ -65,7 +65,7 @@ export function expandValue(variableCreate: Function, value: string): any {
return str; return str;
}; };
let parseValue, parseCommaResult, parseCommaValue, parseResult; let parseValue, parseCommaResult, parseCommaValue, parseResult, createValue;
let parseTupleOrList = () => { let parseTupleOrList = () => {
value = value.trim(); value = value.trim();
@ -84,10 +84,11 @@ export function expandValue(variableCreate: Function, value: string): any {
if (newValPos != -1 && eqPos > newValPos || eqPos == -1) { // is value list if (newValPos != -1 && eqPos > newValPos || eqPos == -1) { // is value list
let values = []; let values = [];
let val = parseValue(); let val = parseValue();
values.push(val); values.push(createValue("[0]", val));
let remaining = value; let remaining = value;
let i = 0;
while (val = parseCommaValue()) while (val = parseCommaValue())
values.push(val); values.push(createValue("[" + (++i) + "]", val));
value = value.substr(1).trim(); // } value = value.substr(1).trim(); // }
return values; return values;
} }
@ -163,17 +164,21 @@ export function expandValue(variableCreate: Function, value: string): any {
value = value.substr(variableMatch[0].length).trim(); value = value.substr(variableMatch[0].length).trim();
let variable = variableMatch[1]; let variable = variableMatch[1];
let val = parseValue(); let val = parseValue();
return createValue(variable, val);
};
createValue = (name, val) => {
let ref = 0; let ref = 0;
if (typeof val == "object") { if (typeof val == "object") {
ref = variableCreate(val); ref = variableCreate(val);
val = "Object"; val = "Object";
} }
if (typeof val == "string" && val.startsWith("*0x")) { if (typeof val == "string" && val.startsWith("*0x")) {
ref = variableCreate("*" + variable); ref = variableCreate("*" + name);
val = "Object@" + val; val = "Object@" + val;
} }
return { return {
name: variable, name: name,
value: val, value: val,
variablesReference: ref variablesReference: ref
}; };

View file

@ -27,15 +27,38 @@ suite("GDB Value Expansion", () => {
}]); }]);
assert.strictEqual(isExpandable(`{{a = b}}`), 1); assert.strictEqual(isExpandable(`{{a = b}}`), 1);
assert.deepEqual(expandValue(variableCreate, `{{a = b}}`), [ assert.deepEqual(expandValue(variableCreate, `{{a = b}}`), [
[ {
{ name: "[0]",
name: "a", value: "Object",
value: "b", variablesReference: {
variablesReference: 0 expanded: [
{
name: "a",
value: "b",
variablesReference: 0
}
]
} }
] }
]); ]);
assert.deepEqual(expandValue(variableCreate, `{1, 2, 3, 4}`), [1, 2, 3, 4]); assert.deepEqual(expandValue(variableCreate, `{1, 2, 3, 4}`), [
{
name: "[0]",
value: "1",
variablesReference: 0
}, {
name: "[1]",
value: "2",
variablesReference: 0
}, {
name: "[2]",
value: "3",
variablesReference: 0
}, {
name: "[3]",
value: "4",
variablesReference: 0
}]);
}); });
test("Error values", () => { test("Error values", () => {
assert.strictEqual(isExpandable(`<No data fields>`), 0); assert.strictEqual(isExpandable(`<No data fields>`), 0);
@ -90,23 +113,29 @@ suite("GDB Value Expansion", () => {
value: "Object", value: "Object",
variablesReference: { variablesReference: {
expanded: [ expanded: [
[ {
{ name: "[0]",
name: "view", value: "Object",
value: "Object@*0x7ffff7ece1e8", variablesReference: {
variablesReference: { expanded: "*view" } expanded: [
}, {
{ name: "view",
name: "renderer", value: "Object@*0x7ffff7ece1e8",
value: "Object@*0x7ffff7eccc50", variablesReference: { expanded: "*view" }
variablesReference: { expanded: "*renderer" } },
}, {
{ name: "renderer",
name: "world", value: "Object@*0x7ffff7eccc50",
value: "Object@*0x7ffff7ece480", variablesReference: { expanded: "*renderer" }
variablesReference: { expanded: "*world" } },
{
name: "world",
value: "Object@*0x7ffff7ece480",
variablesReference: { expanded: "*world" }
}
]
} }
] }
] ]
} }
}, },