<commit_before>'use babel'

import { getBreakpoint, getBreakpoints, getBreakpointByName } from './store-utils'
import { location } from './utils'

export default class Debugger {
  constructor (store, connection) {
    this._connection = connection
    this._store = store
    this._stopPromise = null
  }

  dispose () {
    this.stop()
  }

  /**
   * Starts a new debugging session.
   * @param  {object} config The config used to start the debugger.
   * @param  {string} file   The file to debug
   * @return {Promise}
   */
  start (config, file) {
    if (this.isStarted()) {
      return Promise.resolve()
    }

    if (!config) {
      this._addOutputMessage(`Please select a configuration in the debugger panel on the right.\n`)
      return Promise.resolve()
    }

    this._store.dispatch({ type: 'SET_STATE', state: 'starting' })

    // clear the output panel
    if (atom.config.get('go-debug.clearOutputOnStart') === true) {
      this._store.dispatch({ type: 'CLEAR_OUTPUT_CONTENT' })
    }

    // start the debugger
    this._addOutputMessage(`Starting delve with config "${config.name}"\n`)

    return this._connection.start({ config, file })
      .then((session) => {
        this._addOutputMessage(`Started delve with config "${config.name}"\n`)
        this._store.dispatch({ type: 'SET_STATE', state: 'waiting' })

        this._session = session

        return Promise.all(
          getBreakpoints(this._store).map((bp) => {
            return this.addBreakpoint(bp.file, bp.line)
          })
        ).then(() => {
          // TODO if !config.stopOnEntry
          return this.resume()
        })
      })
      .catch((err) => {
        this._addOutputMessage(`Failed to start delve with config "${config.name}"\r\n  Error: ${err}\n`)
        return this.stop()
      })
  }

  /**
   * Stops a debugging session.
   * @return {Promise}
   */
  stop () {
    if (!this.isStarted()) {<commit_msg>log the err in case start fails<commit_after>'use babel'

import { getBreakpoint, getBreakpoints, getBreakpointByName } from './store-utils'
import { location } from './utils'

export default class Debugger {
  constructor (store, connection) {
    this._connection = connection
    this._store = store
    this._stopPromise = null
  }

  dispose () {
    this.stop()
  }

  /**
   * Starts a new debugging session.
   * @param  {object} config The config used to start the debugger.
   * @param  {string} file   The file to debug
   * @return {Promise}
   */
  start (config, file) {
    if (this.isStarted()) {
      return Promise.resolve()
    }

    if (!config) {
      this._addOutputMessage(`Please select a configuration in the debugger panel on the right.\n`)
      return Promise.resolve()
    }

    this._store.dispatch({ type: 'SET_STATE', state: 'starting' })

    // clear the output panel
    if (atom.config.get('go-debug.clearOutputOnStart') === true) {
      this._store.dispatch({ type: 'CLEAR_OUTPUT_CONTENT' })
    }

    // start the debugger
    this._addOutputMessage(`Starting delve with config "${config.name}"\n`)

    return this._connection.start({ config, file })
      .then((session) => {
        this._addOutputMessage(`Started delve with config "${config.name}"\n`)
        this._store.dispatch({ type: 'SET_STATE', state: 'waiting' })

        this._session = session

        return Promise.all(
          getBreakpoints(this._store).map((bp) => {
            return this.addBreakpoint(bp.file, bp.line)
          })
        ).then(() => {
          // TODO if !config.stopOnEntry
          return this.resume()
        })
      })
      .catch((err) => {
        console.warn('go-debug', 'start', err)
        this._addOutputMessage(`Failed to start delve with config "${config.name}"\r\n  Error: ${err}\n`)
        return this.stop()
      })
  }

  /**
   * Stops a debugging session.
   * @return {Promise}
   */
  stop () {
    if (!this.isStarted()) {
{'fraction_non_alphanumeric': 0.141656050955414, 'fraction_numerical': 0.0, 'mean_word_length': 2.49288256227758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7610498', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1167, 'n_words': 301}