|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|