diff --git a/apps/noir-compiler/src/app/app.tsx b/apps/noir-compiler/src/app/app.tsx index 5fae7839e59..bcb69ddf334 100644 --- a/apps/noir-compiler/src/app/app.tsx +++ b/apps/noir-compiler/src/app/app.tsx @@ -23,6 +23,20 @@ function App() { plugin.on('locale', 'localeChanged', (locale: any) => { setLocale(locale) }) + plugin.on('fileManager', 'currentFileChanged', (filePath) => { + if (filePath.endsWith('.nr')) { + dispatch({ type: 'SET_FILE_PATH', payload: filePath }) + plugin.parse(filePath) + } + }) + // @ts-ignore + plugin.on('editor', 'contentChanged', async (path: string, content: string) => { + setIsContentChanged(true) + // check if autoCompile is enabled + // if (path.endsWith('.nr')) { + // plugin.parse(path, content) + // } + }) setIsPluginActivated(true) }) }, []) diff --git a/apps/noir-compiler/src/app/components/container.tsx b/apps/noir-compiler/src/app/components/container.tsx index 886b5255591..0fe4ffc8e84 100644 --- a/apps/noir-compiler/src/app/components/container.tsx +++ b/apps/noir-compiler/src/app/components/container.tsx @@ -21,22 +21,17 @@ export function Container () { } } - // const handleOpenErrorLocation = async (location: string, startRange: string) => { - // if (location) { - // const fullPathLocation = await circuitApp.plugin.resolveReportPath(location) + const handleOpenErrorLocation = async (location: string, startRange: string) => { + if (location) { + const fullPathLocation = await circuitApp.plugin.resolveReportPath(location) - // await circuitApp.plugin.call('fileManager', 'open', fullPathLocation) - // // @ts-ignore - // const startPosition: { lineNumber: number; column: number } = await circuitApp.plugin.call('editor', 'getPositionAt', startRange) - // // @ts-ignore - // await circuitApp.plugin.call('editor', 'gotoLine', startPosition.lineNumber - 1, startPosition.column) - // } - // } - - // const handlePrimeChange = (value: PrimeValue) => { - // circuitApp.plugin.compilerPrime = value - // circuitApp.dispatch({ type: 'SET_PRIME_VALUE', payload: value as PrimeValue }) - // } + await circuitApp.plugin.call('fileManager', 'open', fullPathLocation) + // @ts-ignore + const startPosition: { lineNumber: number; column: number } = await circuitApp.plugin.call('editor', 'getPositionAt', startRange) + // @ts-ignore + await circuitApp.plugin.call('editor', 'gotoLine', startPosition.lineNumber - 1, startPosition.column) + } + } const handleCircuitAutoCompile = (value: boolean) => { noirApp.dispatch({ type: 'SET_AUTO_COMPILE', payload: value }) @@ -46,48 +41,48 @@ export function Container () { noirApp.dispatch({ type: 'SET_HIDE_WARNINGS', payload: value }) } - // const askGPT = async (report: CompilerReport) => { - // if (report.labels.length > 0) { - // const location = circuitApp.appState.filePathToId[report.labels[0].file_id] - // const error = report.labels[0].message + const askGPT = async (report: CompilerReport) => { + if (report.labels.length > 0) { + const location = circuitApp.appState.filePathToId[report.labels[0].file_id] + const error = report.labels[0].message - // if (location) { - // const fullPathLocation = await circuitApp.plugin.resolveReportPath(location) - // const content = await circuitApp.plugin.call('fileManager', 'readFile', fullPathLocation) - // const message = ` - // circom code: ${content} - // error message: ${error} - // full circom error: ${JSON.stringify(report, null, 2)} - // explain why the error occurred and how to fix it. - // ` - // await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) - // setTimeout(async () => { - // await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) - // }, 500) - // } else { - // const message = ` - // error message: ${error} - // full circom error: ${JSON.stringify(report, null, 2)} - // explain why the error occurred and how to fix it. - // ` - // await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) - // setTimeout(async () => { - // await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) - // }, 500) - // } - // } else { - // const error = report.message - // const message = ` - // error message: ${error} - // full circom error: ${JSON.stringify(report, null, 2)} - // explain why the error occurred and how to fix it. - // ` - // await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) - // setTimeout(async () => { - // await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) - // }, 500) - // } - // } + if (location) { + const fullPathLocation = await circuitApp.plugin.resolveReportPath(location) + const content = await circuitApp.plugin.call('fileManager', 'readFile', fullPathLocation) + const message = ` + circom code: ${content} + error message: ${error} + full circom error: ${JSON.stringify(report, null, 2)} + explain why the error occurred and how to fix it. + ` + await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) + setTimeout(async () => { + await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) + }, 500) + } else { + const message = ` + error message: ${error} + full circom error: ${JSON.stringify(report, null, 2)} + explain why the error occurred and how to fix it. + ` + await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) + setTimeout(async () => { + await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) + }, 500) + } + } else { + const error = report.message + const message = ` + error message: ${error} + full circom error: ${JSON.stringify(report, null, 2)} + explain why the error occurred and how to fix it. + ` + await circuitApp.plugin.call('popupPanel' as any, 'showPopupPanel', true) + setTimeout(async () => { + await circuitApp.plugin.call('remixAI' as any, 'chatPipe', 'error_explaining', message) + }, 500) + } + } const handleCompileClick = () => { compileNoirCircuit(noirApp.plugin, noirApp.appState) @@ -113,9 +108,9 @@ export function Container () {