<commit_before>/** @babel */

import * as path from 'path';
import { CompositeDisposable } from 'atom';
import config from './config';
import SymbolsView from './symbols-view';

class Package {

  activate() {
    this.config = config.schema;
    this.overrideCommands = null;
    this.symbolsView = null;
    this.subscriptions = new CompositeDisposable();
    this.subscriptions.add(
      config.watchOverrideCommands(updateOverrideCommands.bind(this)),
      config.watchToggleFileSymbolsCommand(() => updateOverrideCommands.bind(this)()),
      config.watchToggleProjectSymbolsCommand(() => updateOverrideCommands.bind(this)()),
      atom.commands.add('atom-text-editor', 'rustsym:toggle-file-symbols', this.toggleFileSymbols.bind(this)),
      atom.commands.add('atom-workspace', 'rustsym:toggle-project-symbols', this.toggleProjectSymbols.bind(this)),
    );
    // Call required to set up initial state for override commands
    updateOverrideCommands.bind(this)();
  }

  deactivate() {
    if (this.symbolsView) {
      this.symbolsView.destroy();
      this.symbolsView = null;
    }
    if (this.overrideCommands) {
      this.overrideCommands.dispose();
      this.overrideCommands = null;
    }
    if (this.subscriptions) {
      this.subscriptions.dispose();
      this.subscriptions = null;
    }
  }

  isEditingRust() {
    let editor = atom.workspace.getActiveTextEditor();
    if (!editor) return false;
    return path.extname(editor.getPath()) === '.rs';
  }

  toggleFileSymbols(event) {
    if (!initializeSymbolsView.bind(this)(event)) return;
    this.symbolsView.toggleFileSymbols(event.target);
  }

  toggleProjectSymbols(event) {
    if (!initializeSymbolsView.bind(this)(event)) return;
    this.symbolsView.toggleProjectSymbols(event.target);
  }

}

function initializeSymbolsView(event) {
  if (!this.isEditingRust()) return false;
  // Consume triggering event
  event.stopImmediatePropagation();
  if (this.symbolsView == null) {
    this.symbolsView = new SymbolsView();
  }
  return true;
}

function prioritizeCommandListener(command, listenerName) {
  let listeners = atom.commands.selectorBasedListenersByCommandName[command];
  let listener = listeners.find(
    // Allow substring comparison as bound functions will have their names
    // altered slightly (i.e. 'bound <fn-name>')
    listener => listener.callback.name.indexOf(listenerName) !== -1<commit_msg>Fix package activation error due to Atom API change<commit_after>/** @babel */

import * as path from 'path';
import { CompositeDisposable } from 'atom';
import config from './config';
import SymbolsView from './symbols-view';

class Package {

  activate() {
    this.config = config.schema;
    this.overrideCommands = null;
    this.symbolsView = null;
    this.subscriptions = new CompositeDisposable();
    this.subscriptions.add(
      config.watchOverrideCommands(updateOverrideCommands.bind(this)),
      config.watchToggleFileSymbolsCommand(() => updateOverrideCommands.bind(this)()),
      config.watchToggleProjectSymbolsCommand(() => updateOverrideCommands.bind(this)()),
      atom.commands.add('atom-text-editor', 'rustsym:toggle-file-symbols', this.toggleFileSymbols.bind(this)),
      atom.commands.add('atom-workspace', 'rustsym:toggle-project-symbols', this.toggleProjectSymbols.bind(this)),
    );
    // Call required to set up initial state for override commands
    updateOverrideCommands.bind(this)();
  }

  deactivate() {
    if (this.symbolsView) {
      this.symbolsView.destroy();
      this.symbolsView = null;
    }
    if (this.overrideCommands) {
      this.overrideCommands.dispose();
      this.overrideCommands = null;
    }
    if (this.subscriptions) {
      this.subscriptions.dispose();
      this.subscriptions = null;
    }
  }

  isEditingRust() {
    let editor = atom.workspace.getActiveTextEditor();
    if (!editor) return false;
    return path.extname(editor.getPath()) === '.rs';
  }

  toggleFileSymbols(event) {
    if (!initializeSymbolsView.bind(this)(event)) return;
    this.symbolsView.toggleFileSymbols(event.target);
  }

  toggleProjectSymbols(event) {
    if (!initializeSymbolsView.bind(this)(event)) return;
    this.symbolsView.toggleProjectSymbols(event.target);
  }

}

function initializeSymbolsView(event) {
  if (!this.isEditingRust()) return false;
  // Consume triggering event
  event.stopImmediatePropagation();
  if (this.symbolsView == null) {
    this.symbolsView = new SymbolsView();
  }
  return true;
}

function prioritizeCommandListener(command, listenerName) {
  let listeners = atom.commands.selectorBasedListenersByCommandName[command];
  let listener = listeners.find(
    // Allow substring comparison as bound functions will have their names
    // altered slightly (i.e. 'bound <fn-name>')
    listener => listener.didDispatch.name.indexOf(listenerName) !== -1
{'fraction_non_alphanumeric': 0.1277560271996703, 'fraction_numerical': 0.00041211621677313, 'mean_word_length': 4.019648397104446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1814349', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1432, 'n_words': 279}