<commit_before>/* global atom */
'use strict'

var CompositeDisposable = require('atom').CompositeDisposable
var plantuml = require('node-plantuml')
var url = require('url')
var config = require('./config.json')

var PLANTUML_VIEWER_URI_PROTOCOL = 'plantuml-viewer:'
var PlantumlViewerEditor
var disposables
var nailgun

function createPlantumlViewerEditor (uri, editorId) {
  if (!PlantumlViewerEditor) {
    PlantumlViewerEditor = require('./plantuml-viewer-editor')
  }
  if (!nailgun) {
    nailgun = plantuml.useNailgun()
  }
  return new PlantumlViewerEditor(uri, editorId)
}

atom.deserializers.add({
  name: 'PlantumlViewerEditor',
  deserialize: function (state) {
    return createPlantumlViewerEditor(state.uri, state.editorId)
  }
})

module.exports.config = config

module.exports.activate = function (state) {
  disposables = new CompositeDisposable()
  disposables.add(atom.commands.add('atom-workspace', {
    'plantuml-viewer:toggle': toggle
  }))

  disposables.add(atom.workspace.addOpener(plantumlViewerOpener))
}

module.exports.deactivate = function () {
  disposables.dispose()
  if (nailgun) nailgun.shutdown()
}

function toggle () {
  if (isMarkdownViewerView(atom.workspace.getActivePaneItem())) {
    atom.workspace.destroyActivePaneItem()
    return
  }

  var editor = atom.workspace.getActiveTextEditor()
  if (!editor) return

  var grammars = atom.config.get('plantuml-viewer.grammars') || []
  if (grammars.indexOf(editor.getGrammar().scopeName) === -1) return

  var uri = createPlantumlViewerUri(editor)
  var viewer = atom.workspace.paneForURI(uri)

  if (!viewer) addViewerForUri(uri)
  else viewer.destroyItem(viewer.itemForURI(uri))
}

function addViewerForUri (uri) {
  var prevActivePane = atom.workspace.getActivePane()
  var options = { searchAllPanes: true }

  if (atom.config.get('plantuml-viewer.openInSplitPane')) {
    options.split = 'right'
  }

  atom.workspace.open(uri, options).done(function (viewerView) {
    prevActivePane.activate()
  })
}
<commit_msg>Replace deprecated done for then when using promises<commit_after>/* global atom */
'use strict'

var CompositeDisposable = require('atom').CompositeDisposable
var plantuml = require('node-plantuml')
var url = require('url')
var config = require('./config.json')

var PLANTUML_VIEWER_URI_PROTOCOL = 'plantuml-viewer:'
var PlantumlViewerEditor
var disposables
var nailgun

function createPlantumlViewerEditor (uri, editorId) {
  if (!PlantumlViewerEditor) {
    PlantumlViewerEditor = require('./plantuml-viewer-editor')
  }
  if (!nailgun) {
    nailgun = plantuml.useNailgun()
  }
  return new PlantumlViewerEditor(uri, editorId)
}

atom.deserializers.add({
  name: 'PlantumlViewerEditor',
  deserialize: function (state) {
    return createPlantumlViewerEditor(state.uri, state.editorId)
  }
})

module.exports.config = config

module.exports.activate = function (state) {
  disposables = new CompositeDisposable()
  disposables.add(atom.commands.add('atom-workspace', {
    'plantuml-viewer:toggle': toggle
  }))

  disposables.add(atom.workspace.addOpener(plantumlViewerOpener))
}

module.exports.deactivate = function () {
  disposables.dispose()
  if (nailgun) nailgun.shutdown()
}

function toggle () {
  if (isMarkdownViewerView(atom.workspace.getActivePaneItem())) {
    atom.workspace.destroyActivePaneItem()
    return
  }

  var editor = atom.workspace.getActiveTextEditor()
  if (!editor) return

  var grammars = atom.config.get('plantuml-viewer.grammars') || []
  if (grammars.indexOf(editor.getGrammar().scopeName) === -1) return

  var uri = createPlantumlViewerUri(editor)
  var viewer = atom.workspace.paneForURI(uri)

  if (!viewer) addViewerForUri(uri)
  else viewer.destroyItem(viewer.itemForURI(uri))
}

function addViewerForUri (uri) {
  var prevActivePane = atom.workspace.getActivePane()
  var options = { searchAllPanes: true }

  if (atom.config.get('plantuml-viewer.openInSplitPane')) {
    options.split = 'right'
  }

  atom.workspace.open(uri, options).then(function (viewerView) {
    prevActivePane.activate()
  })
}

{'fraction_non_alphanumeric': 0.12699975387644596, 'fraction_numerical': 0.0004922471080482402, 'mean_word_length': 4.941520467836257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6681401', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1395, 'n_words': 241}