Skip to content

Commit

Permalink
Merge pull request #65 from ConsenSys/maintenance/decorations
Browse files Browse the repository at this point in the history
maintenance: improve performance of decorating documents and add an option to disable the reference provider
  • Loading branch information
tintinweb authored Jan 8, 2021
2 parents e5ec683 + 2ab757c commit 3dea1e4
Show file tree
Hide file tree
Showing 10 changed files with 853 additions and 499 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
# Change Log

## v0.0.31

Happy new year 👪🌃🥂🎇!

- new: allow to disable the "find references" provider
- `preferences → Settings → Solidity Visual Developer: solidity-va.findAllReferences.enable`
- in case another extension implements a better provider someday :)
- new: experimental draw.io uml export to support your threat modelling needs (you're going to ❤ this!)
- disabled by default
- `preferences → Settings → Solidity Visual Developer: solidity-va.codelens.drawio.enable`
- fix: function signature generation for `AbiEncoderV2` functions that declare custom types
- for now this falls back to assume every custom type is an `address`. needs some love if this feature is actually being used.
- refactor: modular uml export
- refactor: improved syntax highlighting / decoration performance
- only decorates when needed, avoid double decoration
- should fix or make it unlikely that decorations are being applied to the wrong editor - fixes #12
- update: dependencies
- surya
- solidity parser
- keccak

## v0.0.30
- new: We've finally implemented support for `Right Click → Find All References` for solidity source files!
- Please note that this currently performs a lexical search of all source-code files containing the word under the cursor (including comments). This may be subject to change to return more specific results in the future.
<br><img width="360" alt="image" src="https://user-images.githubusercontent.com/2865694/94445596-eb132a00-01a7-11eb-9098-32958d58ebd6.gif">

- update: dependencies surya / solidity parser


## v0.0.29
- sort top level contracts list by filename
- fix: VSCode-Error: Proposed API is only available when running out of dev or with the following command line switch... #59
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
This extension contributes **security centric** syntax and semantic highlighting, a detailed class outline, specialized views, advanced Solidity code insights and augmentation to Visual Studio Code.


**Note**: Almost anything can be customized/disabled in the extension settings. Make this extension fit your needs!


We ❤ feedback → [get in touch!](https://github.com/tintinweb/vscode-solidity-auditor/issues)

____
Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"solidity security",
"solidity audit"
],
"version": "0.0.30",
"version": "0.0.31",
"publisher": "tintinweb",
"icon": "images/icon.png",
"engines": {
Expand Down Expand Up @@ -408,6 +408,16 @@
"default": true,
"description": "Enable/Disable codelens - inline action"
},
"solidity-va.findAllReferences.enable": {
"type": "boolean",
"default": true,
"description": "Enable/Disable right-click -> Find All References. Note: This allows you to disable the built-in reference provider in favor of one of another extension. Takes effect after restart."
},
"solidity-va.codelens.drawio.enable": {
"type": "boolean",
"default": false,
"description": "Enable/Disable draw.io uml export"
},
"solidity-va.mode.active": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -450,9 +460,9 @@
"tintinweb.vscode-ethover"
],
"dependencies": {
"@solidity-parser/parser": "^0.8.1",
"@solidity-parser/parser": "^0.11.0",
"c3-linearization": "^0.3.0",
"keccak": "^2.0.0",
"surya": "^0.4.1"
"keccak": "^3.0.1",
"surya": "^0.4.2"
}
}
776 changes: 403 additions & 373 deletions src/extension.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/features/codelens.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* */
const vscode = require('vscode');
const settings = require('../settings.js');

/*
await window.showInputBox({prompt: 'prompt for something',})
Expand Down Expand Up @@ -122,6 +123,15 @@ class SolidityCodeLensProvider {
})
);

if(settings.extensionConfig().codelens.drawio.enable){
codeLens.push(new vscode.CodeLens(firstLine, {
command: 'solidity-va.uml.contract.export.drawio.csv',
title: 'draw.io',
arguments: [document, Object.values(parser.contracts)]
})
);
}

let annotateContractTypes = ["contract","library"];
/** all contract decls */
for(let name in parser.contracts){
Expand Down Expand Up @@ -174,6 +184,15 @@ class SolidityCodeLensProvider {
arguments: [document, [item]]
})
);

