Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3354 from trufflesuite/sections
Browse files Browse the repository at this point in the history
Enhancement: Group variables by section in debugger
  • Loading branch information
haltman-at authored Sep 10, 2020
2 parents e9c30d7 + dd57958 commit acf10c0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
47 changes: 25 additions & 22 deletions packages/core/lib/debug/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,33 +480,36 @@ class DebugPrinter {
}

async printVariables() {
let variables = await this.session.variables();

debug("variables %o", variables);
const values = await this.session.variables();
const sections = this.session.view(data.current.identifiers.sections);

const variableKeys = Object.keys(variables);

// Get the length of the longest name.
const longestNameLength = variableKeys.reduce((longest, name) => {
return name.length > longest ? name.length : longest;
}, -Infinity);
const sectionNames = {
builtin: "Solidity built-ins",
contract: "Contract variables",
local: "Local variables"
};

this.config.logger.log();

variableKeys.forEach(name => {
let paddedName = name + ":";

while (paddedName.length <= longestNameLength) {
paddedName = " " + paddedName;
for (const [section, variables] of Object.entries(sections)) {
if (variables.length > 0) {
this.config.logger.log(sectionNames[section] + ":");
// Get the length of the longest name.
const longestNameLength = variables.reduce((longest, name) => {
return name.length > longest ? name.length : longest;
}, -Infinity);
for (const variable of variables) {
const paddedName = variable.padStart(longestNameLength) + ":";
const value = values[variable];
const formatted = DebugUtils.formatValue(
value,
longestNameLength + 5
);
this.config.logger.log(" " + paddedName, formatted);
}
this.config.logger.log();
}

const value = variables[name];
const formatted = DebugUtils.formatValue(value, longestNameLength + 5);

this.config.logger.log(" " + paddedName, formatted);
});

this.config.logger.log();
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions packages/debugger/lib/data/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,37 @@ const data = createSelectorTree({
)
},

/**
* data.current.identifiers.sections
* intended for use by Teams Debugger
*/
sections: createLeaf(["./refs"], refs => {
let sections = {
builtin: [],
contract: [],
local: []
};
for (const [identifier, ref] of Object.entries(refs)) {
switch (ref.location) {
case "special":
sections.builtin.push(identifier);
break;
case "stack":
sections.local.push(identifier);
break;
case "storage":
case "code":
case "nowhere":
case "memory":
case "definition":
sections.contract.push(identifier);
break;
//other cases shouldn't happen
}
}
return sections;
}),

/**
* data.current.identifiers.refs
*
Expand Down

0 comments on commit acf10c0

Please sign in to comment.