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

pull/3094/head
yann300 6 years ago
parent aa168c64b5
commit c1d7ab499a
  1. 19
      src/app.js
  2. 7
      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. 50
      src/app/plugin/pluginManager.js
  7. 3
      src/app/tabs/compile-tab.js

@ -303,7 +303,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
registry.put({api: msg => self._components.editorpanel.logHtmlMessage(msg), name: 'logCallback'})
// helper for converting offset to line/column
var offsetToLineColumnConverter = new OffsetToLineColumnConverter()
registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'})
@ -362,6 +362,23 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
var fileManager = self._components.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.fileManager.init()

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

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

@ -26,7 +26,7 @@ class EditorPanel {
txListener: self._components.registry.get('txlistener').api,
fileManager: self._components.registry.get('filemanager').api,
udapp: self._components.registry.get('udapp').api,
compiler: self._components.registry.get('compiler').api
pluginManager: self._components.registry.get('pluginmanager').api
}
self.data = {
_FILE_SCROLL_DELTA: 200,
@ -40,16 +40,18 @@ class EditorPanel {
self._view = {}
var editor = new 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 = {
editor: editor,
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({
udapp: self._deps.udapp,
compilers: {
'solidity': self._deps.compiler
}
compilers: {}
},
{
getPosition: (event) => {

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

@ -101,15 +101,7 @@ module.exports = class PluginManager {
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) => {
self.broadcast(JSON.stringify({
action: 'notification',
@ -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) => {
if (event.type !== 'message') return
var extension = self.origins[event.origin]
@ -202,7 +162,13 @@ module.exports = class PluginManager {
receivedDataFrom (methodName, mod, argumentsArray) {
// TODO check whether 'mod' as right to do that
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) {
const self = this

@ -56,6 +56,7 @@ module.exports = class CompileTab {
swarmfileProvider: self._components.registry.get('fileproviders/swarm').api,
fileManager: self._components.registry.get('filemanager').api,
fileProviders: self._components.registry.get('fileproviders').api,
pluginManager: self._components.registry.get('pluginmanager').api
}
self.data = {
hideWarnings: self._deps.config.get('hideWarnings') || false,
@ -127,6 +128,8 @@ module.exports = class CompileTab {
// refill the dropdown list
self._view.contractNames.innerHTML = ''
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._components.compiler.visitContracts(contract => {
self.data.contractsDetails[contract.name] = parseContracts(contract.name, contract.object, self._components.compiler.getSource(contract.file))

Loading…
Cancel
Save