<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * An entrypoint to the [ace.dart](https://github.com/rmsmith/ace.dart) package.
 */
library spark.ace;

import 'dart:async';
import 'dart:html' as html;
import 'dart:js' as js;
import 'dart:math' as math;

import 'package:ace/ace.dart' as ace;
import 'package:path/path.dart' as path;

import 'workspace.dart' as workspace;
import 'editors.dart';
import 'preferences.dart';
import 'utils.dart' as utils;

export 'package:ace/ace.dart' show EditSession;

class AceEditor extends Editor {
  final AceContainer aceContainer;

  workspace.File file;

  html.Element get element => aceContainer.parentElement;

  AceEditor(this.aceContainer);

  void resize() => aceContainer.resize();

  void focus() => aceContainer.focus();
}

/**
 * A wrapper around an Ace editor instance.
 */
class AceContainer {
  static final KEY_BINDINGS = ace.KeyboardHandler.BINDINGS;
  // 2 light themes, 4 dark ones.
  static final THEMES = [
      'textmate', 'tomorrow',
      'tomorrow_night', 'monokai', 'idle_fingers', 'pastel_on_dark'
  ];

  /**
   * The container for the Ace editor.
   */
  final html.Element parentElement;

  ace.Editor _aceEditor;
  workspace.File _file;

  static bool get available => js.context['ace'] != null;

  AceContainer(this.parentElement) {
    _aceEditor = ace.edit(parentElement);
    _aceEditor.renderer.fixedWidthGutter = true;
    _aceEditor.highlightActiveLine = false;
    _aceEditor.printMarginColumn = 80;
    //_aceEditor.renderer.showGutter = false;
    //_aceEditor.setOption('scrollPastEnd', true);
    _aceEditor.readOnly = true;

    // Fallback
    theme = THEMES[0];
  }

  List<ace.Annotation> setMarkers(List<workspace.Marker> markers) {
    ace.EditSession currentSession = this.currentSession;
    // TODO(ericarnold): This is a hack until `annotations` can be modified
    // directly.
    var annotations = currentSession.annotations;

    for (workspace.Marker marker in markers) {
      // TODO(ericarnold): Check the type here before taking from severity.
      String annotationType = _convertMarkerSeverity(marker.severity);
      var annotation = new ace.Annotation(
          text: marker.message,
          row: marker.lineNum,
          type: annotationType);
      annotations.add(annotation);
    }
    currentSession.annotations = annotations;
    return annotations;
  }

  clearAnnotations() => currentSession.annotations = [];
<commit_msg>removed todo and set annotations to reset instead of add to list<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * An entrypoint to the [ace.dart](https://github.com/rmsmith/ace.dart) package.
 */
library spark.ace;

import 'dart:async';
import 'dart:html' as html;
import 'dart:js' as js;
import 'dart:math' as math;

import 'package:ace/ace.dart' as ace;
import 'package:path/path.dart' as path;

import 'workspace.dart' as workspace;
import 'editors.dart';
import 'preferences.dart';
import 'utils.dart' as utils;

export 'package:ace/ace.dart' show EditSession;

class AceEditor extends Editor {
  final AceContainer aceContainer;

  workspace.File file;

  html.Element get element => aceContainer.parentElement;

  AceEditor(this.aceContainer);

  void resize() => aceContainer.resize();

  void focus() => aceContainer.focus();
}

/**
 * A wrapper around an Ace editor instance.
 */
class AceContainer {
  static final KEY_BINDINGS = ace.KeyboardHandler.BINDINGS;
  // 2 light themes, 4 dark ones.
  static final THEMES = [
      'textmate', 'tomorrow',
      'tomorrow_night', 'monokai', 'idle_fingers', 'pastel_on_dark'
  ];

  /**
   * The container for the Ace editor.
   */
  final html.Element parentElement;

  ace.Editor _aceEditor;
  workspace.File _file;

  static bool get available => js.context['ace'] != null;

  AceContainer(this.parentElement) {
    _aceEditor = ace.edit(parentElement);
    _aceEditor.renderer.fixedWidthGutter = true;
    _aceEditor.highlightActiveLine = false;
    _aceEditor.printMarginColumn = 80;
    //_aceEditor.renderer.showGutter = false;
    //_aceEditor.setOption('scrollPastEnd', true);
    _aceEditor.readOnly = true;

    // Fallback
    theme = THEMES[0];
  }

  List<ace.Annotation> setMarkers(List<workspace.Marker> markers) {
    ace.EditSession currentSession = this.currentSession;
    List<ace.Annotation> annotations = [];

    for (workspace.Marker marker in markers) {
      // TODO(ericarnold): Check the type here before taking from severity.
      String annotationType = _convertMarkerSeverity(marker.severity);
      var annotation = new ace.Annotation(
          text: marker.message,
          row: marker.lineNum,
          type: annotationType);
      annotations.add(annotation);
    }
    currentSession.annotations = annotations;
    return annotations;
  }

  clearAnnotations() => currentSession.annotations = [];

{'fraction_non_alphanumeric': 0.11237690673875265, 'fraction_numerical': 0.0034755744352191545, 'mean_word_length': 3.658273381294964, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '1637737', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1558, 'n_words': 439}