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

Commit

Permalink
Print variables by section in CLI debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Sep 9, 2020
1 parent 2e77ad2 commit dd57958
Showing 1 changed file with 25 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 @@ -478,33 +478,36 @@ class DebugPrinter {
}

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

debug("variables %o", variables);

const variableKeys = Object.keys(variables);
const values = await this.session.variables();
const sections = this.session.view(data.current.identifiers.sections);

// 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

0 comments on commit dd57958

Please sign in to comment.