UNPKG

atom-nuclide

Version:

A unified developer experience for web and mobile development, built as a suite of features on top of Atom to provide hackability and the support of an active community.

101 lines (82 loc) 3.42 kB
var doFindReferences = _asyncToGenerator(function* (textEditor, position) { var result = yield (0, (_commonsAtomLoadingNotification2 || _commonsAtomLoadingNotification()).default)(findReferences(textEditor, position.row, position.column), 'Loading references from Hack server...'); if (!result) { return { type: 'error', message: 'Only classes/functions/methods are supported.' }; } var baseUri = result.baseUri; var symbolName = result.symbolName; var references = result.references; // Process this into the format nuclide-find-references expects. references = references.map(function (ref) { return { uri: ref.filename, name: null, // TODO(hansonw): Get the caller when it's available start: { line: ref.line, column: ref.char_start }, end: { line: ref.line, column: ref.char_end } }; }); // Strip off the global namespace indicator. if (symbolName.startsWith('\\')) { symbolName = symbolName.slice(1); } return { type: 'data', baseUri: baseUri, referencedSymbolName: symbolName, references: references }; }); var findReferences = _asyncToGenerator(function* (editor, line, column) { var filePath = editor.getPath(); var hackLanguage = yield (0, (_HackLanguage2 || _HackLanguage()).getHackLanguageForUri)(filePath); if (!hackLanguage || !filePath) { return null; } var contents = editor.getText(); return yield hackLanguage.findReferences(filePath, contents, line + 1, column + 1); }); function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, 'next'); var callThrow = step.bind(null, 'throw'); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; } /* * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the license found in the LICENSE file in * the root directory of this source tree. */ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var _nuclideHackCommon2; function _nuclideHackCommon() { return _nuclideHackCommon2 = require('../../nuclide-hack-common'); } var _nuclideAnalytics2; function _nuclideAnalytics() { return _nuclideAnalytics2 = require('../../nuclide-analytics'); } var _HackLanguage2; function _HackLanguage() { return _HackLanguage2 = require('./HackLanguage'); } var _commonsAtomLoadingNotification2; function _commonsAtomLoadingNotification() { return _commonsAtomLoadingNotification2 = _interopRequireDefault(require('../../commons-atom/loading-notification')); } module.exports = { isEditorSupported: _asyncToGenerator(function* (textEditor) { var fileUri = textEditor.getPath(); if (!fileUri || !(_nuclideHackCommon2 || _nuclideHackCommon()).HACK_GRAMMARS_SET.has(textEditor.getGrammar().scopeName)) { return false; } return true; }), findReferences: function findReferences(editor, position) { return (0, (_nuclideAnalytics2 || _nuclideAnalytics()).trackOperationTiming)('hack:findReferences', function () { return doFindReferences(editor, position); }); } };