Skip to content

Commit

Permalink
Merge pull request #48 from ConsenSys/feat/cockpit_ftrace
Browse files Browse the repository at this point in the history
new feature - ftrace & flatfiles in cockpit view
  • Loading branch information
tintinweb authored May 6, 2020
2 parents e075488 + 47264ca commit 2fc0422
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to the "solidity-visual-auditor" extension will be documented in this file.

## v0.0.24
- new: Solidity Visual Auditor Cockpit panel additions
- Context: show surya ftrace when clicking at a method in the editor
- Flatfiles: List files prefixed `**/flat_*.sol`

## v0.0.23
- new: Update notifications have arrived!
- updated: solidity parser and surya
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"compiler",
"security"
],
"version": "0.0.23",
"version": "0.0.24",
"publisher": "tintinweb",
"icon": "images/icon.png",
"engines": {
Expand Down Expand Up @@ -114,17 +114,15 @@
},
{
"id": "solidity-va-cockpit-flatFiles",
"name": "Workspace: */flat_* Files",
"when": "ONLY_BETA"
"name": "Workspace: */flat_* Files"
},
{
"id": "solidity-va-cockpit-publicMethods",
"name": "Context: Public StateChanging Methods"
},
{
"id": "solidity-va-cockpit-ftrace",
"name": "Context: Function Call Trace",
"when": "ONLY_BETA"
"name": "Context: Function Call Trace"
},
{
"id": "solidity-va-cockpit-settings",
Expand Down Expand Up @@ -433,6 +431,6 @@
"c3-linearization": "^0.3.0",
"keccak": "^2.0.0",
"solidity-parser-diligence": "0.4.18",
"surya": "0.3.6-dev.8"
"surya": "0.3.6-dev.9"
}
}
55 changes: 45 additions & 10 deletions src/features/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,56 @@ class FTraceViewDataProvider extends BaseDataProvider {
this._onDidChangeTreeData = new vscode.EventEmitter();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;

this.data = null;
this.data = null; //json {item: {a:object, b:object, c:object}}
this.documentUri = null;
}

async dataGetRoot(){
if(this.data === null || this.documentUri === null){
return [];
}
return this.data.map(k => {
return Object.keys(this.data).map(k => {
let children = typeof this.data[k] === "object" ? this.data[k] : {};
return {
children: children,
resource: this.documentUri, //uri
label: k,
tooltip: k,
name: k,
parent: null,
iconPath: vscode.ThemeIcon.File,
collapsibleState: children && Object.keys(children).length > 0 ? vscode.TreeItemCollapsibleState.Expanded : 0,
};
});
}

dataGetChildren(){
return null; //no children :)
dataGetChildren(element){
if(!element) {
return this.data;
}

if(!element.children){
return [];
}
// element provided? -
return Object.keys(element.children).map(k => {
let children = typeof element.children[k] === "object" ? element.children[k] : {};
return {
children: children,
resource: this.documentUri, //uri
label: k,
tooltip: k,
name: k,
parent: null,
iconPath: vscode.ThemeIcon.File,
collapsibleState: children && Object.keys(children).length > 0 ? vscode.TreeItemCollapsibleState.Expanded : 0,
};
});
}


dataGetParent(element){
return element.parent;
}

/** events */
Expand Down Expand Up @@ -435,8 +463,6 @@ class FTraceView extends BaseView {

let functionName = focusSolidityElement.function._node.name;



let files;
if(settings.extensionConfig().tools.surya.input.contracts=="workspace"){
await vscode.workspace.findFiles("**/*.sol", settings.DEFAULT_FINDFILES_EXCLUDES, 500)
Expand All @@ -456,18 +482,27 @@ class FTraceView extends BaseView {
functionName = "<Fallback>";
}

let ret = surya.ftrace(contractName + "::" + functionName, 'all', files, {}, true).trim();
let lines = ret.match(/^.*((\r\n|\n|\r)|$)/gm);
let retj = surya.ftrace(contractName + "::" + functionName, 'all', files, {jsonOutput: true}, true);
this.dataProvider.documentUri = documentUri;
this.dataProvider.data = lines;
this.dataProvider.data = retj;
this.refresh();
}
}

/* Methods View */


class PublicMethodsViewDataProvider extends FTraceViewDataProvider {
class PublicMethodsViewDataProvider extends BaseDataProvider {

constructor(treeView){
super();
this.treeView = treeView;
this._onDidChangeTreeData = new vscode.EventEmitter();
this.onDidChangeTreeData = this._onDidChangeTreeData.event;

this.data = null;
this.documentUri = null;
}

async dataGetRoot(){
if(this.data === null || this.documentUri === null){
Expand Down
2 changes: 1 addition & 1 deletion src/features/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Commands{
*/
break;
case "parse":
ret = surya.parse(document.uri.fsPath);
ret = surya.parse(documentOrListItems.uri.fsPath);
vscode.workspace.openTextDocument({content: ret, language: "markdown"})
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
break;
Expand Down
1 change: 1 addition & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
/**
* @author github.com/tintinweb
* @license MIT
Expand Down

0 comments on commit 2fc0422

Please sign in to comment.