<commit_before>/* @flow */

import { TextEditor } from "atom";
import { action } from "mobx";

import OutputStore from "./output";
import { log } from "./../utils";

import type Kernel from "./../kernel";

export default class WatchStore {
  kernel: Kernel;
  editor: TextEditor;
  outputStore = new OutputStore();

  constructor(kernel: Kernel) {
    this.kernel = kernel;
    this.editor = atom.workspace.buildTextEditor({
      softWrapped: true,
      lineNumberGutterVisible: false
    });
    atom.grammars.assignLanguageMode(this.editor, this.kernel.grammar.id);
    this.editor.moveToTop();
    this.editor.element.classList.add("watch-input");
  }

  @action
  run = () => {
    const code = this.getCode();
    log("watchview running:", code);
    if (code && code.length > 0) {
      this.kernel.executeWatch(code, result => {
        this.outputStore.appendOutput(result);
      });
    }
  };

  @action
  setCode = (code: string) => {
    this.editor.setText(code);
  };

  getCode = () => {
    return this.editor.getText();
  };

  focus = () => {<commit_msg>add grammar to watch editor for syntax highlighting<commit_after>/* @flow */

import { TextEditor } from "atom";
import { action } from "mobx";

import OutputStore from "./output";
import { log } from "./../utils";

import type Kernel from "./../kernel";

export default class WatchStore {
  kernel: Kernel;
  editor: TextEditor;
  outputStore = new OutputStore();

  constructor(kernel: Kernel) {
    this.kernel = kernel;
    this.editor = atom.workspace.buildTextEditor({
      softWrapped: true,
      lineNumberGutterVisible: false
    });
    const grammar = this.kernel.grammar;
    if (grammar) atom.grammars.assignLanguageMode(this.editor, grammar.id);
    this.editor.moveToTop();
    this.editor.element.classList.add("watch-input");
  }

  @action
  run = () => {
    const code = this.getCode();
    log("watchview running:", code);
    if (code && code.length > 0) {
      this.kernel.executeWatch(code, result => {
        this.outputStore.appendOutput(result);
      });
    }
  };

  @action
  setCode = (code: string) => {
    this.editor.setText(code);
  };

  getCode = () => {
    return this.editor.getText();
  };

  focus = () => {
{'fraction_non_alphanumeric': 0.15695067264573992, 'fraction_numerical': 0.0008968609865470852, 'mean_word_length': 3.012589928057554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6156311', 'n_tokens_mistral': 708, 'n_tokens_neox': 693, 'n_words': 156}