Commit 80b1017c authored by yann300's avatar yann300

use row position instead of char location

parent 4072af01
...@@ -2,42 +2,45 @@ ...@@ -2,42 +2,45 @@
var EventManager = require('../lib/eventManager') var EventManager = require('../lib/eventManager')
class breakpointManager { class breakpointManager {
constructor (_debugger) { constructor (_debugger, _locationToRowConverter) {
this.event = new EventManager() this.event = new EventManager()
this.debugger = _debugger this.debugger = _debugger
this.breakpoints = {} this.breakpoints = {}
this.isPlaying = false this.isPlaying = false
this.breakpointHits = {} this.locationToRowConverter = _locationToRowConverter
this.currentLine
} }
async play () { async play () {
if (this.hasBreakpoint()) { this.isPlaying = true
this.isPlaying = true var sourceLocation
var sourceLocation for (var currentStep = this.debugger.currentStepIndex + 1; currentStep < this.debugger.traceManager.trace.length; currentStep++) {
for (var currentStep = this.debugger.currentStepIndex; currentStep < this.debugger.traceManager.trace.length; currentStep++) { try {
try { sourceLocation = await this.debugger.callTree.extractSourceLocation(currentStep)
sourceLocation = await this.debugger.callTree.extractSourceLocation(currentStep) } catch (e) {
} catch (e) { console.log('cannot jump to breakpoint ' + e.message)
console.log('cannot jump to breakpoint ' + e.message) }
} if (this.locationToRowConverter) {
if (this.checkSourceLocation(sourceLocation, currentStep)) { var lineColumn = this.locationToRowConverter(sourceLocation)
this.debugger.stepManager.jumpTo(currentStep) if (this.currentLine === lineColumn.start.line) {
this.event.trigger('breakpointHit', [sourceLocation]) continue
break
} }
this.currentLine = lineColumn.start.line
}
if (this.checkSourceLocation(sourceLocation, currentStep, this.currentLine)) {
this.debugger.stepManager.jumpTo(currentStep)
this.event.trigger('breakpointHit', [sourceLocation])
break
} }
} }
} }
checkSourceLocation (sourceLocation, currentStep) { checkSourceLocation (sourceLocation, currentStep, currentLine) {
if (this.breakpoints[sourceLocation.file]) { if (this.breakpoints[sourceLocation.file]) {
var sources = this.breakpoints[sourceLocation.file] var sources = this.breakpoints[sourceLocation.file]
for (var k in sources) { for (var k in sources) {
var source = sources[k] var source = sources[k]
if (sourceLocation.start >= source.start && if (currentLine === source.row) {
sourceLocation.start < source.end &&
(this.breakpointHits[source.file][source.row] === currentStep || this.breakpointHits[source.file][source.row] === -1)) {
this.breakpointHits[source.file][source.row] = currentStep
return true return true
} }
} }
...@@ -59,10 +62,6 @@ class breakpointManager { ...@@ -59,10 +62,6 @@ class breakpointManager {
this.breakpoints[sourceLocation.file] = [] this.breakpoints[sourceLocation.file] = []
} }
this.breakpoints[sourceLocation.file].push(sourceLocation) this.breakpoints[sourceLocation.file].push(sourceLocation)
if (!this.breakpointHits[sourceLocation.file]) {
this.breakpointHits[sourceLocation.file] = {}
}
this.breakpointHits[sourceLocation.file][sourceLocation.row] = -1
} }
remove (sourceLocation) { remove (sourceLocation) {
...@@ -72,7 +71,6 @@ class breakpointManager { ...@@ -72,7 +71,6 @@ class breakpointManager {
var source = sources[k] var source = sources[k]
if (sourceLocation.start === source.start && sourceLocation.length === source.length) { if (sourceLocation.start === source.start && sourceLocation.length === source.length) {
sources.splice(k, 1) sources.splice(k, 1)
this.breakpointHits[sourceLocation.file][source.row] = undefined
break break
} }
} }
......
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