<commit_before>{View} = require 'space-pen'
$ = require 'jquery'
_ = require 'underscore'
SpellCheckTask = require './spell-check-task'
MisspellingView = require './misspelling-view'

module.exports =
class SpellCheckView extends View
  @content: ->
    @div class: 'spell-check'

  views: []

  initialize: (@editor) ->
    @subscribe @editor, 'editor:path-changed', => @subscribeToBuffer()
    @subscribe @editor, 'editor:grammar-changed', => @subscribeToBuffer()
    @observeConfig 'editor.fontSize', => @subscribeToBuffer()
    @observeConfig 'spell-check.grammars', => @subscribeToBuffer()

    @subscribeToBuffer()

  subscribeToBuffer: ->
    @destroyViews()
    @task?.abort()
    return unless @spellCheckCurrentGrammar()

    @buffer?.off '.spell-check'
    @buffer = @editor.getBuffer()
    @buffer.on 'contents-modified.spell-check', => @updateMisspellings()
    @updateMisspellings()

  spellCheckCurrentGrammar: ->
    grammar = @editor.getGrammar().scopeName
    _.contains config.get('spell-check.grammars'), grammar

  destroyViews: ->
    if @views
      view.destroy() for view in @views
      @views = []

  addView: (misspelling)->
    view = new MisspellingView(misspelling, @editor)
    @views.push(view)
    @append(view)

  updateMisspellings: ->
    @task?.abort()

    callback = (misspellings) =>
      @destroyViews()
      @addView(misspelling) for misspelling in misspellings
    @task = new SpellCheckTask(@buffer.getText(), callback)
    @task.start()
<commit_msg>Add addViews method to mirror destroyViews<commit_after>{View} = require 'space-pen'
_ = require 'underscore'
SpellCheckTask = require './spell-check-task'
MisspellingView = require './misspelling-view'

module.exports =
class SpellCheckView extends View
  @content: ->
    @div class: 'spell-check'

  views: []

  initialize: (@editor) ->
    @subscribe @editor, 'editor:path-changed', => @subscribeToBuffer()
    @subscribe @editor, 'editor:grammar-changed', => @subscribeToBuffer()
    @observeConfig 'editor.fontSize', => @subscribeToBuffer()
    @observeConfig 'spell-check.grammars', => @subscribeToBuffer()

    @subscribeToBuffer()

  subscribeToBuffer: ->
    @destroyViews()
    @task?.abort()
    return unless @spellCheckCurrentGrammar()

    @buffer?.off '.spell-check'
    @buffer = @editor.getBuffer()
    @buffer.on 'contents-modified.spell-check', => @updateMisspellings()
    @updateMisspellings()

  spellCheckCurrentGrammar: ->
    grammar = @editor.getGrammar().scopeName
    _.contains config.get('spell-check.grammars'), grammar

  destroyViews: ->
    if @views
      view.destroy() for view in @views
      @views = []

  addViews: (misspellings) ->
    for misspelling in misspellings
      view = new MisspellingView(misspelling, @editor)
      @views.push(view)
      @append(view)

  updateMisspellings: ->
    @task?.abort()

    callback = (misspellings) =>
      @destroyViews()
      @addViews(misspellings)
    @task = new SpellCheckTask(@buffer.getText(), callback)
    @task.start()

{'fraction_non_alphanumeric': 0.14517732847199205, 'fraction_numerical': 0.0, 'mean_word_length': 3.8443017656500804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '7553454', 'n_tokens_mistral': 964, 'n_tokens_neox': 959, 'n_words': 187}