From e4c6b1496e987cd3b73d4ec5a5b6abde98ddb8b8 Mon Sep 17 00:00:00 2001 From: David Disu Date: Mon, 21 Feb 2022 17:38:04 +0100 Subject: [PATCH] Clear error message when switching tabs --- apps/remix-ide/src/app/tabs/compile-tab.js | 4 ++++ apps/solidity-compiler/src/app/compiler-api.ts | 7 +++++++ libs/remix-lib/src/types/ICompilerApi.ts | 1 + .../solidity-compiler/src/lib/solidity-compiler.tsx | 12 ++++++++++-- .../solidity-compiler/src/lib/types/index.ts | 11 +++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 4718b4dee6..262d64f6e5 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -63,6 +63,10 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA this.renderComponent() } + onFileClosed () { + this.renderComponent() + } + onCompilationFinished () { this.renderComponent() } diff --git a/apps/solidity-compiler/src/app/compiler-api.ts b/apps/solidity-compiler/src/app/compiler-api.ts index 2e81d08ba1..b3d46a4712 100644 --- a/apps/solidity-compiler/src/app/compiler-api.ts +++ b/apps/solidity-compiler/src/app/compiler-api.ts @@ -21,6 +21,7 @@ export const CompilerApiMixin = (Base) => class extends Base { onCompilationFinished: (contractsDetails: any, contractMap: any) => void onSessionSwitched: () => void onContentChanged: () => void + onFileClosed: (name: string) => void initCompilerApi () { this.configurationSettings = null @@ -249,6 +250,12 @@ export const CompilerApiMixin = (Base) => class extends Base { } this.on('fileManager', 'noFileSelected', this.data.eventHandlers.onNoFileSelected) + this.data.eventHandlers.onFileClosed = (name: string) => { + this.onFileClosed(name) + } + + this.on('fileManager', 'fileClosed', this.data.eventHandlers.onFileClosed) + this.data.eventHandlers.onCompilationFinished = (success, data, source) => { this.compileErrors = data if (success) { diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts index 62f86b5652..4cdea95799 100644 --- a/libs/remix-lib/src/types/ICompilerApi.ts +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -26,6 +26,7 @@ export interface ICompilerApi { onCompilationFinished: (contractsDetails: any, contractMap: any) => void onSessionSwitched: () => void onContentChanged: () => void + onFileClosed: (name: string) => void resolveContentAndSave: (url: string) => Promise fileExists: (file: string) => Promise diff --git a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx index dcc86f387f..18ded67061 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react' // eslint-disable-line -import { SolidityCompilerProps } from './types' +import { CompileErrors, SolidityCompilerProps } from './types' import { CompilerContainer } from './compiler-container' // eslint-disable-line import { ContractSelection } from './contract-selection' // eslint-disable-line import { Toaster } from '@remix-ui/toaster' // eslint-disable-line @@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import './css/style.css' export const SolidityCompiler = (props: SolidityCompilerProps) => { - const { api, api: { currentFile, compileTabLogic, contractsDetails, contractMap, compileErrors, configurationSettings } } = props + const { api, api: { currentFile, compileTabLogic, contractsDetails, contractMap, configurationSettings } } = props const [state, setState] = useState({ isHardhatProject: false, currentFile, @@ -32,6 +32,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { }) const [currentVersion, setCurrentVersion] = useState('') const [hideWarnings, setHideWarnings] = useState(false) + const [compileErrors, setCompileErrors] = useState(api.compileErrors) useEffect(() => { (async () => { @@ -63,12 +64,19 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => { setState(prevState => { return { ...prevState, currentFile: '' } }) + setCompileErrors({} as CompileErrors) } api.onCompilationFinished = (contractsDetails: any, contractMap: any) => { setState(prevState => { return { ...prevState, contractsDetails, contractMap } }) + setCompileErrors(api.compileErrors) + } + + api.onFileClosed = (name) => { + console.log('path/name: ', name, currentFile) + if (name === currentFile) setCompileErrors({} as CompileErrors) } const toast = (message: string) => { diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts index 4932b1456c..eefc8c69ab 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts @@ -24,3 +24,14 @@ export interface ContractSelectionProps { modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, contractsDetails: Record } + +interface CompileError { + mode?: string, + severity?: string, + formattedMessage?: string, + type?: string +} +export interface CompileErrors { + error: CompileError, + errors: CompileError[] +}