pull/1/head
yann300 6 years ago
parent 3e5d997f15
commit f761fd6fa6
  1. 24
      src/app.js
  2. 41
      src/app/ui/renderer.js

@ -569,29 +569,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
// ----------------- Renderer -----------------
var rendererAPI = {
error: (file, error) => {
if (file === config.get('currentFile')) {
editor.addAnnotation(error)
}
},
errorClick: (errFile, errLine, errCol) => {
if (errFile !== config.get('currentFile')) {
// TODO: refactor with this._components.contextView.jumpTo
var provider = fileManager.fileProviderOf(errFile)
if (provider) {
provider.exists(errFile, (error, exist) => {
if (error) return console.log(error)
fileManager.switchFile(errFile)
editor.gotoLine(errLine, errCol)
})
}
} else {
editor.gotoLine(errLine, errCol)
}
}
}
var renderer = new Renderer(rendererAPI)
var renderer = new Renderer()
registry.put({api: renderer, name: 'renderer'})
// ----------------- StaticAnalysis -----------------

@ -3,19 +3,52 @@
var $ = require('jquery')
var yo = require('yo-yo')
var css = require('./styles/renderer-styles')
var globlalRegistry = require('../../global/registry')
/**
* After refactor, the renderer is only used to render error/warning
* TODO: This don't need to be an object anymore. Simplify and just export the renderError function.
*
*/
function Renderer (appAPI) {
this.appAPI = appAPI
function Renderer (localRegistry) {
const self = this
self._components = {}
self._components.registry = localRegistry || globlalRegistry
// dependencies
self._deps = {
editor: self._components.registry.get('editor').api,
fileManager: self._components.registry.get('filemanager').api,
config: self._components.registry.get('config').api
}
if (document && document.head) {
document.head.appendChild(css)
}
}
Renderer.prototype._error = function (file, error) {
const self = this
if (file === self._deps.config.get('currentFile')) {
self._deps.editor.addAnnotation(error)
}
}
Renderer.prototype._errorClick = function (errFile, errLine, errCol) {
const self = this
if (errFile !== self._deps.config.get('currentFile')) {
// TODO: refactor with this._components.contextView.jumpTo
var provider = self._deps.fileManager.fileProviderOf(errFile)
if (provider) {
provider.exists(errFile, (error, exist) => {
if (error) return console.log(error)
self._deps.fileManager.switchFile(errFile)
self._deps.editor.gotoLine(errLine, errCol)
})
}
} else {
self._deps.editor.gotoLine(errLine, errCol)
}
}
/**
* format msg like error or warning,
*
@ -45,7 +78,7 @@ Renderer.prototype.error = function (message, container, opt) {
}
if (!opt.noAnnotations && errLocation) {
this.appAPI.error(errLocation.errFile, {
this._error(errLocation.errFile, {
row: errLocation.errLine,
column: errLocation.errCol,
text: text,
@ -60,7 +93,7 @@ Renderer.prototype.error = function (message, container, opt) {
$error.click((ev) => {
if (opt.errFile && opt.errLine) {
this.appAPI.errorClick(opt.errFile, opt.errLine, opt.errCol)
this._errorClick(opt.errFile, opt.errLine, opt.errCol)
} else if (opt.click) {
opt.click(message)
}

Loading…
Cancel
Save