Skip to content

Commit

Permalink
patch re-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
0mkara committed Sep 12, 2020
1 parent 2cb233f commit dad4ced
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions ext-src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,32 +361,32 @@ 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: {
path: m.path,
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" });
Expand Down
42 changes: 24 additions & 18 deletions ext-src/solc-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!" });
Expand Down Expand Up @@ -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",
Expand All @@ -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 });
});
}


Expand Down
15 changes: 15 additions & 0 deletions ext-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class App extends Component<IProps, IState> {
const { processMessage } = data;
this.setState({
processMessage,
message: []
});
}
if (data.versions) {
Expand Down

0 comments on commit dad4ced

Please sign in to comment.