Fixed error when parsing warnings

pull/3996/head
ioedeveloper 1 year ago
parent caa6f8b005
commit fb43f37f2a
  1. 133
      apps/circuit-compiler/src/app/services/circomPluginClient.ts
  2. 2
      package.json
  3. 8
      yarn.lock

@ -1,8 +1,8 @@
import { PluginClient } from '@remixproject/plugin' import {PluginClient} from '@remixproject/plugin'
import { createClient } from '@remixproject/plugin-webview' import {createClient} from '@remixproject/plugin-webview'
import EventManager from 'events' import EventManager from 'events'
import pathModule from 'path' import pathModule from 'path'
import { parse } from 'circom_wasm' import {parse} from 'circom_wasm'
export class CircomPluginClient extends PluginClient { export class CircomPluginClient extends PluginClient {
public internalEvents: EventManager public internalEvents: EventManager
@ -11,11 +11,11 @@ export class CircomPluginClient extends PluginClient {
super() super()
createClient(this) createClient(this)
this.internalEvents = new EventManager() this.internalEvents = new EventManager()
this.methods = ["init", "parse"] this.methods = ['init', 'parse']
this.onload() this.onload()
} }
init (): void { init(): void {
console.log('initializing circom plugin...') console.log('initializing circom plugin...')
} }
@ -28,7 +28,7 @@ export class CircomPluginClient extends PluginClient {
}) })
} }
async parse (path: string, fileContent: string): Promise<void> { async parse(path: string, fileContent: string): Promise<void> {
let buildFiles = { let buildFiles = {
[path]: fileContent [path]: fileContent
} }
@ -38,15 +38,30 @@ export class CircomPluginClient extends PluginClient {
try { try {
const result = JSON.parse(parsedOutput) const result = JSON.parse(parsedOutput)
if (result.length === 0) {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
} else {
const markers = [] const markers = []
for (const report of result) { for (const report of result) {
for (const label in report.labels) { for (const label in report.labels) {
if (report.labels[label].file_id === '0') { if (report.labels[label].file_id === '0') {
// @ts-ignore // @ts-ignore
const startPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.start) const startPosition: {lineNumber: number; column: number} =
await this.call(
'editor',
'getPositionAt',
report.labels[label].range.start
)
// @ts-ignore // @ts-ignore
const endPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.end) const endPosition: {lineNumber: number; column: number} =
await this.call(
'editor',
'getPositionAt',
report.labels[label].range.end
)
markers.push({ markers.push({
message: report.message, message: report.message,
@ -66,19 +81,33 @@ export class CircomPluginClient extends PluginClient {
} }
} }
} }
if (markers.length > 0) {
// @ts-ignore // @ts-ignore
await this.call('editor', 'addErrorMarker', markers) await this.call('editor', 'addErrorMarker', markers)
} catch (e) { } else {
// @ts-ignore // @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path]) await this.call('editor', 'clearErrorMarkers', [path])
console.log(parsedOutput) }
}
} catch (e) {
console.log(e)
} }
} }
async resolveDependencies (filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []): Promise<Record<string, string>> { async resolveDependencies(
const includes = (fileContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) filePath: string,
fileContent: string,
output = {},
depPath: string = '',
blackPath: string[] = []
): Promise<Record<string, string>> {
const includes = (fileContent.match(/include ['"].*['"]/g) || []).map(
(include) => include.replace(/include ['"]/g, '').replace(/['"]/g, '')
)
await Promise.all(includes.map(async include => { await Promise.all(
includes.map(async (include) => {
// fix for endless recursive includes // fix for endless recursive includes
if (blackPath.includes(include)) return if (blackPath.includes(include)) return
let dependencyContent = '' let dependencyContent = ''
@ -89,46 +118,96 @@ export class CircomPluginClient extends PluginClient {
if (pathExists) { if (pathExists) {
dependencyContent = await this.call('fileManager', 'readFile', path) dependencyContent = await this.call('fileManager', 'readFile', path)
} else { } else {
let relativePath = pathModule.resolve(filePath.slice(0, filePath.lastIndexOf('/')), include) let relativePath = pathModule.resolve(
if (relativePath.indexOf('/') === 0) relativePath = relativePath.slice(1) filePath.slice(0, filePath.lastIndexOf('/')),
include
)
if (relativePath.indexOf('/') === 0)
relativePath = relativePath.slice(1)
// @ts-ignore // @ts-ignore
const relativePathExists = await this.call('fileManager', 'exists', relativePath) const relativePathExists = await this.call(
'fileManager',
'exists',
relativePath
)
if (relativePathExists) { if (relativePathExists) {
dependencyContent = await this.call('fileManager', 'readFile', relativePath) dependencyContent = await this.call(
'fileManager',
'readFile',
relativePath
)
} else { } else {
if (depPath) { if (depPath) {
path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) path = pathModule.resolve(
depPath.slice(0, depPath.lastIndexOf('/')),
include
)
if (path.indexOf('/') === 0) path = path.slice(1) if (path.indexOf('/') === 0) path = path.slice(1)
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} else { } else {
if (include.startsWith('circomlib')) { if (include.startsWith('circomlib')) {
const splitInclude = include.split('/') const splitInclude = include.split('/')
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g)
if (version && version[0]) { if (version && version[0]) {
path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` path = `https://raw.githubusercontent.com/iden3/circomlib/${
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) version[0]
}/circuits/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} else { } else {
path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) .slice(1)
.join('/')}`
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} }
} else { } else {
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} }
} }
} }
} }
const dependencyIncludes = (dependencyContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) const dependencyIncludes = (
dependencyContent.match(/include ['"].*['"]/g) || []
).map((include) =>
include.replace(/include ['"]/g, '').replace(/['"]/g, '')
)
blackPath.push(include) blackPath.push(include)
if (dependencyIncludes.length > 0) { if (dependencyIncludes.length > 0) {
await this.resolveDependencies(filePath, dependencyContent, output, path, blackPath) await this.resolveDependencies(
filePath,
dependencyContent,
output,
path,
blackPath
)
output[include] = dependencyContent output[include] = dependencyContent
} else { } else {
output[include] = dependencyContent output[include] = dependencyContent
} }
})) })
)
return output return output
} }
} }

@ -150,7 +150,7 @@
"brace": "^0.8.0", "brace": "^0.8.0",
"change-case": "^4.1.1", "change-case": "^4.1.1",
"chokidar": "^2.1.8", "chokidar": "^2.1.8",
"circom_wasm": "circom_wasm", "circom_wasm": "^0.0.2",
"color-support": "^1.1.3", "color-support": "^1.1.3",
"commander": "^9.4.1", "commander": "^9.4.1",
"core-js": "^3.6.5", "core-js": "^3.6.5",

@ -9897,10 +9897,10 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
inherits "^2.0.1" inherits "^2.0.1"
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
circom_wasm@circom_wasm: circom_wasm@^0.0.2:
version "0.0.0-alpha.1" version "0.0.2"
resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.0.0-alpha.1.tgz#9578c82d78c5e02527ae3d65c9a57d98c3e9a53d" resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.0.2.tgz#9d24866b8289a5778999270823a4cb06e64145b5"
integrity sha512-z1QKPvqhdLdfUw1hy/WBmi4wDj2UHN7o9Mq9QptGZkpKC9PzB5HCRj3v3uTI1ZJPH6IR6L1ytbrptM7VV3O0fA== integrity sha512-SCMP6cxHHL7MLedDrTl+nGYyE6+kE5GepbxtZm65GlR0wUMD9eNOD1shwScWaDnmBOZTrImmNeTYZA5DWCmIww==
circular-json@^0.3.0: circular-json@^0.3.0:
version "0.3.3" version "0.3.3"

Loading…
Cancel
Save