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.
160 lines (132 loc) • 5.11 kB
JavaScript
Object.defineProperty(exports, '__esModule', {
value: true
});
/*
* 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.
*/
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
exports.registerProvider = registerProvider;
exports.provideBusySignal = provideBusySignal;
exports.activate = activate;
exports.deactivate = deactivate;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _atom2;
function _atom() {
return _atom2 = require('atom');
}
// eslint-disable-next-line nuclide-internal/no-cross-atom-imports
var _nuclideBusySignal2;
function _nuclideBusySignal() {
return _nuclideBusySignal2 = require('../../nuclide-busy-signal');
}
var _nuclideLogging2;
function _nuclideLogging() {
return _nuclideLogging2 = require('../../nuclide-logging');
}
var _nuclideRemoteConnection2;
function _nuclideRemoteConnection() {
return _nuclideRemoteConnection2 = require('../../nuclide-remote-connection');
}
var _utils2;
function _utils() {
return _utils2 = require('./utils');
}
var _FuzzyFileNameProvider2;
function _FuzzyFileNameProvider() {
return _FuzzyFileNameProvider2 = _interopRequireDefault(require('./FuzzyFileNameProvider'));
}
var Activation = (function () {
function Activation(state) {
_classCallCheck(this, Activation);
this._disposables = new (_atom2 || _atom()).CompositeDisposable();
}
_createClass(Activation, [{
key: 'activate',
value: function activate() {
// Do search preprocessing for all existing and future root directories.
initSearch(atom.project.getPaths());
this._disposables.add(atom.project.onDidChangePaths(initSearch));
}
}, {
key: 'dispose',
value: function dispose() {
this._disposables.dispose();
}
}]);
return Activation;
})();
var activation = null;
function getActivation() {
if (activation == null) {
activation = new Activation();
activation.activate();
}
return activation;
}
var projectRoots = new Set();
var busySignalProvider = null;
/**
* @param projectPaths All the root directories in the Atom workspace.
*/
function initSearch(projectPaths) {
var newProjectRoots = new Set();
projectPaths.forEach(function (projectPath) {
newProjectRoots.add(projectPath);
if (projectRoots.has(projectPath)) {
return;
}
var service = (0, (_nuclideRemoteConnection2 || _nuclideRemoteConnection()).getServiceByNuclideUri)('FuzzyFileSearchService', projectPath);
if (service) {
// It doesn't matter what the search term is. Empirically, doing an initial
// search speeds up the next search much more than simply doing the setup
// kicked off by 'fileSearchForDirectory'.
service.isFuzzySearchAvailableFor(projectPath).then(function (isAvailable) {
if (isAvailable) {
(function () {
var queryPromise = service.queryFuzzyFile(projectPath, 'a', (0, (_utils2 || _utils()).getIgnoredNames)()).catch(function (error) {
(0, (_nuclideLogging2 || _nuclideLogging()).getLogger)().error('Error starting fuzzy filename search for ' + projectPath, error);
});
if (busySignalProvider != null) {
busySignalProvider.reportBusy('File search: indexing files for project ' + projectPath, function () {
return queryPromise;
});
}
})();
}
});
}
});
// Clean up removed project roots.
projectRoots.forEach(function (projectPath) {
if (!newProjectRoots.has(projectPath)) {
var service = (0, (_nuclideRemoteConnection2 || _nuclideRemoteConnection()).getServiceByNuclideUri)('FuzzyFileSearchService', projectPath);
if (service != null) {
service.disposeFuzzySearch(projectPath);
}
}
});
projectRoots = newProjectRoots;
}
function registerProvider() {
return (_FuzzyFileNameProvider2 || _FuzzyFileNameProvider()).default;
}
function provideBusySignal() {
if (busySignalProvider == null) {
busySignalProvider = new (_nuclideBusySignal2 || _nuclideBusySignal()).BusySignalProviderBase();
}
return busySignalProvider;
}
function activate(state) {
getActivation();
}
function deactivate() {
if (activation) {
activation.dispose();
activation = null;
}
}