Commit 2bc69fc2 authored by Iuri Matias's avatar Iuri Matias Committed by yann300

move source highlighter out of debugger

parent c82501e9
...@@ -8,7 +8,7 @@ var globalRegistry = require('../../global/registry') ...@@ -8,7 +8,7 @@ var globalRegistry = require('../../global/registry')
/** /**
* Manage remix and source highlighting * Manage remix and source highlighting
*/ */
function Debugger (sourceHighlighter) { function Debugger () {
var self = this var self = this
this.event = new EventManager() this.event = new EventManager()
...@@ -65,7 +65,6 @@ function Debugger (sourceHighlighter) { ...@@ -65,7 +65,6 @@ function Debugger (sourceHighlighter) {
}) })
this.debugger.event.register('traceUnloaded', this, function () { this.debugger.event.register('traceUnloaded', this, function () {
self.sourceHighlighter.currentSourceLocation(null)
self.event.trigger('debuggerStatus', [false]) self.event.trigger('debuggerStatus', [false])
}) })
...@@ -80,19 +79,20 @@ function Debugger (sourceHighlighter) { ...@@ -80,19 +79,20 @@ function Debugger (sourceHighlighter) {
Debugger.prototype.registerAndHighlightCodeItem = function (index) { Debugger.prototype.registerAndHighlightCodeItem = function (index) {
const self = this const self = this
// register selected code item, highlight the corresponding source location // register selected code item, highlight the corresponding source location
if (self._deps.compiler.lastCompilationResult) { if (!self._deps.compilersArtefacts['__last']) return
self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
if (error) return console.log(error) if (error) return console.log(error)
self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self._deps.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { var compilerData = self._deps.compilersArtefacts['__last'].getdata()
if (!error && self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) { if (!compilerData) return
var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult.source.sources) self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, compilerData.contracts, function (error, rawLocation) {
self.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation) if (!error) {
} else { var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilerData.source.sources)
self.sourceHighlighter.currentSourceLocation(null) self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation])
} } else {
}) self.event.trigger('newSourceLocation', [null])
}
}) })
} })
} }
module.exports = Debugger module.exports = Debugger
...@@ -31,7 +31,10 @@ class DebuggerUI { ...@@ -31,7 +31,10 @@ class DebuggerUI {
constructor (container) { constructor (container) {
const self = this const self = this
this.transactionDebugger = new Debugger(new SourceHighlighter())
this.sourceHighlighter = new SourceHighlighter()
this.transactionDebugger = new Debugger(this.sourceHighlighter)
this.debugger = this.transactionDebugger.debugger this.debugger = this.transactionDebugger.debugger
this.isActive = false this.isActive = false
this.event = new EventManager() this.event = new EventManager()
...@@ -62,6 +65,7 @@ class DebuggerUI { ...@@ -62,6 +65,7 @@ class DebuggerUI {
listenToEvents () { listenToEvents () {
const self = this const self = this
this.transactionDebugger.event.register('debuggerStatus', function (isActive) { this.transactionDebugger.event.register('debuggerStatus', function (isActive) {
self.sourceHighlighter.currentSourceLocation(null)
self.isActive = isActive self.isActive = isActive
}) })
...@@ -72,6 +76,10 @@ class DebuggerUI { ...@@ -72,6 +76,10 @@ class DebuggerUI {
this.event.register('indexChanged', function (index) { this.event.register('indexChanged', function (index) {
self.transactionDebugger.registerAndHighlightCodeItem(index) self.transactionDebugger.registerAndHighlightCodeItem(index)
}) })
this.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
self.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation)
})
} }
startTxBrowser () { startTxBrowser () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment