<commit_before>define (require) ->
  graphite = require 'graphite'

  _ = require 'underscore'
  CodeMirror = require 'cm/codemirror'
  require 'cm/javascript'
  require 'cm/coffeescript'
  require 'cm/runmode'
  require 'cm/show-hint'

  notebook = null
  require ['notebook'], (nb) ->
    notebook = nb

  token_after = (cm, token, line) ->
    t = token
    last_interesting_token = null
    loop
      next_token = cm.getTokenAt CodeMirror.Pos(line, t.end + 1)
      if t.start == next_token.start
        break
      if next_token.type?
        last_interesting_token = next_token
      t = next_token
    last_interesting_token

  suggest = (cm, showHints, options) ->
    cur = cm.getCursor()
    token = cm.getTokenAt(cur)
    if token.type is null
      list = (k for k of graphite.function_docs)
      showHints
        list: list
        from: CodeMirror.Pos cur.line, token.end
        to: CodeMirror.Pos cur.line, token.end
    else if token.type is 'string'
      open = token.string[0]
      string = token.string[1..]
      close = string[string.length - 1]
      if open == close
        string = string[...-1]
        end_offset = 1
      else
        end_offset = 0
      promise = graphite.complete string
      promise.done (list) ->
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start + 1
          to: CodeMirror.Pos cur.line, token.end - end_offset
    else
      full_s = token.string
      sub_s = full_s[...cur.ch-token.start]
      next_token = token_after cm, token, cur.line
      collect_suggestions = (s) ->
        list = []
        for k of notebook.available_context_fns cm.lead_cell.notebook
          if k.indexOf(s) is 0
            list.push k
        for k of graphite.function_docs
          if k.indexOf(s) is 0
            list.push k
        for k of graphite.parameter_docs
          if k.indexOf(s) is 0
            suggestion = k
            suggestion += ': ' unless next_token?.string is ':'
            list.push suggestion
        list
      list = collect_suggestions full_s
      if list.length > 0
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start
          to: CodeMirror.Pos cur.line, token.end
      else
        list = collect_suggestions sub_s
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start
          to: CodeMirror.Pos cur.line, cur.ch

  cmd = (doc, fn) ->
    fn.doc = doc
    fn

  commands =
    run: cmd 'Runs the contents of the cell and advances the cursor to the next cell', (cm) -><commit_msg>fix another reference to available_context_fns<commit_after>define (require) ->
  graphite = require 'graphite'

  _ = require 'underscore'
  CodeMirror = require 'cm/codemirror'
  require 'cm/javascript'
  require 'cm/coffeescript'
  require 'cm/runmode'
  require 'cm/show-hint'

  notebook = null
  require ['notebook'], (nb) ->
    notebook = nb

  token_after = (cm, token, line) ->
    t = token
    last_interesting_token = null
    loop
      next_token = cm.getTokenAt CodeMirror.Pos(line, t.end + 1)
      if t.start == next_token.start
        break
      if next_token.type?
        last_interesting_token = next_token
      t = next_token
    last_interesting_token

  suggest = (cm, showHints, options) ->
    cur = cm.getCursor()
    token = cm.getTokenAt(cur)
    if token.type is null
      list = (k for k of graphite.function_docs)
      showHints
        list: list
        from: CodeMirror.Pos cur.line, token.end
        to: CodeMirror.Pos cur.line, token.end
    else if token.type is 'string'
      open = token.string[0]
      string = token.string[1..]
      close = string[string.length - 1]
      if open == close
        string = string[...-1]
        end_offset = 1
      else
        end_offset = 0
      promise = graphite.complete string
      promise.done (list) ->
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start + 1
          to: CodeMirror.Pos cur.line, token.end - end_offset
    else
      full_s = token.string
      sub_s = full_s[...cur.ch-token.start]
      next_token = token_after cm, token, cur.line
      collect_suggestions = (s) ->
        list = []
        for k of cm.lead_cell.context.context_fns
          if k.indexOf(s) is 0
            list.push k
        for k of graphite.function_docs
          if k.indexOf(s) is 0
            list.push k
        for k of graphite.parameter_docs
          if k.indexOf(s) is 0
            suggestion = k
            suggestion += ': ' unless next_token?.string is ':'
            list.push suggestion
        list
      list = collect_suggestions full_s
      if list.length > 0
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start
          to: CodeMirror.Pos cur.line, token.end
      else
        list = collect_suggestions sub_s
        showHints
          list: list
          from: CodeMirror.Pos cur.line, token.start
          to: CodeMirror.Pos cur.line, cur.ch

  cmd = (doc, fn) ->
    fn.doc = doc
    fn

  commands =
    run: cmd 'Runs the contents of the cell and advances the cursor to the next cell', (cm) ->
{'fraction_non_alphanumeric': 0.09246773261413986, 'fraction_numerical': 0.004623386630706993, 'mean_word_length': 1.9333333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3663086', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1595, 'n_words': 455}