<commit_before>SyncPrompt = require('./sync_prompt')
Output = require('./output/local_output')
commands = require('./commands')
AutoComplete = require('./completion')
File = require('./file')

class App

  _commands: []

  constructor: (@scope) ->
    @output = new Output()
    @stack = new Error().stack
    @prompt = new SyncPrompt(typeahead: new AutoComplete(@scope, @find_file()).autocomplete)
    @prompt.on('data', @find_command)

  commands: ->
    if @_commands.length is 0
      @_commands.push new command({@output, @scope, @prompt, app: @}) for _, command of commands
    @_commands

  find_command: (input, chain) =>
    for command in @commands()
      if match = command.match(input.trim())
        args = String(match[1]).trim().split(' ')
        return command.execute.call command, args, chain
    false

  open: ->
    @prompt.type('whereami')
    @prompt.open()

  find_file: ->
    return @file if @file
    @file = do =>
      foundCall = false
      for item in @stack.split('\n')
        if foundCall
          [_, file, line] = item.match(/([^ (:]+):(\d+):\d+/)
          return new File(file, line) if file isnt '<anonymous>'
        else if item.match /Pry\.open/
          foundCall = true
      new File(__filename, 1)


module.exports = App
<commit_msg>regexp goes throught the stack to find the file<commit_after>SyncPrompt = require('./sync_prompt')
Output = require('./output/local_output')
commands = require('./commands')
AutoComplete = require('./completion')
File = require('./file')

class App

  _commands: []

  constructor: (@scope) ->
    @output = new Output()
    @stack = new Error().stack
    @prompt = new SyncPrompt(typeahead: new AutoComplete(@scope, @find_file()).autocomplete)
    @prompt.on('data', @find_command)

  commands: ->
    if @_commands.length is 0
      @_commands.push new command({@output, @scope, @prompt, app: @}) for _, command of commands
    @_commands

  find_command: (input, chain) =>
    for command in @commands()
      if match = command.match(input.trim())
        args = String(match[1]).trim().split(' ')
        return command.execute.call command, args, chain
    false

  open: ->
    @prompt.type('whereami')
    @prompt.open()

  find_file: ->
    @file or= do =>
      # match the first line after Pry.open that isnt in "file" <anonymous>
      [_, file, line] = @stack.match(/at Pry.open.*(?:\s+at.*<anonymous>:.*\s|\s+at.*\(([^:]*)\:(\d+))+/)
      new File(file or __filename, line or 1)

module.exports = App

{'fraction_non_alphanumeric': 0.1672, 'fraction_numerical': 0.0024, 'mean_word_length': 3.0799347471451877, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '3349063', 'n_tokens_mistral': 810, 'n_tokens_neox': 772, 'n_words': 206}