diff --git a/README.md b/README.md index a127cb1f..34741ee4 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ [![Discord chat](https://img.shields.io/discord/722971683388129290?color=7389D8&logo=discord&logoColor=ffffff)](https://discord.gg/87sE7Bm) Ethcode is a vscode plugin for compiling, deploy, execute solidity and vyper smart contracts/programs in Ethereum blockchian. It supports multiple test networks. Ethcode has inbuilt support for Remix transaction debug and solidity unit testing. + +## Website +https://ethcode.dev/ +## Docs +https://docs.ethcode.dev/ ## Installation VisualStudio Marketplace - https://marketplace.visualstudio.com/items?itemName=ethential.ethcode diff --git a/ext-src/extension.ts b/ext-src/extension.ts index ef93c4d5..78dec6c5 100644 --- a/ext-src/extension.ts +++ b/ext-src/extension.ts @@ -361,6 +361,9 @@ class ReactPanel { logger.error(m.error); } else if (m.command === "import") { if (!sources[m.path]) { + sources[m.path] = { + content: undefined + }; solcWorker.send({ command: "import", payload: { @@ -368,25 +371,22 @@ class ReactPanel { rootPath } }); - } else { - solcWorker.send({ - command: "import", - payload: { - path: m.path, - content: sources[m.path].content - } - }); } } else if (m.command === "re-compile") { - if (m.path) + if (m.path) { sources[m.path] = { content: m.data.content, }; - solcWorker.send({ - command: "compile", - payload: input, - version: this.version, - }); + input.sources = sources; + const noContent = Object.values(input.sources).filter(source => source.content === undefined); + if(noContent.length < 1) { + solcWorker.send({ + command: "compile", + payload: input, + version: this.version, + }); + } + } } else if (m.command === "compiled") { context.workspaceState.update("sources", JSON.stringify(sources)); this._panel.webview.postMessage({ compiled: m.output, sources, testPanel: "main" }); diff --git a/ext-src/solc-worker.ts b/ext-src/solc-worker.ts index 555fde28..502b3331 100644 --- a/ext-src/solc-worker.ts +++ b/ext-src/solc-worker.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as fs from "fs"; import { RemixURLResolver } from "remix-url-resolver"; import { Uri } from "vscode"; +import { SolcError } from "./types"; function handleLocal(pathString: string, fileName: any, rootPath: Uri) { // if no relative/absolute path given then search in node_modules folder @@ -59,8 +60,18 @@ function compile(m: any) { console.log("compiling on solc-worker with local version: ", solc.version()); const output = solc.compile(JSON.stringify(input), { import: findImports }); const op = JSON.parse(output); + const operr: SolcError[] = op.errors; // @ts-ignores process.send({ command: "compiled", output }); + // Iterate through errors + // If there is no import error left, exit worker + const dfimp = operr.filter((error: SolcError) => error.errorCode === "6275"); + if (dfimp.length < 1) { + // @ts-ignore + process.send({ command: "process", processMessage: "compilation finished with error!" }); + // @ts-ignore + process.send({ command: "compile-ok" }); + } if (Object.keys(op.sources).length > 0) { // @ts-ignore process.send({ command: "process", processMessage: "compilation ok!" }); @@ -100,7 +111,7 @@ function compile(m: any) { } function importFiles(m: any) { - const { path, rootPath, content } = m.payload; + const { path, rootPath } = m.payload; const FSHandler = [ { type: "local", @@ -112,23 +123,18 @@ function importFiles(m: any) { } } ]; - if (content) { - // @ts-ignore - process.send({ command: "re-compile", data: { content }, path }); - } else { - // @ts-ignore - const urlResolver = new RemixURLResolver(); - // this section usually executes after solc returns error file not found - urlResolver.resolve(path, FSHandler) - .then((data: any) => { - // @ts-ignore - process.send({ command: "re-compile", data, path }); - }) - .catch((e: Error) => { - // @ts-ignore - process.send({ error: e }); - }); - } + // @ts-ignore + const urlResolver = new RemixURLResolver(); + // this section usually executes after solc returns error file not found + urlResolver.resolve(path, FSHandler) + .then((data: any) => { + // @ts-ignore + process.send({ command: "re-compile", data, path }); + }) + .catch((e: Error) => { + // @ts-ignore + process.send({ error: e }); + }); } diff --git a/ext-src/types.ts b/ext-src/types.ts index 3b5e2d23..9c038547 100644 --- a/ext-src/types.ts +++ b/ext-src/types.ts @@ -14,4 +14,19 @@ export interface IAccount { export interface TokenData { machineID: string; token: string; +} + +interface ISrcLoc { + end: number; + file: string; + start: number; +} +export interface SolcError { + component: string; + errorCode: string; + formattedMessage: string; + message: string; + severity: string; + sourceLocation: ISrcLoc; + type: string; } \ No newline at end of file diff --git a/src/components/App.tsx b/src/components/App.tsx index 5850404c..97ef79cc 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -158,7 +158,6 @@ class App extends Component { const { processMessage } = data; this.setState({ processMessage, - message: [] }); } if (data.versions) {