<commit_before>/* @flow */

import type { TextEditor, Range } from 'atom'
import { scanDeclarations } from 'declarations-javascript'
import { processDeclaration } from './helpers'

const FLOW_PACKAGES = ['declarations-flow', 'flow-ide']

export default {
  activate() {
    if (!atom.inSpecMode()) {
      require('atom-package-deps').install('declarations-js') // eslint-disable-line
    }
  },

  provideDeclarations() {
    return {
      grammarScopes: ['source.js', 'source.js.jsx'],
      async getDeclarations({ textEditor, visibleRange }: { textEditor: TextEditor, visibleRange: Range }) {
        if (textEditor.getText().indexOf('/* @flow */') !== -1 && FLOW_PACKAGES.some(name => atom.packages.isPackageActive(name))) {
          // Let the declarations-flow package handle the flow files
          return []
        }
        const filePath = textEditor.getPath()
        return processDeclaration(scanDeclarations(filePath, textEditor.getText(), function(node) {
          return visibleRange.containsPoint([node.loc.start.line - 1, node.loc.start.column])
        }), filePath)
      },
    }
  },
}<commit_msg>:art: Minor rearrangement<commit_after>/* @flow */

import type { TextEditor, Range } from 'atom'
import { scanDeclarations } from 'declarations-javascript'
import { processDeclaration } from './helpers'

const FLOW_PACKAGES = ['declarations-flow', 'flow-ide']

export default {
  activate() {
    if (!atom.inSpecMode()) {
       // eslint-disable-next-line global-require
      require('atom-package-deps').install('declarations-js')
    }
  },

  provideDeclarations() {
    return {
      grammarScopes: ['source.js', 'source.js.jsx'],
      async getDeclarations({ textEditor, visibleRange }: { textEditor: TextEditor, visibleRange: Range }) {
        if (textEditor.getText().indexOf('/* @flow */') !== -1 && FLOW_PACKAGES.some(name => atom.packages.isPackageActive(name))) {
          // Let the declarations-flow package handle the flow files
          return []
        }
        const filePath = textEditor.getPath()
        return processDeclaration(scanDeclarations(filePath, textEditor.getText(), function(node) {
          return visibleRange.containsPoint([node.loc.start.line - 1, node.loc.start.column])
        }), filePath)
      },
    }
  },
}
{'fraction_non_alphanumeric': 0.14678899082568808, 'fraction_numerical': 0.0017474879860200961, 'mean_word_length': 3.232902033271719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6107593', 'n_tokens_mistral': 678, 'n_tokens_neox': 665, 'n_words': 137}