new file on workspace change.

pull/5370/head
lianahus 3 years ago committed by yann300
parent 200e2b21f7
commit 76f26f3ad9
  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 const requiredModules = [ // services + layout views + system views
'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme',
'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', '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'] '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) 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) { 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) return nativePlugins.includes(name) || requiredModules.includes(name)
} }

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

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

@ -9,6 +9,8 @@ import { resetEditorMode, listenToEvents } from './actions/compiler'
import { OverlayTrigger, Tooltip } from 'react-bootstrap' // eslint-disable-line import { OverlayTrigger, Tooltip } from 'react-bootstrap' // eslint-disable-line
import { getValidLanguage } from '@remix-project/remix-solidity' import { getValidLanguage } from '@remix-project/remix-solidity'
import { CopyToClipboard } from '@remix-ui/clipboard' 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' import './css/style.css'
@ -21,7 +23,7 @@ declare global {
const _paq = window._paq = window._paq || [] //eslint-disable-line const _paq = window._paq = window._paq || [] //eslint-disable-line
export const CompilerContainer = (props: CompilerContainerProps) => { 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({ const [state, setState] = useState({
hideWarnings: false, hideWarnings: false,
autoCompile: false, autoCompile: false,
@ -51,6 +53,19 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
const [truffleCompilation, setTruffleCompilation] = useState(false) const [truffleCompilation, setTruffleCompilation] = useState(false)
const [compilerContainer, dispatch] = useReducer(compilerReducer, compilerInitialState) 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(() => { useEffect(() => {
fetchAllVersion((allversions, selectedVersion, isURL) => { fetchAllVersion((allversions, selectedVersion, isURL) => {
setState(prevState => { setState(prevState => {
@ -156,8 +171,8 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
} }
const createNewConfigFile = async () => { const createNewConfigFile = async () => {
const configFileContent = const configFileContent = JSON.stringify(json_config, null, '\t')
await api.writeFile(configFilePathInput.current.value, "") await api.writeFile(configFilePathInput.current && configFilePathInput.current.value !== '' ? configFilePathInput.current.value : configFilePath, configFileContent)
setConfigFilePath(configFilePathInput.current.value) setConfigFilePath(configFilePathInput.current.value)
} }
const handleConfigPathChange = async () => { const handleConfigPathChange = async () => {
@ -165,7 +180,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => {
setConfigFilePath(configFilePathInput.current.value) setConfigFilePath(configFilePathInput.current.value)
else { else {
modal( 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', 'Create',
async () => await createNewConfigFile(), async () => await createNewConfigFile(),
'Cancel', 'Cancel',

@ -13,6 +13,7 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
const [state, setState] = useState({ const [state, setState] = useState({
isHardhatProject: false, isHardhatProject: false,
isTruffleProject: false, isTruffleProject: false,
workspaceName: '',
currentFile, currentFile,
loading: false, loading: false,
compileTabLogic: null, 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 isHardhat = isLocalhost && await compileTabLogic.isHardhatProject()
const isTruffle = await compileTabLogic.isTruffleProject() const isTruffle = await compileTabLogic.isTruffleProject()
setState(prevState => { setState(prevState => {
<<<<<<< HEAD
return { ...prevState, currentFile, isHardhatProject: isHardhat, isTruffleProject: isTruffle } 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 ( return (
<> <>
<div id="compileTabView"> <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} 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} /> } { contractsFile[currentFile] && contractsFile[currentFile].contractsDetails && <ContractSelection api={api} contractsDetails={contractsFile[currentFile].contractsDetails} contractList={contractsFile[currentFile].contractList} modal={modal} /> }
{ compileErrors[currentFile] && { compileErrors[currentFile] &&
<div className="remixui_errorBlobs p-4" data-id="compiledErrors"> <div className="remixui_errorBlobs p-4" data-id="compiledErrors">

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

Loading…
Cancel
Save