Skip to content

Commit 124f47a

Browse files
authored
Merge pull request #6029 from ethereum/yellowlines
config file compiler
2 parents 46879c8 + dd0ecf1 commit 124f47a

File tree

8 files changed

+140
-77
lines changed

8 files changed

+140
-77
lines changed

apps/remix-ide/src/app/plugins/parser/code-parser.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ export class CodeParser extends Plugin {
167167
await this.handleChangeEvents()
168168
})
169169

170+
this.on('solidity', 'compilerQueryParamsUpdated', async () => {
171+
await this.call('editor', 'discardLineTexts')
172+
await this.call('editor', 'clearErrorMarkers', [this.currentFile])
173+
await this.handleChangeEvents()
174+
})
175+
176+
this.on('solidity', 'compilerAppParamsUpdated', async () => {
177+
await this.call('editor', 'discardLineTexts')
178+
await this.call('editor', 'clearErrorMarkers', [this.currentFile])
179+
await this.handleChangeEvents()
180+
})
181+
182+
this.on('solidity', 'configFileChanged', async () => {
183+
await this.call('editor', 'discardLineTexts')
184+
await this.call('editor', 'clearErrorMarkers', [this.currentFile])
185+
await this.handleChangeEvents()
186+
})
187+
170188
this.on('filePanel', 'setWorkspace', async () => {
171189
await this.call('fileDecorator', 'clearFileDecorators')
172190
await this.importService.updateDirectoryCacheTimeStamp()

apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,35 @@ export default class CodeParserCompiler {
141141
this.compiler.set('useFileConfiguration', true)
142142
this.compiler.set('compilerRetriggerMode', CompilerRetriggerMode.retrigger)
143143

144-
if (await this.plugin.call('fileManager', 'exists','remappings.txt')) {
145-
const remappings = await this.plugin.call('fileManager', 'readFile','remappings.txt')
144+
const configFileContent =
145+
state.useFileConfiguration ?
146+
state.configFileContent :
147+
148+
{
149+
"language": "Solidity",
150+
"settings": {
151+
"optimizer": {
152+
"enabled": state.optimize,
153+
"runs": state.runs
154+
},
155+
"outputSelection": {
156+
"*": {
157+
"": ["ast"],
158+
"*": ["evm.gasEstimates"]
159+
}
160+
},
161+
"evmVersion": state.evmVersion && state.evmVersion.toString() || undefined,
162+
}
163+
}
164+
165+
this.compiler.set('configFileContent', state.useFileConfiguration? configFileContent: JSON.stringify(configFileContent))
166+
167+
if (await this.plugin.call('fileManager', 'exists', 'remappings.txt')) {
168+
const remappings = await this.plugin.call('fileManager', 'readFile', 'remappings.txt')
146169
this.compiler.set('remappings', remappings.split('\n').filter(Boolean))
147170
} else {
148171
this.compiler.set('remappings', [])
149172
}
150-
151-
const configFileContent = {
152-
"language": "Solidity",
153-
"settings": {
154-
"optimizer": {
155-
"enabled": state.optimize,
156-
"runs": state.runs
157-
},
158-
"outputSelection": {
159-
"*": {
160-
"": ["ast"],
161-
"*": ["evm.gasEstimates"]
162-
}
163-
},
164-
"evmVersion": state.evmVersion && state.evmVersion.toString() || undefined,
165-
}
166-
}
167-
168-
this.compiler.set('configFileContent', JSON.stringify(configFileContent))
169173
const content = await this.plugin.call('fileManager', 'readFile', this.plugin.currentFile)
170174
const sources = { [this.plugin.currentFile]: { content } }
171175
this.compiler.compile(sources, this.plugin.currentFile)

apps/remix-ide/src/app/plugins/solidity-script.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SolidityScript extends Plugin {
4444
evmVersion: params.evmVersion,
4545
optimizer: {
4646
enabled: params.optimize,
47-
runs: params.run
47+
runs: params.runs
4848
}
4949
}
5050
const compilation = await compile(

apps/remix-ide/src/app/tabs/compile-tab.js

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const profile = {
2121
documentation: 'https://remix-ide.readthedocs.io/en/latest/compile.html',
2222
version: packageJson.version,
2323
maintainedBy: 'Remix',
24-
methods: ['getCompilationResult', 'compile', 'compileWithParameters', 'setCompilerConfig', 'compileFile', 'getCompilerState', 'getCompilerQueryParameters', 'getCompiler']
24+
methods: ['getCompilationResult', 'compile', 'compileWithParameters', 'setCompilerConfig', 'compileFile', 'getCompilerState', 'getCompilerConfig', 'getCompilerQueryParameters', 'getCompiler']
2525
}
2626

2727
// EditorApi:
2828
// - events: ['compilationFinished'],
2929
// - methods: ['getCompilationResult']
3030

3131
export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerApi
32-
constructor (config, fileManager) {
32+
constructor(config, fileManager) {
3333
super(profile)
3434
this.fileManager = fileManager
3535
this.config = config
@@ -42,55 +42,55 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
4242
this.el.setAttribute('id', 'compileTabView')
4343
}
4444

45-
renderComponent () {
45+
renderComponent() {
4646
// empty method, is a state update needed?
4747
}
4848

49-
onCurrentFileChanged () {
49+
onCurrentFileChanged() {
5050
this.renderComponent()
5151
}
5252

5353
// onResetResults () {
5454
// this.renderComponent()
5555
// }
5656

57-
onSetWorkspace () {
57+
onSetWorkspace() {
5858
this.renderComponent()
5959
}
6060

61-
onFileRemoved () {
61+
onFileRemoved() {
6262
this.renderComponent()
6363
}
6464

65-
onNoFileSelected () {
65+
onNoFileSelected() {
6666
this.renderComponent()
6767
}
6868

69-
onFileClosed () {
69+
onFileClosed() {
7070
this.renderComponent()
7171
}
7272

73-
onCompilationFinished () {
73+
onCompilationFinished() {
7474
this.renderComponent()
7575
}
7676

77-
render () {
78-
return <div id='compileTabView'><SolidityCompiler api={this}/></div>
77+
render() {
78+
return <div id='compileTabView'><SolidityCompiler api={this} /></div>
7979
}
8080

81-
async compileWithParameters (compilationTargets, settings) {
81+
async compileWithParameters(compilationTargets, settings) {
8282
return await super.compileWithParameters(compilationTargets, settings)
8383
}
8484

85-
getCompilationResult () {
85+
getCompilationResult() {
8686
return super.getCompilationResult()
8787
}
8888

89-
getFileManagerMode () {
89+
getFileManagerMode() {
9090
return this.fileManager.mode
9191
}
9292

93-
isDesktop () {
93+
isDesktop() {
9494
return Registry.getInstance().get('platform').api.isDesktop()
9595
}
9696

@@ -99,7 +99,7 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
9999
* This function is used by remix-plugin compiler API.
100100
* @param {object} settings {evmVersion, optimize, runs, version, language}
101101
*/
102-
async setCompilerConfig (settings) {
102+
async setCompilerConfig(settings) {
103103
super.setCompilerConfig(settings)
104104
this.renderComponent()
105105
// @todo(#2875) should use loading compiler return value to check whether the compiler is loaded instead of "setInterval"
@@ -108,20 +108,24 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
108108
pluginInfo = await this.call('udapp', 'showPluginDetails')
109109

110110
if (this.currentRequest.from === 'udapp') {
111-
this.call('notification', 'toast', compilerConfigChangedToastMsg((pluginInfo ? pluginInfo.displayName : this.currentRequest.from ), value))
111+
this.call('notification', 'toast', compilerConfigChangedToastMsg((pluginInfo ? pluginInfo.displayName : this.currentRequest.from), value))
112112
}
113113
}
114114

115-
compile (fileName) {
115+
async getCompilerConfig() {
116+
return await super.getCompilerConfig()
117+
}
118+
119+
compile(fileName) {
116120
if (!isNative(this.currentRequest.from)) this.call('notification', 'toast', compileToastMsg(this.currentRequest.from, fileName))
117121
super.compile(fileName)
118122
}
119123

120-
compileFile (event) {
124+
compileFile(event) {
121125
return super.compileFile(event)
122126
}
123127

124-
async onActivation () {
128+
async onActivation() {
125129
super.onActivation()
126130
this.on('filePanel', 'workspaceInitializationCompleted', () => {
127131
this.call('filePanel', 'registerContextMenuItem', {
@@ -134,6 +138,16 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
134138
pattern: [],
135139
group: 6
136140
})
141+
this.on('fileManager', 'fileSaved', async (file) => {
142+
if(await this.getAppParameter('configFilePath') === file) {
143+
this.emit('configFileChanged', file)
144+
}
145+
})
146+
this.on('fileManager', 'fileAdded', async (file) => {
147+
if(await this.getAppParameter('configFilePath') === file) {
148+
this.emit('configFileChanged', file)
149+
}
150+
})
137151
})
138152
try {
139153
this.currentFile = await this.call('fileManager', 'file')
@@ -142,28 +156,38 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
142156
}
143157
}
144158

145-
getCompiler () {
159+
getCompiler() {
146160
return this.compileTabLogic.compiler
147161
}
148162

149-
getCompilerQueryParameters () {
163+
getCompilerQueryParameters() {
150164
const params = this.queryParams.get()
151165
params.evmVersion = params.evmVersion === 'null' || params.evmVersion === 'undefined' ? null : params.evmVersion
152166
params.optimize = (params.optimize === 'false' || params.optimize === null || params.optimize === undefined) ? false : params.optimize
153167
params.optimize = params.optimize === 'true' ? true : params.optimize
154168
return params
155169
}
156170

157-
setCompilerQueryParameters (params) {
171+
setCompilerQueryParameters(params) {
158172
this.queryParams.update(params)
173+
try {
174+
this.emit('compilerQueryParamsUpdated')
175+
} catch (e) {
176+
// do nothing
177+
}
159178
}
160179

161-
async getAppParameter (name) {
180+
async getAppParameter(name) {
162181
return await this.call('config', 'getAppParameter', name)
163182
}
164183

165-
async setAppParameter (name, value) {
184+
async setAppParameter(name, value) {
166185
await this.call('config', 'setAppParameter', name, value)
186+
try {
187+
this.emit('compilerAppParamsUpdated')
188+
} catch (e) {
189+
// do nothing
190+
}
167191
}
168192
}
169193

apps/remix-ide/src/app/tabs/test-tab.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@ export default class TestTab extends ViewPlugin {
113113
const web3 = await this.call('blockchain', 'web3VM')
114114
await this.testRunner.init(web3)
115115
await this.createTestLibs()
116+
const runningTest = {}
117+
runningTest[path] = { content }
118+
const { currentVersion, evmVersion, optimize, runs } = await this.compileTab.getCurrentCompilerConfig()
119+
const currentCompilerUrl = urlFromVersion(currentVersion)
120+
const compilerConfig = {
121+
currentCompilerUrl,
122+
evmVersion,
123+
optimize,
124+
usingWorker: canUseWorker(currentVersion),
125+
runs
126+
}
116127
return new Promise((resolve, reject) => {
117-
const runningTest = {}
118-
runningTest[path] = { content }
119-
const { currentVersion, evmVersion, optimize, runs } = this.compileTab.getCurrentCompilerConfig()
120-
const currentCompilerUrl = urlFromVersion(currentVersion)
121-
const compilerConfig = {
122-
currentCompilerUrl,
123-
evmVersion,
124-
optimize,
125-
usingWorker: canUseWorker(currentVersion),
126-
runs
127-
}
128+
128129
this.testRunner.runTestSources(runningTest, compilerConfig, () => { /* Do nothing. */ }, () => { /* Do nothing. */ }, null, (error, result) => {
129130
if (error) return reject(error)
130131
resolve(result)

libs/remix-ui/solidity-compiler/src/lib/api/compiler-api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
122122
return this.compileTabLogic.compiler.state.lastCompilationResult
123123
}
124124

125-
getCompilerState () {
126-
return this.compileTabLogic.getCompilerState()
125+
async getCompilerState () {
126+
return await this.compileTabLogic.getCompilerState()
127127
}
128128

129129
/**
@@ -152,7 +152,7 @@ export const CompilerApiMixin = (Base) => class extends Base {
152152
* @param {object} settings {evmVersion, optimize, runs, version, language}
153153
*/
154154
async compileWithParameters (compilationTargets: Source, settings: CompilerInputOptions) {
155-
const compilerState = this.getCompilerState()
155+
const compilerState = await this.getCompilerState()
156156
const version = settings.version || compilerState.currentVersion
157157
const settingsCompile: CompilerInput = JSON.parse(compilerInputFactory(null, settings))
158158
const res = await compile(
@@ -165,8 +165,8 @@ export const CompilerApiMixin = (Base) => class extends Base {
165165
}
166166

167167
// This function is used for passing the compiler configuration to 'remix-tests'
168-
getCurrentCompilerConfig () {
169-
const compilerState = this.getCompilerState()
168+
async getCurrentCompilerConfig () {
169+
const compilerState = await this.getCompilerState()
170170
const compilerDetails: any = {
171171
currentVersion: compilerState.currentVersion,
172172
evmVersion: compilerState.evmVersion,

0 commit comments

Comments
 (0)