if(settings.extensionConfig().codelens.drawio.enable){
lenses.push(new vscode.CodeLens(range, {
command: 'solidity-va.uml.contract.export.drawio.csv',
title: 'draw.io',
arguments: [document, [item]]
})
);
}

return lenses;
}
Expand Down
137 changes: 17 additions & 120 deletions src/features/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ const path = require('path');
const settings = require('../settings');

const mod_templates = require('./templates');
const mod_utils = require('./utils.js');
const mod_symbols = require('./symbols.js');
const mod_utils = require('./utils');


const { DrawIoCsvWriter } = require('./writer/drawio');
const { PlantumlWriter } = require('./writer/plantuml');

const surya = require('surya');



const suryaDefaultColorSchemeDark = {
digraph : {
bgcolor: "#2e3e56",
Expand Down Expand Up @@ -462,7 +466,7 @@ ${topLevelContractsText}`;
// takes object key=contractName value=fsPath
let topLevelContracts = candidates || await this._findTopLevelContracts();
let content = "";
let trufflepath = undefined;
let trufflepath;


this.solidityFlattener(Object.values(topLevelContracts), (filepath, trufflepath, content) => {
Expand Down Expand Up @@ -571,126 +575,19 @@ ${topLevelContractsText}`;
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
}

async umlContractsOutline(contractObjects) {
const stateMutabilityToIcon = {
view:"🔍",
pure:"🔍",
constant:"🔍",
payable:"💰"
};

const functionVisibility = {
"public": '+',
"external": '+', //~
"internal": '#', //mapped to protected; ot
"private": '-' ,
"default": '+' // public
};
const variableVisibility = {
"public": '+',
"external": '+', //~
"internal": '#', //mapped to protected; ot
"private": '-' ,
"default": "#" // internal
};
const contractNameMapping = {
"contract":"class",
"interface":"interface",
"library":"abstract"
};

function _mapAstFunctionName(name) {
switch(name) {
case null:
return "**__constructor__**";
case "":
return "**__fallback__**";
default:
return name;
}
}

let content = `@startuml
' -- for auto-render install: https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml
' -- options --
${settings.extensionConfig().uml.options}
${settings.extensionConfig().uml.actors.enable ? "allowmixing": ""}
' -- classes --
`;
async drawioContractsOutlineAsCSV(contractObj) {

content += contractObjects.reduce((umlTxt, contractObj) => {
const writer = new DrawIoCsvWriter();
const content = writer.export(contractObj);

return umlTxt + `\n
${contractNameMapping[contractObj._node.kind] || "class"} ${contractObj.name} {
' -- inheritance --
${Object.values(contractObj.dependencies).reduce((txt, name) => {
return txt + `\t{abstract}${name}\n`;
},"")
}
' -- usingFor --
${Object.values(contractObj.usingFor).reduce((txt, astNode) => {
return txt + `\t{abstract}📚${astNode.libraryName} for [[${mod_symbols.getVariableDeclarationType(astNode)}]]\n`;
},"")
}
' -- vars --
${Object.values(contractObj.stateVars).reduce((umlSvarTxt, astNode) => {
return umlSvarTxt + `\t${variableVisibility[astNode.visibility] || ""}${astNode.isDeclaredConst?"{static}":""}[[${mod_symbols.getVariableDeclarationType(astNode).replace(/\(/g,"").replace(/\)/g,"")}]] ${astNode.name}\n`;
}, "")
}
' -- methods --
${Object.values(contractObj.functions).reduce((umlFuncTxt, funcObj) => {
return umlFuncTxt + `\t${functionVisibility[funcObj._node.visibility] || ""}${stateMutabilityToIcon[funcObj._node.stateMutability]||""}${_mapAstFunctionName(funcObj._node.name)}()\n`;
}, "")
}
}
`;
}, "");

content += "' -- inheritance / usingFor --\n" + contractObjects.reduce((umlTxt, contractObj) => {
return umlTxt
+ Object.values(contractObj.dependencies).reduce((txt, name) => {
return txt + `${contractObj.name} --[#DarkGoldenRod]|> ${name}\n`;
}, "")
+ Object.values(contractObj.usingFor).reduce((txt, astNode) => {
return txt + `${contractObj.name} ..[#DarkOliveGreen]|> ${astNode.libraryName} : //for ${mod_symbols.getVariableDeclarationType(astNode)}//\n`;
}, "");
}, "");


if(settings.extensionConfig().uml.actors.enable){
//lets see if we can get actors as well :)

let addresses = [];

for (let contractObj of contractObjects) {
addresses = addresses.concat(Object.values(contractObj.stateVars).filter(astNode => !astNode.isDeclaredConst && astNode.typeName.name =="address").map(astNode => astNode.name));
for (let fidx in contractObj.functions){
let functionObj = contractObj.functions[fidx];
addresses = addresses.concat(Object.values(functionObj.arguments).filter(astNode => astNode.typeName.name =="address").map(astNode => astNode.name));
}
}

let actors = [...new Set(addresses)];
actors = actors.filter( item => {
if (item === null) {
return false;
} // no nulls
if (item.startsWith("_") && actors.indexOf(item.slice(1))) {
return false;
} // no _<name> dupes
return true;
});

content += `
' -- actors --
together {
${actors.reduce((txt, name) => txt + `\tactor ${name}\n`, "")}
}
`;
}
vscode.workspace.openTextDocument({content: content, language: "csv"})
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
}

content += "\n@enduml";
async umlContractsOutline(contractObjects) {
await this.drawioContractsOutlineAsCSV(contractObjects);
let writer = new PlantumlWriter();
const content = writer.export(contractObjects);

vscode.workspace.openTextDocument({content: content, language: "plantuml"})
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
Expand Down
4 changes: 2 additions & 2 deletions src/features/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function functionSignatureExtractor(content) {

function getCanonicalizedArgumentFromAstNode(node){
let arraySuffix = '';

if (typeof node.typeName != "undefined"){
if (node.typeName.type=="ArrayTypeName") {
//is array
Expand All @@ -106,7 +105,8 @@ function getCanonicalizedArgumentFromAstNode(node){
if(node.type=="ElementaryTypeName"){
return node.name + arraySuffix;
} else if (node.type=="UserDefinedTypeName"){
return node.namePath + arraySuffix;
// TODO: assumes address which is not correct. this might as well unwind to an elementary type but that needs more effort to resolve.
return "address" + arraySuffix; //assume address instead of resolving node.namePath
} else {
return null;
}
Expand Down
22 changes: 22 additions & 0 deletions src/features/whatsnew/whatsNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,32 @@ const MESSAGE = `[<img width="130" alt="get in touch with Consensys Diligence" s
Thanks for using **Solidity Visual Developer** 🤜🤛
**Note**: Almost anything can be customized/disabled in the extension settings. Make this extension fit your needs!
### What's New?
The complete changelog can be found [here](https://github.com/ConsenSys/vscode-solidity-auditor/blob/master/CHANGELOG.md).
#### v0.0.31
Happy new year from your [Diligence Family](https://consensys.net/diligence) 🙌 👪🌃🥂🎇!
- new: optionally disable the "find references" provider
- \`preferences → Settings → Solidity Visual Developer: solidity-va.findAllReferences.enable\`
- new: experimental [draw.io](https://draw.io) uml export to support your threat modelling needs (you're going to ❤ this!)
- experimental feature, you'll have to manually enable this
- \`preferences → Settings → Solidity Visual Developer: solidity-va.codelens.drawio.enable\`
- fix: function signature generation for \`AbiEncoderV2\` functions that declare custom types
- for now this falls back to assume every custom type is an \`address\`. may need more love if there's support for this feature.
- refactor: modular uml export
- refactor: improved syntax highlighting / decoration performance
- only decorates when needed, avoid double decoration
- should fix or make it unlikely that decorations are being applied to the wrong editor - fixes #12
- update: dependencies
- surya
- solidity parser
- keccak
#### v0.0.30
- new: We've finally implemented support for \`Right Click → Find All References\` for solidity source files!
- Please note that this currently performs a lexical search of all source-code files containing the word under the cursor (including comments). This may be subject to change to return more specific results in the future.
Expand Down
Loading

0 comments on commit 3dea1e4

Please sign in to comment.