instanciate PluginManager in app.js and use it for compilation notification

pull/3094/head
yann300 6 years ago
parent aa168c64b5
commit c1d7ab499a
  1. 17
      src/app.js
  2. 5
      src/app/editor/contextualListener.js
  3. 10
      src/app/files/compiler-metadata.js
  4. 14
      src/app/panels/editor-panel.js
  5. 7
      src/app/panels/file-panel.js
  6. 48
      src/app/plugin/pluginManager.js
  7. 3
      src/app/tabs/compile-tab.js

@ -362,6 +362,23 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
var fileManager = self._components.fileManager var fileManager = self._components.fileManager
registry.put({api: fileManager, name: 'filemanager'}) registry.put({api: fileManager, name: 'filemanager'})
// ---------------- Plugin Manager -------------------------------
let pluginManager = new PluginManager(
self,
self._components.compilersArtefacts,
txlistener,
self._components.fileProviders,
self._components.fileManager,
udapp)
registry.put({api: pluginManager, name: 'pluginmanager'})
pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => {
// TODO check whether the tab is configured
let compiler = new CompilerAbstract(languageVersion, data, source)
self._components.compilersArtefacts['__last'] = compiler
})
self._components.editorpanel.init() self._components.editorpanel.init()
self._components.fileManager.init() self._components.fileManager.init()

