示例#1
0
 async (error, tags: Array<Object>) => {
   if (error != null) {
     reject(error);
   } else {
     const processed = await Promise.all(
       tags.map(async tag => {
         // Convert relative paths to absolute ones.
         tag.file = nuclideUri.join(dir, tag.file);
         // Tag files are often not perfectly in sync - filter out missing files.
         if (await fsPromise.exists(tag.file)) {
           if (tag.fields != null) {
             const map = new Map();
             for (const key in tag.fields) {
               map.set(key, tag.fields[key]);
             }
             tag.fields = map;
           }
           return tag;
         }
         return null;
       }),
     );
     // $FlowFixMe(>=0.55.0) Flow suppress
     resolve(arrayCompact(processed));
   }
 },
  _renderProviders(): void {
    // Create collection of provider React elements to render, and
    // display them in order
    const providerElements: Array<React.Element<any>> = arrayCompact(
      this._contextProviders.map((prov, index) => {
        const createElementFn = prov.getElementFactory();
        const element = createElementFn({
          ContextViewMessage,
          definition: this.currentDefinition,
          setLocked: this._setLocked,
        });
        if (element != null) {
          return (
            <ProviderContainer title={prov.title} key={index}>
              {element}
            </ProviderContainer>
          );
        }
      }),
    );

    // If there are no context providers to show, show a message instead
    if (providerElements.length === 0) {
      providerElements.push(<NoProvidersView key={0} />);
    }

    ReactDOM.render(
      <ContextViewPanel
        definition={this.currentDefinition}
        locked={this._locked}>
        {providerElements}
      </ContextViewPanel>,
      this._panelDOMElement,
    );
  }
示例#3
0
 ).map(([processes, javaProcesses, cpuAndMemUsage]) => {
   const javaPids = new Set(
     javaProcesses.map(javaProc => Number(javaProc.pid)),
   );
   return arrayCompact(
     processes.map(x => {
       const info = x.trim().split(/\s+/);
       const pid = parseInt(info[1], 10);
       if (!Number.isInteger(pid)) {
         return null;
       }
       const cpuAndMem = cpuAndMemUsage.get(pid);
       let cpu = null;
       let mem = null;
       if (cpuAndMem != null) {
         cpu = parseFloat(cpuAndMem[0]);
         mem = parseFloat(cpuAndMem[1]);
       }
       const isJava = javaPids.has(pid);
       return {
         user: info[0],
         pid,
         name: info[info.length - 1],
         cpuUsage: cpu,
         memUsage: mem,
         isJava,
       };
     }),
   );
 });
export async function getIPsForHosts(
  hosts: Array<string>,
): Promise<Array<DnsLookup>> {
  const promise_array = hosts.map(host =>
    lookupPreferIpv6(host).catch(() => {}),
  );
  const values = await Promise.all(promise_array);
  // $FlowFixMe(>=0.55.0) Flow suppress
  return arrayCompact(values);
}
 /**
  * The main public entry point.
  * Returns a list of references, grouped by file (with previews),
  * according to the given offset and limit.
  * References in each file are grouped together if they're adjacent.
  */
 async getFileReferences(
   offset: number,
   limit: number,
 ): Promise<Array<FileReferences>> {
   const fileReferences: Array<?FileReferences> = await Promise.all(
     this._references
       .slice(offset, offset + limit)
       .map(this._makeFileReferences.bind(this)),
   );
   return arrayCompact(fileReferences);
 }
// Returns paths of currently opened editor tabs.
function getOpenTabsMatching(query: string): Array<FileResult> {
  const matcher = new Matcher(
    arrayCompact(
      atom.workspace.getTextEditors().map(editor => editor.getPath()),
    ),
  );
  return matcher.match(query, {recordMatchIndexes: true}).map(result => ({
    resultType: 'FILE',
    path: result.value,
    score: result.score,
    matchIndexes: result.matchIndexes,
  }));
}
示例#7
0
 async _genAllCodeActions(
   editor: atom$TextEditor,
   range: atom$Range,
   diagnostics: Array<DiagnosticMessage>,
 ): Promise<Array<CodeAction>> {
   const codeActionRequests = [];
   for (const provider of this._providerRegistry.getAllProvidersForEditor(
     editor,
   )) {
     codeActionRequests.push(
       provider.getCodeActions(editor, range, diagnostics),
     );
   }
   return arrayFlatten(arrayCompact(await Promise.all(codeActionRequests)));
 }
 async symbolSearch(
   query: string,
   directories: Array<NuclideUri>,
 ): Promise<?Array<SymbolResult>> {
   if (query.length === 0) {
     return [];
   }
   const serviceDirectories = await this._getLanguageServicesForFiles(
     directories,
   );
   const results = await Promise.all(
     serviceDirectories.map(([service, dirs]) =>
       service.symbolSearch(query, dirs),
     ),
   );
   return arrayFlatten(arrayCompact(results));
 }
