Skip to content

Commit ef922c5

Browse files
committed
fix parser compiler
1 parent 048d8d1 commit ef922c5

File tree

4 files changed

+92
-65
lines changed

4 files changed

+92
-65
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ export class CodeParser extends Plugin {
170170
this.on('solidity', 'compilerQueryParamsUpdated', async (file) => {
171171
await this.call('editor', 'discardLineTexts')
172172
await this.handleChangeEvents()
173-
})
173+
})
174+
175+
this.on('solidity', 'compilerAppParamsUpdated', async (file) => {
176+
await this.call('editor', 'discardLineTexts')
177+
await this.handleChangeEvents()
178+
})
179+
180+
this.on('solidity', 'configFileChanged', async (file) => {
181+
await this.call('editor', 'discardLineTexts')
182+
await this.handleChangeEvents()
183+
})
174184

175185
this.on('filePanel', 'setWorkspace', async () => {
176186
await this.call('fileDecorator', 'clearFileDecorators')

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,39 +134,43 @@ export default class CodeParserCompiler {
134134
this.plugin.currentFile = await this.plugin.call('fileManager', 'file')
135135
if (this.plugin.currentFile && this.plugin.currentFile.endsWith('.sol')) {
136136
const state = await this.plugin.call('solidity', 'getCompilerState')
137-
console.log('state', state)
138137
this.compiler.set('optimize', state.optimize)
139138
this.compiler.set('evmVersion', state.evmVersion)
140139
this.compiler.set('language', state.language)
141140
this.compiler.set('runs', state.runs)
142141
this.compiler.set('useFileConfiguration', true)
143142
this.compiler.set('compilerRetriggerMode', CompilerRetriggerMode.retrigger)
144143

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

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

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const profile = {
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,24 +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-
async getCompilerConfig () {
115+
async getCompilerConfig() {
116116
return await super.getCompilerConfig()
117117
}
118118

119-
compile (fileName) {
119+
compile(fileName) {
120120
if (!isNative(this.currentRequest.from)) this.call('notification', 'toast', compileToastMsg(this.currentRequest.from, fileName))
121121
super.compile(fileName)
122122
}
123123

124-
compileFile (event) {
124+
compileFile(event) {
125125
return super.compileFile(event)
126126
}
127127

128-
async onActivation () {
128+
async onActivation() {
129129
super.onActivation()
130130
this.on('filePanel', 'workspaceInitializationCompleted', () => {
131131
this.call('filePanel', 'registerContextMenuItem', {
@@ -138,6 +138,16 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
138138
pattern: [],
139139
group: 6
140140
})
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+
})
141151
})
142152
try {
143153
this.currentFile = await this.call('fileManager', 'file')
@@ -146,11 +156,11 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
146156
}
147157
}
148158

149-
getCompiler () {
159+
getCompiler() {
150160
return this.compileTabLogic.compiler
151161
}
152162

153-
getCompilerQueryParameters () {
163+
getCompilerQueryParameters() {
154164
const params = this.queryParams.get()
155165
console.log('getCompilerQueryParameters', params)
156166
params.evmVersion = params.evmVersion === 'null' || params.evmVersion === 'undefined' ? null : params.evmVersion
@@ -159,24 +169,28 @@ export default class CompileTab extends CompilerApiMixin(ViewPlugin) { // implem
159169
return params
160170
}
161171

162-
setCompilerQueryParameters (params) {
172+
setCompilerQueryParameters(params) {
163173
console.log('setCompilerQueryParameters', params)
164174
this.queryParams.update(params)
165-
try{
175+
try {
166176
this.emit('compilerQueryParamsUpdated')
167-
} catch (e) {}
177+
} catch (e) {
178+
// do nothing
179+
}
168180
}
169181

170-
async getAppParameter (name) {
182+
async getAppParameter(name) {
171183
return await this.call('config', 'getAppParameter', name)
172184
}
173185

174-
async setAppParameter (name, value) {
186+
async setAppParameter(name, value) {
175187
console.log('setAppParameter', name, value)
176188
await this.call('config', 'setAppParameter', name, value)
177-
try{
178-
this.emit('compilerQueryParamsUpdated')
179-
} catch (e) {}
189+
try {
190+
this.emit('compilerAppParamsUpdated')
191+
} catch (e) {
192+
// do nothing
193+
}
180194
}
181195
}
182196

libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,21 @@ export class CompileTabLogic {
110110
}
111111

112112
async setCompilerMappings () {
113-
if (await this.api.fileExists('remappings.txt')) {
114-
this.api.readFile('remappings.txt').then(remappings => {
115-
this.compiler.set('remappings', remappings.split('\n').filter(Boolean))
116-
})
117-
} else this.compiler.set('remappings', [])
113+
if (await this.api.fileExists('remappings.txt')) {
114+
this.api.readFile('remappings.txt').then(remappings => {
115+
this.compiler.set('remappings', remappings.split('\n').filter(Boolean))
116+
})
117+
} else this.compiler.set('remappings', [])
118118
}
119-
119+
120120
async setCompilerConfigContent () {
121-
if (this.configFilePath && this.useFileConfiguration) {
122-
this.api.readFile(this.configFilePath).then(content => {
123-
this.compiler.set('configFileContent', content)
124-
})
125-
}
121+
if (this.configFilePath && this.useFileConfiguration) {
122+
this.api.readFile(this.configFilePath).then(content => {
123+
this.compiler.set('configFileContent', content)
124+
})
125+
}
126126
}
127127

128-
129128
/**
130129
* Compile a specific file of the file manager
131130
* @param {string} target the path to the file to compile

0 commit comments

Comments
 (0)