From b208b27f92843d6177c1c5b01a60980a4054a52f Mon Sep 17 00:00:00 2001 From: tintinweb Date: Mon, 25 Nov 2019 14:03:40 +0100 Subject: [PATCH] fix misused promises prepare 0.0.8 --- CHANGELOG.md | 3 ++ README.md | 3 ++ package.json | 2 +- src/extension.js | 33 ++++---------- src/features/compile.js | 90 +++++++++++++++++++------------------- src/features/signatures.js | 3 +- 6 files changed, 62 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e277ba6..ee0c267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 0.0.8 +- fix misused promises + ## 0.0.7 - updated grammar - fixed mythX issue due to API change diff --git a/README.md b/README.md index 60ef641..2fa48b0 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,9 @@ Note: Active features can be disabled by setting `Settings` → `Vyper` → `Mod see [CHANGELOG](./CHANGELOG.md) +## 0.0.8 +- fix misused promises + ## 0.0.7 - updated grammar - fixed mythX issue due to API change diff --git a/package.json b/package.json index 2220a46..cd09a18 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-vyper", "displayName": "Vyper", "description": "Ethereum Vyper language support for Visual Studio Code", - "version": "0.0.7", + "version": "0.0.8", "keywords": [ "vyper", "ethereum", diff --git a/src/extension.js b/src/extension.js index b64e6ac..a2b181a 100644 --- a/src/extension.js +++ b/src/extension.js @@ -1,3 +1,4 @@ +'use strict' /** * @author github.com/tintinweb * @license MIT @@ -28,30 +29,22 @@ var activeEditor; /** event funcs */ async function onDidSave(document){ - return new Promise((reject,resolve) =>{ - - if(document.languageId!=VYPER_ID){ - console.log("langid mismatch") - reject("langid_mismatch") - return; - } + if(document.languageId!=VYPER_ID){ + console.log("langid mismatch") + return; + } - //always run on save - - if(vyperConfig.compile.onSave){ - resolve(mod_compile.compileContractCommand(document.uri)) - } - }) + //always run on save + if(vyperConfig.compile.onSave){ + mod_compile.compileContractCommand(document.uri) + } } async function onDidChange(event) { - return new Promise((reject,resolve) => { if(vscode.window.activeTextEditor.document.languageId!=VYPER_ID){ - reject("langid_mismatch") return; } - console.log("onDidChange ...") if(vyperConfig.decoration.enable){ mod_deco.decorateWords(activeEditor, [ { @@ -99,11 +92,6 @@ async function onDidChange(event) { }, ], mod_deco.styles.boldUnderline); } - - - console.log("✓ onDidChange") - resolve() - }); } function onInitModules(context, type) { mod_hover.init(context, type, vyperConfig) @@ -117,8 +105,6 @@ function onActivate(context) { if (!active || !active.document) return; activeEditor = active; - console.log(" activate extension: vyper ...") - registerDocType(VYPER_ID); function registerDocType(type) { @@ -186,7 +172,6 @@ function onActivate(context) { } - console.log("✓ activate extension: vyper") } /* exports */ diff --git a/src/features/compile.js b/src/features/compile.js index 0e58ec8..a3866de 100644 --- a/src/features/compile.js +++ b/src/features/compile.js @@ -167,51 +167,6 @@ compileVyper.necessary = function(options, callback) { function compileActiveFileCommand(contractFile) { compileActiveFile(contractFile) .then( - (errormsg) => { - diagnosticCollections.compiler.delete(contractFile); - diagnosticCollections.mythx.delete(contractFile); - vscode.window.showErrorMessage('[Compiler Error] ' + errormsg); - let lineNr = 1; // add default errors to line 0 if not known - let matches = /(?:line\s+(\d+))/gm.exec(errormsg) - if (matches && matches.length==2){ - //only one line ref - lineNr = parseInt(matches[1]) - } - - let lines = errormsg.split(/\r?\n/) - console.log(errormsg) - let shortmsg = lines[0] - - // IndexError - if (lines.indexOf("SyntaxError: invalid syntax") > -1) { - let matches = /line (\d+)/gm.exec(errormsg) - if (matches.length >= 2) { - lineNr = parseInt(matches[1]) - } - shortmsg = "SyntaxError: invalid syntax"; - } else { - //match generic vyper exceptions - let matches = /vyper\.exceptions\.\w+Exception:\s+(?:line\s+(\d+)).*$/gm.exec(errormsg) - if (matches && matches.length > 0) { - shortmsg = matches[0] - if (matches.length >= 2) { - lineNr = parseInt(matches[1]) - } - } - - - } - if (errormsg) { - diagnosticCollections.compiler.set(contractFile, [{ - code: '', - message: shortmsg, - range: new vscode.Range(new vscode.Position(lineNr - 1, 0), new vscode.Position(lineNr - 1, 255)), - severity: vscode.DiagnosticSeverity.Error, - source: errormsg, - relatedInformation: [] - }]); - } - }, (success) => { diagnosticCollections.compiler.delete(contractFile); diagnosticCollections.mythx.delete(contractFile); @@ -283,6 +238,49 @@ function compileActiveFileCommand(contractFile) { }) } } + }, + (errormsg) => { + diagnosticCollections.compiler.delete(contractFile); + diagnosticCollections.mythx.delete(contractFile); + vscode.window.showErrorMessage('[Compiler Error] ' + errormsg); + let lineNr = 1; // add default errors to line 0 if not known + let matches = /(?:line\s+(\d+))/gm.exec(errormsg) + if (matches && matches.length==2){ + //only one line ref + lineNr = parseInt(matches[1]) + } + + let lines = errormsg.split(/\r?\n/) + console.log(errormsg) + let shortmsg = lines[0] + + // IndexError + if (lines.indexOf("SyntaxError: invalid syntax") > -1) { + let matches = /line (\d+)/gm.exec(errormsg) + if (matches.length >= 2) { + lineNr = parseInt(matches[1]) + } + shortmsg = "SyntaxError: invalid syntax"; + } else { + //match generic vyper exceptions + let matches = /vyper\.exceptions\.\w+Exception:\s+(?:line\s+(\d+)).*$/gm.exec(errormsg) + if (matches && matches.length > 0) { + shortmsg = matches[0] + if (matches.length >= 2) { + lineNr = parseInt(matches[1]) + } + } + } + if (errormsg) { + diagnosticCollections.compiler.set(contractFile, [{ + code: '', + message: shortmsg, + range: new vscode.Range(new vscode.Position(lineNr - 1, 0), new vscode.Position(lineNr - 1, 255)), + severity: vscode.DiagnosticSeverity.Error, + source: errormsg, + relatedInformation: [] + }]); + } } ) .catch(ex => { @@ -292,7 +290,7 @@ function compileActiveFileCommand(contractFile) { } function compileActiveFile(contractFile) { - return new Promise((reject, resolve) => { + return new Promise((resolve, reject) => { if (!contractFile && vscode.window.activeTextEditor.document.languageId !== VYPER_ID) { reject("Not a vyper source file") return; diff --git a/src/features/signatures.js b/src/features/signatures.js index 6fae1d5..4150bd0 100644 --- a/src/features/signatures.js +++ b/src/features/signatures.js @@ -1,10 +1,11 @@ +'use strict' /** * @author github.com/tintinweb * @license MIT * * */ -class VyperSignatureHelpProvider{ +class VyperSignatureHelpProvider { provideSignatureHelp(document, position, token, context){ return new Promise((resolve, reject) => { position = position.translate(0, -1)