@ -15,6 +15,7 @@ class ContextualListener {
self._components = {} self._components = {}
self._components.registry = localRegistry || globalRegistry self._components.registry = localRegistry || globalRegistry
self.editor = opts.editor self.editor = opts.editor
self.pluginManager = opts.pluginManager
self._deps = { self._deps = {
compilersArtefacts: self._components.registry.get('compilersartefacts').api, compilersArtefacts: self._components.registry.get('compilersartefacts').api,
config: self._components.registry.get('config').api, config: self._components.registry.get('config').api,
@ -26,15 +27,13 @@ class ContextualListener {
} }
this._activeHighlights = [] this._activeHighlights = []
self._deps.compiler.event.register('compilationFinished', (success, data, source) => { self.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => {
this._stopHighlighting() this._stopHighlighting()
this._index = { this._index = {
Declarations: {}, Declarations: {},
FlatReferences: {} FlatReferences: {}
} }
if (success) {
this._buildIndex(data, source) this._buildIndex(data, source)
}
}) })
self.editor.event.register('contentChanged', () => { this._stopHighlighting() }) self.editor.event.register('contentChanged', () => { this._stopHighlighting() })

@ -1,23 +1,23 @@
'use strict' 'use strict'
var executionContext = require('../../execution-context') var executionContext = require('../../execution-context')
var CompilerAbstract = require('../compiler/compiler-abstract')
class CompilerMetadata { class CompilerMetadata {
constructor (events, opts) { constructor (opts) {
var self = this var self = this
self._events = events
self._opts = opts self._opts = opts
self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'Custom'] self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42', 'Custom']
} }
syncContractMetadata () { syncContractMetadata () {
var self = this var self = this
self._events.compiler.register('compilationFinished', (success, data, source) => { self._opts.pluginManager.event.register('sendCompilationResult', (file, source, languageVersion, data) => {
if (!success) return
if (!self._opts.config.get('settings/generate-contract-metadata')) return if (!self._opts.config.get('settings/generate-contract-metadata')) return
let compiler = new CompilerAbstract(languageVersion, data, source)
var provider = self._opts.fileManager.currentFileProvider() var provider = self._opts.fileManager.currentFileProvider()
var path = self._opts.fileManager.currentPath() var path = self._opts.fileManager.currentPath()
if (provider && path) { if (provider && path) {
self._opts.compiler.visitContracts((contract) => { compiler.visitContracts((contract) => {
if (contract.file !== source.target) return if (contract.file !== source.target) return
var fileName = path + '/' + contract.name + '.json' var fileName = path + '/' + contract.name + '.json'

@ -26,7 +26,7 @@ class EditorPanel {
txListener: self._components.registry.get('txlistener').api, txListener: self._components.registry.get('txlistener').api,
fileManager: self._components.registry.get('filemanager').api, fileManager: self._components.registry.get('filemanager').api,
udapp: self._components.registry.get('udapp').api, udapp: self._components.registry.get('udapp').api,
compiler: self._components.registry.get('compiler').api pluginManager: self._components.registry.get('pluginmanager').api
} }
self.data = { self.data = {
_FILE_SCROLL_DELTA: 200, _FILE_SCROLL_DELTA: 200,
@ -40,16 +40,18 @@ class EditorPanel {
self._view = {} self._view = {}
var editor = new Editor({}) var editor = new Editor({})
self._components.registry.put({api: editor, name: 'editor'}) self._components.registry.put({api: editor, name: 'editor'})
var contextualListener = new ContextualListener({editor: editor})
var contextualListener = new ContextualListener({editor, pluginManager: self._deps.pluginManager})
var contextView = new ContextView({contextualListener, editor})
self._components = { self._components = {
editor: editor, editor: editor,
contextualListener: contextualListener, contextualListener: contextualListener,
contextView: new ContextView({contextualListener: contextualListener, editor: editor}), contextView: contextView,
// TODO list of compilers is always empty; should find a path to add plugin compiler here
terminal: new Terminal({ terminal: new Terminal({
udapp: self._deps.udapp, udapp: self._deps.udapp,
compilers: { compilers: {}
'solidity': self._deps.compiler
}
}, },
{ {
getPosition: (event) => { getPosition: (event) => {

@ -49,7 +49,7 @@ function filepanel (localRegistry) {
fileProviders: self._components.registry.get('fileproviders').api, fileProviders: self._components.registry.get('fileproviders').api,
fileManager: self._components.registry.get('filemanager').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 pluginManager: self._components.registry.get('pluginmanager').api,
} }
var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser']) var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser'])
var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost']) var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost'])
@ -62,12 +62,9 @@ function filepanel (localRegistry) {
// ----------------- editor panel ---------------------- // ----------------- editor panel ----------------------
self._compilerMetadata = new CompilerMetadata( self._compilerMetadata = new CompilerMetadata(
{
compiler: self._deps.compiler.event
},
{ {
fileManager: self._deps.fileManager, fileManager: self._deps.fileManager,
compiler: self._deps.compiler, pluginManager: self._deps.pluginManager,
config: self._deps.config config: self._deps.config
} }
) )

@ -101,14 +101,6 @@ module.exports = class PluginManager {
value: [ file ] value: [ file ]
})) }))
}) })
compiler.event.register('compilationFinished', (success, data, source) => {
self.broadcast(JSON.stringify({
action: 'notification',
key: 'compiler',
type: 'compilationFinished',
value: [ success, data, source ]
}))
})
txlistener.event.register('newTransaction', (tx) => { txlistener.event.register('newTransaction', (tx) => {
self.broadcast(JSON.stringify({ self.broadcast(JSON.stringify({
@ -119,38 +111,6 @@ module.exports = class PluginManager {
})) }))
}) })
app.event.register('tabChanged', (tabName) => {
// TODO Fix this cause this event is no longer triggered
if (self.inFocus && self.inFocus !== tabName) {
// trigger unfocus
self.post(self.inFocus, JSON.stringify({
action: 'notification',
key: 'app',
type: 'unfocus',
value: []
}))
}
if (self.plugins[tabName]) {
// trigger focus
self.post(tabName, JSON.stringify({
action: 'notification',
key: 'app',
type: 'focus',
value: []
}))
self.inFocus = tabName
pluginAPI.compiler.getCompilationResult(tabName, (error, data) => {
if (!error) return
self.post(tabName, JSON.stringify({
action: 'notification',
key: 'compiler',
type: 'compilationData',
value: [data]
}))
})
}
})
window.addEventListener('message', (event) => { window.addEventListener('message', (event) => {
if (event.type !== 'message') return if (event.type !== 'message') return
var extension = self.origins[event.origin] var extension = self.origins[event.origin]
@ -202,7 +162,13 @@ module.exports = class PluginManager {
receivedDataFrom (methodName, mod, argumentsArray) { receivedDataFrom (methodName, mod, argumentsArray) {
// TODO check whether 'mod' as right to do that // TODO check whether 'mod' as right to do that
console.log(argumentsArray) console.log(argumentsArray)
this.event.trigger(methodName, argumentsArray) this.event.trigger(methodName, argumentsArray) // forward to internal modules
this.broadcast(JSON.stringify({ // forward to plugins
action: 'notification',
key: mod,
type: methodName,
value: argumentsArray
}))
} }
post (name, value) { post (name, value) {
const self = this const self = this

@ -56,6 +56,7 @@ module.exports = class CompileTab {
swarmfileProvider: self._components.registry.get('fileproviders/swarm').api, swarmfileProvider: self._components.registry.get('fileproviders/swarm').api,
fileManager: self._components.registry.get('filemanager').api, fileManager: self._components.registry.get('filemanager').api,
fileProviders: self._components.registry.get('fileproviders').api, fileProviders: self._components.registry.get('fileproviders').api,
pluginManager: self._components.registry.get('pluginmanager').api
} }
self.data = { self.data = {
hideWarnings: self._deps.config.get('hideWarnings') || false, hideWarnings: self._deps.config.get('hideWarnings') || false,
@ -127,6 +128,8 @@ module.exports = class CompileTab {
// refill the dropdown list // refill the dropdown list
self._view.contractNames.innerHTML = '' self._view.contractNames.innerHTML = ''
if (success) { if (success) {
// TODO consider using compile tab as a proper module instead of just forwarding event
self._deps.pluginManager.receivedDataFrom('sendCompilationResult', 'solidity-compiler', [data.target, source, self.data.selectedVersion, data] )
self._view.contractNames.removeAttribute('disabled') self._view.contractNames.removeAttribute('disabled')
self._components.compiler.visitContracts(contract => { self._components.compiler.visitContracts(contract => {
self.data.contractsDetails[contract.name] = parseContracts(contract.name, contract.object, self._components.compiler.getSource(contract.file)) self.data.contractsDetails[contract.name] = parseContracts(contract.name, contract.object, self._components.compiler.getSource(contract.file))

Loading…
Cancel
Save