new file on workspace change.

pull/2249/head
lianahus 3 years ago committed by yann300
parent 6df6987224
commit a311dbcac7
  1. 5
      apps/remix-ide/src/remixAppManager.js
  2. 6
      apps/solidity-compiler/src/app/compiler-api.ts
  3. 2
      libs/remix-lib/src/types/ICompilerApi.ts
  4. 23
      libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx
  5. 11
      libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx
  6. 4
      libs/remix-ui/solidity-compiler/src/lib/types/index.ts

@ -7,7 +7,7 @@ const _paq = window._paq = window._paq || []
const requiredModules = [ // services + layout views + system views
'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme',
'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons',
'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout',
'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity', 'solidity-logic', 'gistHandler', 'layout',
'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries', 'openzeppelin-proxy', 'hardhat-provider', 'compileAndRun', 'search']
const dependentModules = ['git', 'hardhat', 'truffle', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd)
@ -19,7 +19,8 @@ const sensitiveCalls = {
}
export function isNative(name) {
const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'hardhat-provider', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification', 'hardhat-provider', 'ganache-provider']
const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'solidity-logic',
'hardhat-provider', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification', 'hardhat-provider', 'ganache-provider']
return nativePlugins.includes(name) || requiredModules.includes(name)
}

@ -18,7 +18,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
onCurrentFileChanged: (fileName: string) => void
// onResetResults: () => void
onSetWorkspace: (workspace: any) => void
onSetWorkspace: (isLocalhost: boolean, workspaceName: string) => void
onNoFileSelected: () => void
onCompilationFinished: (compilationDetails: { contractMap: { file: string } | Record<string, any>, contractsDetails: Record<string, any> }) => void
onSessionSwitched: () => void
@ -237,12 +237,12 @@ export const CompilerApiMixin = (Base) => class extends Base {
this.on('filePanel', 'setWorkspace', (workspace) => {
this.resetResults()
if (this.onSetWorkspace) this.onSetWorkspace(workspace.isLocalhost)
if (this.onSetWorkspace) this.onSetWorkspace(workspace.isLocalhost, workspace.name)
})
this.on('remixd', 'rootFolderChanged', () => {
this.resetResults()
if (this.onSetWorkspace) this.onSetWorkspace(true)
if (this.onSetWorkspace) this.onSetWorkspace(true, 'localhost')
})
this.on('editor', 'sessionSwitched', () => {

@ -24,7 +24,7 @@ export interface ICompilerApi {
onCurrentFileChanged: (fileName: string) => void
// onResetResults: () => void,
onSetWorkspace: (workspace: any) => void
onSetWorkspace: (isLocalhost: boolean, workspaceName: string) => void
onNoFileSelected: () => void
onCompilationFinished: (contractsDetails: any, contractMap: any) => void
onSessionSwitched: () => void

@ -9,6 +9,8 @@ import { resetEditorMode, listenToEvents } from './actions/compiler'
import { OverlayTrigger, Tooltip } from 'react-bootstrap' // eslint-disable-line
import { getValidLanguage } from '@remix-project/remix-solidity'
import { CopyToClipboard } from '@remix-ui/clipboard'
// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries
import * as json_config from '../../../../../apps/remix-ide/contracts/solidity_compiler_config.json'
import './css/style.css'
@ -21,7 +23,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => {
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject } = props // eslint-disable-line
const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings, isHardhatProject, isTruffleProject, workspaceName } = props // eslint-disable-line
const [state, setState] = useState({
hideWarnings: false,
autoCompile: false,
@ -51,6 +53,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const [truffleCompilation, setTruffleCompilation] = useState(false)
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState)
useEffect(() => {
setConfigFilePath("/compiler_config.json")
api.fileExists("/compiler_config.json").then((exists) => {
if (!exists) createNewConfigFile()
else {
// what to do? discuss
}
})
setConfigFilePath("/compiler_config.json")
setManualConfig(false)
setShowFilePathInput(false)
}, [workspaceName])
useEffect(() => {
fetchAllVersion((allversions, selectedVersion, isURL) => {
setState(prevState => {
@ -156,8 +171,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
}
const createNewConfigFile = async () => {
const configFileContent =
await api.writeFile(configFilePathInput.current.value, "")
const configFileContent = JSON.stringify(json_config, null, '\t')
await api.writeFile(configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath, configFileContent)
setConfigFilePath(configFilePathInput.current.value)
}
const handleConfigPathChange = async () => {
@ -165,7 +180,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
setConfigFilePath(configFilePathInput.current.value)
else {
modal(
'New configuration file', 'The file you entered does not exist. Do you want to create a new one?',
'New configuration file', `The file "${configFilePathInput.current.value}"" you entered does not exist. Do you want to create a new one?`,
'Create',
async () => await createNewConfigFile(),
'Cancel',

@ -13,6 +13,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const [state, setState] = useState({
isHardhatProject: false,
isTruffleProject: false,
workspaceName: '',
currentFile,
loading: false,
compileTabLogic: null,
@ -63,11 +64,15 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
})
}
api.onSetWorkspace = async (isLocalhost: boolean) => {
api.onSetWorkspace = async (isLocalhost: boolean, workspaceName: string) => {
const isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
const isTruffle = await compileTabLogic.isTruffleProject()
setState(prevState => {
<<<<<<< HEAD
return { ...prevState, currentFile, isHardhatProject: isHardhat, isTruffleProject: isTruffle }
=======
return { ...prevState, currentFile, isHardhatProject: isHardhat, workspaceName: workspaceName }
>>>>>>> bc1405382... new file on workspace change.
})
}
@ -150,7 +155,11 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
return (
<>
<div id="compileTabView">
<<<<<<< HEAD
<CompilerContainer api={api} isHardhatProject={state.isHardhatProject} isTruffleProject={state.isTruffleProject} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
=======
<CompilerContainer api={api} isHardhatProject={state.isHardhatProject} workspaceName={state.workspaceName} compileTabLogic={compileTabLogic} tooltip={toast} modal={modal} compiledFileName={currentFile} updateCurrentVersion={updateCurrentVersion} configurationSettings={configurationSettings} />
>>>>>>> bc1405382... new file on workspace change.
{ contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && <ContractSelection api={api} contractsDetails={contractsFile[currentFile].contractsDetails} contractList={contractsFile[currentFile].contractList} modal={modal} /> }
{ compileErrors[currentFile] &&
<div className="remixui_errorBlobs p-4" data-id="compiledErrors">

@ -10,7 +10,11 @@ export interface CompilerContainerProps {
api: ICompilerApi,
compileTabLogic: CompileTabLogic,
isHardhatProject: boolean,
<<<<<<< HEAD
isTruffleProject: boolean,
=======
workspaceName: string,
>>>>>>> bc1405382... new file on workspace change.
tooltip: (message: string | JSX.Element) => void,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
compiledFileName: string,

Loading…
Cancel
Save