From 2bc69fc2587d5985da35a4164f1e51dd1386621f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 2 Oct 2018 16:33:16 -0400 Subject: [PATCH] move source highlighter out of debugger --- src/app/debugger/debugger.js | 28 ++++++++++++++-------------- src/app/debugger/debuggerUI.js | 10 +++++++++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/app/debugger/debugger.js b/src/app/debugger/debugger.js index e1f8667390..fb681bce03 100644 --- a/src/app/debugger/debugger.js +++ b/src/app/debugger/debugger.js @@ -8,7 +8,7 @@ var globalRegistry = require('../../global/registry') /** * Manage remix and source highlighting */ -function Debugger (sourceHighlighter) { +function Debugger () { var self = this this.event = new EventManager() @@ -65,7 +65,6 @@ function Debugger (sourceHighlighter) { }) this.debugger.event.register('traceUnloaded', this, function () { - self.sourceHighlighter.currentSourceLocation(null) self.event.trigger('debuggerStatus', [false]) }) @@ -80,19 +79,20 @@ function Debugger (sourceHighlighter) { Debugger.prototype.registerAndHighlightCodeItem = function (index) { const self = this // register selected code item, highlight the corresponding source location - if (self._deps.compiler.lastCompilationResult) { - self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { - if (error) return console.log(error) - self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self._deps.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { - if (!error && self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) { - var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult.source.sources) - self.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation) - } else { - self.sourceHighlighter.currentSourceLocation(null) - } - }) + if (!self._deps.compilersArtefacts['__last']) return + self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { + if (error) return console.log(error) + var compilerData = self._deps.compilersArtefacts['__last'].getdata() + if (!compilerData) return + self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, compilerData.contracts, function (error, rawLocation) { + if (!error) { + var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilerData.source.sources) + self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) + } else { + self.event.trigger('newSourceLocation', [null]) + } }) - } + }) } module.exports = Debugger diff --git a/src/app/debugger/debuggerUI.js b/src/app/debugger/debuggerUI.js index d35bbe7637..f6e495f1e0 100644 --- a/src/app/debugger/debuggerUI.js +++ b/src/app/debugger/debuggerUI.js @@ -31,7 +31,10 @@ class DebuggerUI { constructor (container) { 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.isActive = false this.event = new EventManager() @@ -62,6 +65,7 @@ class DebuggerUI { listenToEvents () { const self = this this.transactionDebugger.event.register('debuggerStatus', function (isActive) { + self.sourceHighlighter.currentSourceLocation(null) self.isActive = isActive }) @@ -72,6 +76,10 @@ class DebuggerUI { this.event.register('indexChanged', function (index) { self.transactionDebugger.registerAndHighlightCodeItem(index) }) + + this.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { + self.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation) + }) } startTxBrowser () {