diff --git a/src/app/files/compiler-metadata.js b/src/app/files/compiler-metadata.js new file mode 100644 index 0000000000..0b26ce193a --- /dev/null +++ b/src/app/files/compiler-metadata.js @@ -0,0 +1,49 @@ +'use strict' + +class CompilerMetadata { + constructor (events, opts) { + var self = this + self._events = events + self._opts = opts + } + + syncContractMetadata () { + var self = this + self._events.compiler.register('compilationFinished', (success, data, source) => { + if (success) { + var provider = self._opts.fileManager.currentFileProvider() + var path = self._opts.fileManager.currentPath() + if (provider && path) { + self._opts.compiler.visitContracts((contract) => { + var fileName = path + contract.name + '.json' + provider.get(fileName, (error, content) => { + if (!error) { + content = content || '{}' + var metadata + try { + metadata = JSON.parse(content) + } catch (e) { + console.log(e) + } + var linkReferences = metadata['linkReferences'] + if (!linkReferences) linkReferences = {} + for (var libFile in contract.object.evm.bytecode.linkReferences) { + if (!linkReferences[libFile]) linkReferences[libFile] = {} + for (var lib in contract.object.evm.bytecode.linkReferences[libFile]) { + if (!linkReferences[libFile][lib]) { + linkReferences[libFile][lib] = '
' + } + } + } + metadata['linkReferences'] = linkReferences + provider.set(fileName, JSON.stringify(metadata, null, '\t')) + } + }) + }) + } + } + }) + } +} + +module.exports = CompilerMetadata diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index fbaf2dc0d7..17e13486f4 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -71,6 +71,14 @@ class FileManager { this.refreshTabs() } + currentFileProvider () { + var path = this.currentPath() + if (path) { + return this.fileProviderOf(path) + } + return null + } + currentPath () { var self = this var currentFile = self._deps.config.get('currentFile') diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index b30bfb86eb..575464d29b 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -2,6 +2,7 @@ var async = require('async') var $ = require('jquery') var yo = require('yo-yo') +var CompilerMetadata = require('../files/compiler-metadata') var remixLib = require('remix-lib') var Gists = require('gists') var EventManager = remixLib.EventManager @@ -48,7 +49,8 @@ function filepanel (localRegistry) { self._deps = { fileProviders: self._components.registry.get('fileproviders').api, fileManager: self._components.registry.get('filemanager').api, - config: self._components.registry.get('config').api + config: self._components.registry.get('config').api, + compiler: self._components.registry.get('compiler').api } var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser']) var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost']) @@ -57,6 +59,18 @@ function filepanel (localRegistry) { var gistExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['gist']) var configExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['config']) + // ----------------- editor panel ---------------------- + self._compilerMetadata = new CompilerMetadata( + { + compiler: self._deps.compiler.event + }, + { + fileManager: self._deps.fileManager, + compiler: self._deps.compiler + } + ) + self._compilerMetadata.syncContractMetadata() + var dragbar = yo`` function remixdDialog () {