Store badge info for opened files

pull/2093/head
David Disu 3 years ago
parent 29814a7efd
commit 3b376ce738
  1. 1
      apps/remix-ide/src/app/tabs/compile-tab.js
  2. 17
      apps/solidity-compiler/src/app/compiler-api.ts
  3. 2
      libs/remix-lib/src/types/ICompilerApi.ts
  4. 18
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx

@ -86,6 +86,7 @@ class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerA
}
getFileManagerMode () {
this.emit()
return this.fileManager.mode
}

@ -22,6 +22,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
onSessionSwitched: () => void
onContentChanged: () => void
onFileClosed: (name: string) => void
statusChanged: (data: { key: string, title?: string, type?: string }) => void
initCompilerApi () {
this.configurationSettings = null
@ -190,31 +191,31 @@ export const CompilerApiMixin = (Base) => class extends Base {
resetResults () {
this.currentFile = ''
this.contractsDetails = {}
this.emit('statusChanged', { key: 'none' })
this.statusChanged({ key: 'none' })
if (this.onResetResults) this.onResetResults()
}
listenToEvents () {
this.on('editor', 'contentChanged', () => {
this.emit('statusChanged', { key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' })
this.statusChanged({ key: 'edited', title: 'the content has changed, needs recompilation', type: 'info' })
if (this.onContentChanged) this.onContentChanged()
})
this.data.eventHandlers.onLoadingCompiler = (url) => {
this.data.loading = true
this.data.loadingUrl = url
this.emit('statusChanged', { key: 'loading', title: 'loading compiler...', type: 'info' })
this.statusChanged({ key: 'loading', title: 'loading compiler...', type: 'info' })
}
this.compiler.event.register('loadingCompiler', this.data.eventHandlers.onLoadingCompiler)
this.data.eventHandlers.onCompilerLoaded = () => {
this.data.loading = false
this.emit('statusChanged', { key: 'none' })
this.statusChanged({ key: 'none' })
}
this.compiler.event.register('compilerLoaded', this.data.eventHandlers.onCompilerLoaded)
this.data.eventHandlers.onStartingCompilation = () => {
this.emit('statusChanged', { key: 'loading', title: 'compiling...', type: 'info' })
this.statusChanged({ key: 'loading', title: 'compiling...', type: 'info' })
}
this.data.eventHandlers.onRemoveAnnotations = () => {
@ -262,12 +263,12 @@ export const CompilerApiMixin = (Base) => class extends Base {
// forwarding the event to the appManager infra
this.emit('compilationFinished', source.target, source, 'soljson', data)
if (data.errors && data.errors.length > 0) {
this.emit('statusChanged', {
this.statusChanged({
key: data.errors.length,
title: `compilation finished successful with warning${data.errors.length > 1 ? 's' : ''}`,
type: 'warning'
})
} else this.emit('statusChanged', { key: 'succeed', title: 'compilation successful', type: 'success' })
} else this.statusChanged({ key: 'succeed', title: 'compilation successful', type: 'success' })
// Store the contracts
this.contractsDetails = {}
this.compiler.visitContracts((contract) => {
@ -279,7 +280,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
})
} else {
const count = (data.errors ? data.errors.filter(error => error.severity === 'error').length : 0 + (data.error ? 1 : 0))
this.emit('statusChanged', { key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' })
this.statusChanged({ key: count, title: `compilation failed with ${count} error${count > 1 ? 's' : ''}`, type: 'error' })
}
// Update contract Selection
this.contractMap = {}

@ -38,6 +38,8 @@ export interface ICompilerApi {
logToTerminal: (log: terminalLog) => void
compileWithHardhat: (configPath: string) => Promise<string>
statusChanged: (data: { key: string, title?: string, type?: string }) => void,
emit: (key: string, ...payload: any) => void
}
export type terminalLog = {

@ -33,6 +33,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const [currentVersion, setCurrentVersion] = useState('')
const [hideWarnings, setHideWarnings] = useState<boolean>(false)
const [compileErrors, setCompileErrors] = useState<Record<string, CompileErrors>>({ [currentFile]: api.compileErrors })
const [badgeStatus, setBadgeStatus] = useState<Record<string, { key: string, title?: string, type?: string }>>({})
useEffect(() => {
(async () => {
@ -41,6 +42,14 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
})()
}, [])
useEffect(() => {
if (badgeStatus[currentFile]) {
api.emit('statusChanged', badgeStatus[currentFile])
} else {
api.emit('statusChanged', { key: 'none' })
}
}, [badgeStatus[currentFile], currentFile])
api.onCurrentFileChanged = (currentFile: string) => {
setState(prevState => {
return { ...prevState, currentFile }
@ -75,7 +84,14 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
}
api.onFileClosed = (name) => {
if (name === currentFile) setCompileErrors({ ...compileErrors, [currentFile]: {} as CompileErrors })
if (name === currentFile) {
setCompileErrors({ ...compileErrors, [currentFile]: {} as CompileErrors })
setBadgeStatus({ ...badgeStatus, [currentFile]: { key: 'none' } })
}
}
api.statusChanged = (data: { key: string, title?: string, type?: string }) => {
setBadgeStatus({ ...badgeStatus, [currentFile]: data })
}
const toast = (message: string) => {

Loading…
Cancel
Save