From 1f6a0abaab47fb294b0a0a19218ac7e8717be26d Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 17 Aug 2022 12:42:35 +0200 Subject: [PATCH] fix highlight --- .../src/app/components/CompilerButton.tsx | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/vyper/src/app/components/CompilerButton.tsx b/apps/vyper/src/app/components/CompilerButton.tsx index 89d72b9a17..17cf771514 100644 --- a/apps/vyper/src/app/components/CompilerButton.tsx +++ b/apps/vyper/src/app/components/CompilerButton.tsx @@ -28,7 +28,8 @@ function CompilerButton({ contract, setOutput, compilerUrl }: Props) { /** Compile a Contract */ async function compileContract() { try { - let _contract + await remixClient.discardHighlight() + let _contract: any try { _contract = await remixClient.getContract() } catch (e: any) { @@ -53,10 +54,33 @@ function CompilerButton({ contract, setOutput, compilerUrl }: Props) { const line = output.line if (line) { const lineColumnPos = { - start: { line: line - 1 }, - end: { line: line - 1 } + start: { line: line - 1, column: 10 }, + end: { line: line - 1, column: 10 } } remixClient.highlight(lineColumnPos as any, _contract.name, '#e0b4b4') + } else { + const regex = output.message.match(/line ((\d+):(\d+))+/g) + const errors = output.message.split(/line ((\d+):(\d+))+/g) // extract error message + if (regex) { + let errorIndex = 0 + regex.map((errorLocation) => { + const location = errorLocation.replace('line ', '').split(':') + let message = errors[errorIndex] + errorIndex = errorIndex + 4 + if (message) { + try { + message = message.split('\n\n')[1] + } catch (e) {} + } + if (location.length > 0) { + const lineColumnPos = { + start: { line: parseInt(location[0]) - 1, column: 10 }, + end: { line: parseInt(location[0]) - 1, column: 10 } + } + remixClient.highlight(lineColumnPos as any, _contract.name, message) + } + }) + } } throw new Error(output.message) }