|
|
@ -11,7 +11,7 @@ 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() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|