How to use surya - 7 common examples

To help you get started, we’ve selected a few surya examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
outTxt = ['No Dependencies Found'];
                    }
                    else {
                        ret.shift();
                        const reducer = (accumulator, currentValue) => `${accumulator}\n  ↖ ${currentValue}`;
                        outTxt.push(`  ↖ ${ret.reduce(reducer)}`);
                    }
                    

                    vscode.workspace.openTextDocument({content: outTxt.join("\n"), language: "markdown"})
                        .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                }
                break;
            case "ftrace":
                //  contract::func, all, files 
                ret = surya.ftrace(args[0], args[1] || 'all', files, {}, true);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "mdreport":
                ret = surya.mdreport(files);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => {
                        if(solidityVAConfig.preview.markdown){
                            vscode.commands.executeCommand("markdown-preview-enhanced.openPreview", doc.uri)
                                .catch(error => {
                                    //command does not exist
                                    vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
                                        .then(editor => {
                                            vscode.commands.executeCommand("markdown.extension.togglePreview")
                                            .catch(error => {
                                                //command does not exist
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
files = uris.map(function (uri) {
                        return uri.fsPath;
                    });
                });
        } else {
            files = [document.uri.fsPath, ...Object.keys(this.g_parser.sourceUnits)];  //better only add imported files. need to resolve that somehow
        } 

        switch(command) {
            case "describe":
                ret = surya.describe(files, {}, true);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "graph":
                ret = surya.graph(args || files, {colorScheme: suryaDefaultColorSchemeDark});
                //solidity-va.preview.render.markdown
                vscode.workspace.openTextDocument({content: ret, language: "dot"})
                    .then(doc => {
                        if(solidityVAConfig.preview.dot){
                            vscode.commands.executeCommand("interactive-graphviz.preview.beside", {document: doc, content:ret, callback:null})
                            .catch(error =>{
                                vscode.commands.executeCommand("graphviz.previewToSide", doc.uri)
                                .catch(error => {
                                    //command not available. fallback open as text and try graphviz.showPreview
                                    vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
                                        .then(editor => {
                                            vscode.commands.executeCommand("graphviz.showPreview", editor)  // creates new pane
                                                .catch(error => {
                                                    //command not available - do nothing
                                                });
                                        });
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
});
                                        });
                                });
                            });
                        } else {
                            vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
                        }
                        
                    });
                /*
                vscode.env.openExternal(vscode.Uri.file("/Users/tintin/workspace/vscode/solidity-auditor/images/icon.png"))
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside))
                    */
                break;
            case "inheritance":
                ret = surya.inheritance(files,{draggable:false});
                vscode.workspace.openTextDocument({content: ret, language: "dot"})
                    .then(doc => {
                        if(solidityVAConfig.preview.dot){
                            vscode.commands.executeCommand("interactive-graphviz.preview.beside", {document: doc, content:ret, callback:null})
                            .catch(error =>{
                                vscode.commands.executeCommand("graphviz.previewToSide", doc.uri)
                                .catch(error => {
                                    //command not available. fallback open as text and try graphviz.showPreview
                                    vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
                                        .then(editor => {
                                            vscode.commands.executeCommand("graphviz.showPreview", editor)  // creates new pane
                                                .catch(error => {
                                                    //command not available - do nothing
                                                });
                                        });
                                });
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
outTxt.push(`  ↖ ${ret.reduce(reducer)}`);
                    }
                    

                    vscode.workspace.openTextDocument({content: outTxt.join("\n"), language: "markdown"})
                        .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                }
                break;
            case "ftrace":
                //  contract::func, all, files 
                ret = surya.ftrace(args[0], args[1] || 'all', files, {}, true);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "mdreport":
                ret = surya.mdreport(files);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => {
                        if(solidityVAConfig.preview.markdown){
                            vscode.commands.executeCommand("markdown-preview-enhanced.openPreview", doc.uri)
                                .catch(error => {
                                    //command does not exist
                                    vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
                                        .then(editor => {
                                            vscode.commands.executeCommand("markdown.extension.togglePreview")
                                            .catch(error => {
                                                //command does not exist
                                            });
                                        });
                                });
                        } else {
                            vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
}
                        
                    });
                    /*
                let draggable = surya.inheritance(files,{draggable:true})
                console.error(draggable)
                createWebViewBesides('imgPreview','imgPreview',draggable)
                */
                break;
            case "parse":
                ret = surya.parse(document.uri.fsPath);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "dependencies":
                ret = surya.dependencies(files, args[0]);

                let outTxt = [];

                if(ret){
                    outTxt.push(ret[0]);
                
                    if (ret.length < 2) {
                        outTxt = ['No Dependencies Found'];
                    }
                    else {
                        ret.shift();
                        const reducer = (accumulator, currentValue) => `${accumulator}\n  ↖ ${currentValue}`;
                        outTxt.push(`  ↖ ${ret.reduce(reducer)}`);
                    }
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
});
                                });
                            });
                        } else {
                            vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside);
                        }
                        
                    });
                    /*
                let draggable = surya.inheritance(files,{draggable:true})
                console.error(draggable)
                createWebViewBesides('imgPreview','imgPreview',draggable)
                */
                break;
            case "parse":
                ret = surya.parse(document.uri.fsPath);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "dependencies":
                ret = surya.dependencies(files, args[0]);

                let outTxt = [];

                if(ret){
                    outTxt.push(ret[0]);
                
                    if (ret.length < 2) {
                        outTxt = ['No Dependencies Found'];
                    }
                    else {
                        ret.shift();
github ConsenSys / vscode-solidity-auditor / src / features / commands.js View on Github external
let files;

        if(solidityVAConfig.tools.surya.input.contracts=="workspace"){
            await vscode.workspace.findFiles("**/*.sol",'**/node_modules', 500)
                .then(uris => {
                    files = uris.map(function (uri) {
                        return uri.fsPath;
                    });
                });
        } else {
            files = [document.uri.fsPath, ...Object.keys(this.g_parser.sourceUnits)];  //better only add imported files. need to resolve that somehow
        } 

        switch(command) {
            case "describe":
                ret = surya.describe(files, {}, true);
                vscode.workspace.openTextDocument({content: ret, language: "markdown"})
                    .then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside));
                break;
            case "graph":
                ret = surya.graph(args || files, {colorScheme: suryaDefaultColorSchemeDark});
                //solidity-va.preview.render.markdown
                vscode.workspace.openTextDocument({content: ret, language: "dot"})
                    .then(doc => {
                        if(solidityVAConfig.preview.dot){
                            vscode.commands.executeCommand("interactive-graphviz.preview.beside", {document: doc, content:ret, callback:null})
                            .catch(error =>{
                                vscode.commands.executeCommand("graphviz.previewToSide", doc.uri)
                                .catch(error => {
                                    //command not available. fallback open as text and try graphviz.showPreview
                                    vscode.window.showTextDocument(doc, vscode.ViewColumn.Beside)
                                        .then(editor => {

surya

Sūrya, The Sun God: A set of utilities for inspecting the structure of Solidity contracts.

Apache-2.0
Latest version published 2 months ago

Package Health Score

76 / 100
Full package analysis