示例#9
0
  // Handles new NUXes emitted from the store
  _handleNewNux(nuxTourModel: NuxTourModel): void {
    const nuxViews = arrayCompact(
      nuxTourModel.nuxList.map((model, index, arr) => {
        try {
          return new NuxView(
            nuxTourModel.id,
            model.selector,
            model.selectorFunction,
            model.position,
            model.content,
            model.completionPredicate,
            index,
            arr.length, // Number of NuxViewModels in the NuxTourModel
          );
        } catch (err) {
          const error = `NuxView #${index} for "${
            nuxTourModel.id
          }" failed to instantiate.`;
          logger.error(`ERROR: ${error}`, err);
          this._track(
            nuxTourModel.id,
            nuxTourModel.name,
            `NuxView #${index + 1} failed to instantiate.`,
            err.toString(),
          );
          return null;
        }
      }),
    );

    const nuxTour = new NuxTour(
      nuxTourModel.id,
      nuxTourModel.name,
      nuxViews,
      nuxTourModel.trigger,
      nuxTourModel.gatekeeperID,
    );

    this._emitter.emit(NEW_TOUR_EVENT, {
      nuxTour,
      nuxTourModel,
    });
  }
示例#10
0
async function getHackDirectoriesByService(
  directories: Array<atom$Directory>, // top-level project directories
): Promise<Array<[LanguageService, Array<NuclideUri>]>> {
  const promises: Array<
    Promise<?[LanguageService, NuclideUri]>,
  > = directories.map(async directory => {
    const service = await getHackLanguageForUri(directory.getPath());
    return service ? [service, directory.getPath()] : null;
  });
  const serviceDirectories: Array<?[
    LanguageService,
    NuclideUri,
  ]> = await Promise.all(promises);

  const results: Map<LanguageService, Array<NuclideUri>> = collect(
    arrayCompact(serviceDirectories),
  );

  return Array.from(results.entries());
}
  async _getLanguageServicesForFiles(
    filePaths: Array<string>,
  ): Promise<Array<[LanguageService, Array<string>]>> {
    const promises: Array<Promise<?[LanguageService, string]>> = filePaths.map(
      async filePath => {
        const service = await this._getLanguageServiceForFile(filePath);
        return service ? [service, filePath] : null;
      },
    );

    const fileServices: Array<?[LanguageService, string]> = await Promise.all(
      promises,
    );

    const results: Map<LanguageService, Array<string>> = collect(
      arrayCompact(fileServices),
    );

    return Array.from(results);
  }
示例#12
0
async function getServerInfos(
  configDirectory: NuclideUri,
): Promise<Array<ServerInfo>> {
  const entries = await fs.readdir(configDirectory);
  return arrayCompact(
    await Promise.all(
      entries.map(async entry => {
        const subdir = nuclideUri.join(configDirectory, entry);
        const info = JSON.parse(
          await fs.readFile(nuclideUri.join(subdir, SERVER_INFO_FILE), 'utf8'),
        );
        if (info.commandPort != null && info.family != null) {
          return info;
        } else {
          return null;
        }
      }),
    ),
  );
}
示例#13
0
  async executeQuery(
    query: string,
    directories: Array<atom$Directory>,
  ): Promise<Array<SymbolResult>> {
    if (query.length === 0) {
      return [];
    }

    const serviceDirectories = await getHackDirectoriesByService(directories);
    const results = await Promise.all(
      serviceDirectories.map(([service, dirs]) =>
        service.symbolSearch(query, dirs),
      ),
    );
    return arrayFlatten(arrayCompact(results));
  },

  getComponentForItem(item: SymbolResult): React.Element<any> {
    const name = item.name || '';

    // flowlint-next-line sketchy-null-string:off
    const symbolClasses = item.icon
      ? `file icon icon-${item.icon}`
      : 'file icon no-icon';
    return (
      <div title={item.hoverText || ''}>
        <span className={symbolClasses}>
          <code>{name}</code>
        </span>
        <span className="omnisearch-symbol-result-filename">
 async getAllLanguageServices(): Promise<Array<T>> {
   const lsPromises: Array<Promise<?T>> = [...this._processes.values()];
   return arrayCompact(await Promise.all(lsPromises));
 }
示例#15
0
  async _fetchAndRender(
    position: atom$Point,
  ): Promise<?{
    range: atom$Range,
    renderedProviders: React$Element<*>,
  }> {
    let datatipAndProviderPromise;
    if (this._lastPosition && position.isEqual(this._lastPosition)) {
      datatipAndProviderPromise = this._lastDatatipAndProviderPromise;
    } else {
      this._lastDatatipAndProviderPromise = getTopDatatipAndProvider(
        this._datatipProviders,
        this._editor,
        position,
        provider => provider.datatip(this._editor, position),
      );
      datatipAndProviderPromise = this._lastDatatipAndProviderPromise;
      this._lastPosition = position;
    }

    const datatipsAndProviders = arrayCompact(
      await Promise.all([
        datatipAndProviderPromise,
        getTopDatatipAndProvider(
          this._modifierDatatipProviders,
          this._editor,
          position,
          provider =>
            provider.modifierDatatip(this._editor, position, this._heldKeys),
        ),
      ]),
    );

    if (datatipsAndProviders.length === 0) {
      return null;
    }

    const range = datatipsAndProviders[0].datatip.range;
    analytics.track('datatip-popup', {
      scope: this._editor.getGrammar().scopeName,
      providerName: getProviderName(datatipsAndProviders[0].provider),
      rangeStartRow: String(range.start.row),
      rangeStartColumn: String(range.start.column),
      rangeEndRow: String(range.end.row),
      rangeEndColumn: String(range.end.column),
    });

    const renderedProviders = (
      <div>
        {datatipsAndProviders.map(({datatip, provider}) => (
          <PinnableDatatip
            datatip={datatip}
            editor={this._editor}
            key={getProviderName(provider)}
            onPinClick={this._handlePinClicked}
          />
        ))}
      </div>
    );

    return {
      range,
      renderedProviders,
    };
  }