           callback result.slice(0,-1).map (line)->
             line.replace /\0/g,'\n'
     if text?
+      debug "sending stdin text to #{modPath}"
       process.process.stdin.write "#{text}\x04\n"
 
   runModiCmd: ({dir,options,command,text,uri,args,callback}) =>
+    debug "Trying to run ghc-modi in #{dir.getPath()}"
     process=@spawnProcess(dir,options)
     unless process
+      debug "Failed. Falling back to ghc-mod"
       return @runModCmd {options,command,text,uri,args,callback}
     parseData = (data)->
+      debug "Got response from ghc-modi:\n#{data}"
       lines = "#{data}".split("\n")
       result = lines[lines.length-2]
       unless result.match(/^OK/)


  destroy: =>
    return unless @processMap?
    @killProcess()
    @emitter.emit 'did-destroy'
    @emitter = null

      cmd = [command, uri].concat args
    else
      cmd = [command].concat args
    debug "Running ghc-modi command #{cmd}"
    process.stdin.write cmd.join(' ').replace(/\r|\r?\n/g,' ') + '\n'

    if text?
      debug "Unloading file text from ghc-modi"
      process.stdin.write "unload #{uri}\n"

  killProcess: =>
    return unless @processMap?
    debug "Killing all ghc-modi processes"
    atom.project.getDirectories().forEach (dir) =>
      @killProcessForDir dir

  killProcessForDir: (dir) =>
    return unless @processMap?
    debug "Killing ghc-modi process for #{dir.getPath()}"
    clearTimeout @processMap.get(dir)?.timer
    @processMap.get(dir)?.process.stdin?.end?()
    @processMap.get(dir)?.process.kill?()
