 NodeDebuggerView = require './node-debugger-view'
 jumpToBreakpoint = require './jump-to-breakpoint'
 
-log = (msg) -> # console.log(msg)
+log = (msg) -> console.log(msg)
 
 class ProcessManager extends EventEmitter
   constructor: (@atom = atom)->

      @process.once 'exit', onProcessEnd
      @process.once 'close', onProcessEnd

class BreakpointManager
  constructor: (@debugger) ->
    log "BreakpointManager.constructor"
    self = this
    @breakpoints = []
    @client = null
    @removeOnConnected = @debugger.subscribe 'connected', ->
      self.client = self.debugger.client
      log "BreakpointManager.connected #{@client}"
      self.attachBreakpoint breakpoint for breakpoint in self.breakpoints
    @removeOnDisconnected = @debugger.subscribe 'disconnected', ->
      log "BreakpointManager.disconnected"
      self.client = null
      for breakpoint in self.breakpoints
        breakpoint.id = null
        self.decorateBreakpoint breakpoint
    @onAddBreakpointEvent = Event()
    @onRemoveBreakpointEvent = Event()


        condition: breakpoint.condition
      }, (err, res) ->
        log "BreakpointManager.attachBreakpoint - done"
        if err
          breakpoint.clearId()
          reject(err)
        else
          breakpoint.setId(res.breakpoint)
          resolve(breakpoint)

  detachBreakpoint: (breakpointId) ->
    log "BreakpointManager.detachBreakpoint"
    self = this
    new Promise (resolve, reject) ->
      return resolve() unless self.client
      return resolve() unless breakpointId
      log "BreakpointManager.detachBreakpoint - client request"
      self.client.clearBreakpoint {
        breakpoint: breakpointId
      }, (err) ->
        resolve()

  tryFindBreakpoint: (script, line) ->
    return { breakpoint: breakpoint, index: i } for breakpoint, i in @breakpoints when breakpoint.script is script and breakpoint.line is line

class Debugger extends EventEmitter
  constructor: (@atom)->
