Skip to content

Commit

Permalink
fix misused promises
Browse files Browse the repository at this point in the history
prepare 0.0.8
  • Loading branch information
tintinweb committed Nov 25, 2019
1 parent fc23501 commit b208b27
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 0.0.8
- fix misused promises

## 0.0.7
- updated grammar
- fixed mythX issue due to API change
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 9 additions & 24 deletions src/extension.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 Expand Up @@ -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, [
{
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -186,7 +172,6 @@ function onActivate(context) {


}
console.log("✓ activate extension: vyper")
}

/* exports */
Expand Down
90 changes: 44 additions & 46 deletions src/features/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 => {
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/features/signatures.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit b208b27

Please sign in to comment.