Fixed error when parsing warnings

pull/3996/head
ioedeveloper 1 year ago
parent caa6f8b005
commit fb43f37f2a
  1. 233
      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 { createClient } from '@remixproject/plugin-webview'
import {PluginClient} from '@remixproject/plugin'
import {createClient} from '@remixproject/plugin-webview'
import EventManager from 'events'
import pathModule from 'path'
import { parse } from 'circom_wasm'
import {parse} from 'circom_wasm'
export class CircomPluginClient extends PluginClient {
public internalEvents: EventManager
@ -11,11 +11,11 @@ export class CircomPluginClient extends PluginClient {
super()
createClient(this)
this.internalEvents = new EventManager()
this.methods = ["init", "parse"]
this.methods = ['init', 'parse']
this.onload()
}
init (): void {
init(): void {
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 = {
[path]: fileContent
}
@ -38,97 +38,176 @@ export class CircomPluginClient extends PluginClient {
try {
const result = JSON.parse(parsedOutput)
const markers = []
for (const report of result) {
for (const label in report.labels) {
if (report.labels[label].file_id === '0') {
// @ts-ignore
const startPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.start)
// @ts-ignore
const endPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.end)
markers.push({
message: report.message,
severity: report.type.toLowerCase(),
position: {
start: {
line: startPosition.lineNumber,
column: startPosition.column
if (result.length === 0) {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
} else {
const markers = []
for (const report of result) {
for (const label in report.labels) {
if (report.labels[label].file_id === '0') {
// @ts-ignore
const startPosition: {lineNumber: number; column: number} =
await this.call(
'editor',
'getPositionAt',
report.labels[label].range.start
)
// @ts-ignore
const endPosition: {lineNumber: number; column: number} =
await this.call(
'editor',
'getPositionAt',
report.labels[label].range.end
)
markers.push({
message: report.message,
severity: report.type.toLowerCase(),
position: {
start: {
line: startPosition.lineNumber,
column: startPosition.column
},
end: {
line: endPosition.lineNumber,
column: endPosition.column
}
},
end: {
line: endPosition.lineNumber,
column: endPosition.column
}
},
file: path
})
file: path
})
}
}
}
if (markers.length > 0) {
// @ts-ignore
await this.call('editor', 'addErrorMarker', markers)
} else {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
}
}
// @ts-ignore
await this.call('editor', 'addErrorMarker', markers)
} catch (e) {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
console.log(parsedOutput)
console.log(e)
}
}
async resolveDependencies (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 => {
// fix for endless recursive includes
if (blackPath.includes(include)) return
let dependencyContent = ''
let path = include
// @ts-ignore
const pathExists = await this.call('fileManager', 'exists', path)
async resolveDependencies(
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, '')
)
if (pathExists) {
dependencyContent = await this.call('fileManager', 'readFile', path)
} else {
let relativePath = pathModule.resolve(filePath.slice(0, filePath.lastIndexOf('/')), include)
if (relativePath.indexOf('/') === 0) relativePath = relativePath.slice(1)
await Promise.all(
includes.map(async (include) => {
// fix for endless recursive includes
if (blackPath.includes(include)) return
let dependencyContent = ''
let path = include
// @ts-ignore
const relativePathExists = await this.call('fileManager', 'exists', relativePath)
const pathExists = await this.call('fileManager', 'exists', path)
if (relativePathExists) {
dependencyContent = await this.call('fileManager', 'readFile', relativePath)
if (pathExists) {
dependencyContent = await this.call('fileManager', 'readFile', path)
} else {
if (depPath) {
path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include)
if (path.indexOf('/') === 0) path = path.slice(1)
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
let relativePath = pathModule.resolve(
filePath.slice(0, filePath.lastIndexOf('/')),
include
)
if (relativePath.indexOf('/') === 0)
relativePath = relativePath.slice(1)
// @ts-ignore
const relativePathExists = await this.call(
'fileManager',
'exists',
relativePath
)
if (relativePathExists) {
dependencyContent = await this.call(
'fileManager',
'readFile',
relativePath
)
} else {
if (include.startsWith('circomlib')) {
const splitInclude = include.split('/')
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g)
if (depPath) {
path = pathModule.resolve(
depPath.slice(0, depPath.lastIndexOf('/')),
include
)
if (path.indexOf('/') === 0) path = path.slice(1)
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} else {
if (include.startsWith('circomlib')) {
const splitInclude = include.split('/')
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g)
if (version && version[0]) {
path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
if (version && version[0]) {
path = `https://raw.githubusercontent.com/iden3/circomlib/${
version[0]
}/circuits/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
} else {
path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude
.slice(1)
.join('/')}`
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
}
} else {
path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
dependencyContent = await this.call(
'contentImport',
'resolveAndSave',
path,
null
)
}
} else {
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)
if (dependencyIncludes.length > 0) {
await this.resolveDependencies(filePath, dependencyContent, output, path, blackPath)
output[include] = dependencyContent
} else {
output[include] = dependencyContent
}
}))
blackPath.push(include)
if (dependencyIncludes.length > 0) {
await this.resolveDependencies(
filePath,
dependencyContent,
output,
path,
blackPath
)
output[include] = dependencyContent
} else {
output[include] = dependencyContent
}
})
)
return output
}
}

@ -150,7 +150,7 @@
"brace": "^0.8.0",
"change-case": "^4.1.1",
"chokidar": "^2.1.8",
"circom_wasm": "circom_wasm",
"circom_wasm": "^0.0.2",
"color-support": "^1.1.3",
"commander": "^9.4.1",
"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"
safe-buffer "^5.0.1"
circom_wasm@circom_wasm:
version "0.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.0.0-alpha.1.tgz#9578c82d78c5e02527ae3d65c9a57d98c3e9a53d"
integrity sha512-z1QKPvqhdLdfUw1hy/WBmi4wDj2UHN7o9Mq9QptGZkpKC9PzB5HCRj3v3uTI1ZJPH6IR6L1ytbrptM7VV3O0fA==
circom_wasm@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/circom_wasm/-/circom_wasm-0.0.2.tgz#9d24866b8289a5778999270823a4cb06e64145b5"
integrity sha512-SCMP6cxHHL7MLedDrTl+nGYyE6+kE5GepbxtZm65GlR0wUMD9eNOD1shwScWaDnmBOZTrImmNeTYZA5DWCmIww==
circular-json@^0.3.0:
version "0.3.3"

Loading…
Cancel
Save