Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function, event, and custom error signatures #130

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ And there is more to come 🙌 stay tuned!
![vscode-auditor-flaterra](https://user-images.githubusercontent.com/2865694/55907553-5db8d000-5bd7-11e9-8a11-8cef3964e284.gif)
* list all function signatures (human readable or json format)
![vscode-auditor-funcsigs](https://user-images.githubusercontent.com/2865694/55907153-3f9ea000-5bd6-11e9-8a47-e69a762963e9.gif)
* list all custom error signatures (human readable or json format)
* list all event signatures (human readable or json format)
* open remix in external browser

Please refer to the extension's contribution section to show an up-to-date list of commands.
Expand Down
66 changes: 65 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@
"onCommand:solidity-va.tools.flattenCandidates",
"onCommand:solidity-va.tools.function.signatures",
"onCommand:solidity-va.tools.function.signatures.json",
"onCommand:solidity-va.tools.function.signatures.forWorkspace",
"onCommand:solidity-va.tools.function.signatures.forWorkspace.json",
"onCommand:solidity-va.tools.error.signatures",
"onCommand:solidity-va.tools.error.signatures.json",
"onCommand:solidity-va.tools.error.signatures.forWorkspace",
"onCommand:solidity-va.tools.error.signatures.forWorkspace.json",
"onCommand:solidity-va.tools.event.signatures",
"onCommand:solidity-va.tools.event.signatures.json",
"onCommand:solidity-va.tools.event.signatures.forWorkspace",
"onCommand:solidity-va.tools.event.signatures.forWorkspace.json",
"onCommand:solidity-va.tools.remix.openExternal",
"onCommand:solidity-va.cockpit.explorer.refresh",
"onCommand:solidity-va.cockpit.topLevelContracts.refresh",
Expand Down Expand Up @@ -232,9 +241,54 @@
"title": "Tools - list function signatures (json)",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.function.signatures.forWorkspace",
"title": "Tools - list function signatures for workspace",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.function.signatures.forWorkspace.json",
"title": "Tools - list function signatures for all solidity files in workspace (json)",
"title": "Tools - list function signatures for workspace (json)",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.error.signatures",
"title": "Tools - list custom error signatures",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.error.signatures.json",
"title": "Tools - list custom error signatures (json)",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.error.signatures.forWorkspace",
"title": "Tools - list custom error signatures for workspace",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.error.signatures.forWorkspace.json",
"title": "Tools - list custom error signatures for workspace (json)",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.event.signatures",
"title": "Tools - list event signatures",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.event.signatures.json",
"title": "Tools - list event signatures (json)",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.event.signatures.forWorkspace",
"title": "Tools - list event signatures for workspace",
"category": "Solidity Visual Developer"
},
{
"command": "solidity-va.tools.event.signatures.forWorkspace.json",
"title": "Tools - list event signatures for workspace (json)",
"category": "Solidity Visual Developer"
},
{
Expand Down Expand Up @@ -443,6 +497,16 @@
"default": true,
"description": "Enable/Disable codelens 'funcSigs'"
},
"solidity-va.codelens.errorSigs.enable": {
"type": "boolean",
"default": true,
"description": "Enable/Disable codelens 'errorSigs'"
},
"solidity-va.codelens.eventSigs.enable": {
"type": "boolean",
"default": true,
"description": "Enable/Disable codelens 'eventSigs'"
},
"solidity-va.codelens.uml.enable": {
"type": "boolean",
"default": true,
Expand Down
90 changes: 90 additions & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,15 @@ function onActivate(context) {
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.function.signatures.forWorkspace',
function (doc) {
commands.listFunctionSignaturesForWorkspace(false);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.function.signatures.forWorkspace.json',
Expand All @@ -649,6 +658,87 @@ function onActivate(context) {
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.error.signatures',
function (doc, asJson) {
commands.listErrorSignatures(doc || vscode.window.activeTextEditor.document, asJson);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.error.signatures.json',
function (doc) {
commands.listErrorSignatures(doc || vscode.window.activeTextEditor.document, true);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.error.signatures.forWorkspace',
function (doc) {
commands.listErrorSignaturesForWorkspace(false);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.error.signatures.forWorkspace.json',
function (doc) {
commands.listErrorSignaturesForWorkspace(true);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.error.signatureForAstItem',
function (item) {
commands.listErrorSignatureForAstItem(item);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.event.signatures',
function (doc, asJson) {
commands.listEventSignatures(doc || vscode.window.activeTextEditor.document, asJson);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.event.signatures.json',
function (doc) {
commands.listEventSignatures(doc || vscode.window.activeTextEditor.document, true);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.event.signatures.forWorkspace',
function (doc) {
commands.listEventSignaturesForWorkspace(false);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.event.signatures.forWorkspace.json',
function (doc) {
commands.listEventSignaturesForWorkspace(true);
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'solidity-va.tools.remix.openExternal',
Expand Down
46 changes: 44 additions & 2 deletions src/features/codelens.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ class SolidityCodeLensProvider {
)
);

config.errorSigs.enable && codeLens.push(
new vscode.CodeLens(
firstLine, {
command: 'solidity-va.tools.error.signatures',
title: 'errorSigs',
arguments: [document]
}
)
);

config.eventSigs.enable && codeLens.push(
new vscode.CodeLens(
firstLine, {
command: 'solidity-va.tools.event.signatures',
title: 'eventSigs',
arguments: [document]
}
)
);

let parser = this.g_workspace.sourceUnits[document.uri.fsPath];
if(!parser) {
console.warn("[ERR] parser was not ready while adding codelenses. omitting contract specific lenses.");
Expand All @@ -134,7 +154,7 @@ class SolidityCodeLensProvider {
);


let annotateContractTypes = ["contract","library", "abstract"];
let annotateContractTypes = ["contract", "library", "abstract"];
/** all contract decls */
for(let contractObj of Object.values(parser.contracts)){
if(token.isCancellationRequested){
Expand All @@ -148,6 +168,12 @@ class SolidityCodeLensProvider {
for(let funcObj of contractObj.functions){
codeLens = codeLens.concat(this.onFunctionDecl(document, contractObj.name, funcObj));
}

for(let node of contractObj._node.subNodes){
if (node.type == 'CustomErrorDefinition') {
codeLens = codeLens.concat(this.onCustomErrorDecl(node));
}
}
} else if (contractObj._node.kind == "interface"){
// add uml to interface
let item = contractObj;
Expand Down Expand Up @@ -213,7 +239,7 @@ class SolidityCodeLensProvider {
})
);
//exclude constructor (item._node.name == null)
config.funcSigs.enable && item._node.name && lenses.push(new vscode.CodeLens(range, {
config.funcSigs.enable && item._node.name && ['public', 'external'].includes(item._node.visibility) && lenses.push(new vscode.CodeLens(range, {
command: 'solidity-va.tools.function.signatureForAstItem',
title: 'funcSig',
arguments: [item]
Expand All @@ -222,6 +248,22 @@ class SolidityCodeLensProvider {

return lenses;
}

onCustomErrorDecl(item) {
let lenses = [];
let range = elemLocToRange(item);

let config = settings.extensionConfig().codelens;

config.errorSigs.enable && lenses.push(new vscode.CodeLens(range, {
command: 'solidity-va.tools.error.signatureForAstItem',
title: 'errorSig',
arguments: [item]
})
);

return lenses;
}
}

module.exports = {
Expand Down
Loading