Commit db94d928 authored by Aniket-Engg's avatar Aniket-Engg

pickup compiler version from pragma

checks improved support for fixed pragma version range pragma handled suggested changes linting fix load compiler before compilation too if statement removed using semver nightly build support linting fix
parent 244ba6c8
...@@ -32,6 +32,9 @@ class CompilerContainer { ...@@ -32,6 +32,9 @@ class CompilerContainer {
* Update the compilation button with the name of the current file * Update the compilation button with the name of the current file
*/ */
set currentFile (name = '') { set currentFile (name = '') {
if (name && name !== '') {
this._setCompilerVersionFromPragma(name)
}
if (!this._view.compilationButton) return if (!this._view.compilationButton) return
const button = this.compilationButton(name.split('/').pop()) const button = this.compilationButton(name.split('/').pop())
yo.update(this._view.compilationButton, button) yo.update(this._view.compilationButton, button)
...@@ -113,6 +116,23 @@ class CompilerContainer { ...@@ -113,6 +116,23 @@ class CompilerContainer {
return el return el
} }
_setCompilerVersionFromPragma (filename) {
this.compileTabLogic.fileManager.getFile(filename).then(data => {
const pragmaArr = data.match(/(pragma solidity (.+?);)/g)
if (pragmaArr && pragmaArr.length === 1) {
const pragmaStr = pragmaArr[0].replace('pragma solidity', '').trim()
const pragma = pragmaStr.substring(0, pragmaStr.length - 1)
const fixedVersions = this.data.allversions.filter(obj => !obj.prerelease).map(obj => obj.version)
const compilerToLoad = semver.maxSatisfying(fixedVersions, pragma)
const compilerPath = this.data.allversions.filter(obj => !obj.prerelease && obj.version === compilerToLoad)[0].path
if (this.data.selectedVersion !== compilerPath) {
this.data.selectedVersion = compilerPath
this._updateVersionSelector()
}
}
})
}
_retrieveVersion () { _retrieveVersion () {
let version = this._view.versionSelector.value let version = this._view.versionSelector.value
return version.substring(9, version.length) return version.substring(9, version.length)
...@@ -243,6 +263,9 @@ class CompilerContainer { ...@@ -243,6 +263,9 @@ class CompilerContainer {
compile (event) { compile (event) {
if (this.config.get('currentFile')) { if (this.config.get('currentFile')) {
if (!this.data.selectedVersion.includes('nightly')) {
this._setCompilerVersionFromPragma(this.config.get('currentFile'))
}
this.compileTabLogic.runCompiler() this.compileTabLogic.runCompiler()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment