waitsForPromise(async () => {
      editor.insertText('test');
      atom.commands.dispatch(editor.getElement(), 'signature-help:show');

      const signatureSpy = testProvider.getSignatureHelp;
      expect(signatureSpy.callCount).toBe(1);
      expect(signatureSpy.calls[0].args).toEqual([editor, new Point(0, 4)]);

      // Wait for promise to be resolved.
      await nextTick();

      const datatipSpy = mockDatatipService.createPinnedDataTip;
      expect(datatipSpy.callCount).toBe(1);
      expect(datatipSpy.calls[0].args[0].range).toEqual(
        new Range([0, 4], [0, 4]),
      );

      // Moving the cursor should immediately move the datatip and query again.
      editor.setCursorBufferPosition([0, 3]);

      expect(datatipSpy.callCount).toBe(2);
      expect(datatipSpy.calls[1].args[0].range).toEqual(
        new Range([0, 3], [0, 3]),
      );

      // Compensate for the debounce.
      advanceClock(500);
      expect(signatureSpy.callCount).toBe(2);
      expect(signatureSpy.calls[1].args).toEqual([editor, new Point(0, 3)]);

      // Wait for promise to be resolved.
      await nextTick();
      expect(datatipSpy.callCount).toBe(3);

      // Once the signature returns null, abort the flow.
      signatureSpy.andReturn(Promise.resolve(null));
      editor.setCursorBufferPosition([0, 0]);

      // No repositioning when the cursor moves too far.
      expect(datatipSpy.callCount).toBe(3);

      // Compensate for the debounce.
      advanceClock(500);
      expect(signatureSpy.callCount).toBe(3);

      await nextTick();
      expect(datatipSpy.callCount).toBe(3);

      editor.setCursorBufferPosition([0, 1]);
      advanceClock(500);
      expect(signatureSpy.callCount).toBe(3);
    });
Beispiel #2
0
              .flatMap(() => {
                const bufferPath = nullthrows(textEditor.getPath());
                // TODO (tjfryan): do something to handle generated files
                if (fileContentsAtHead.has(bufferPath)) {
                  return Observable.empty();
                }

                bufferedFilesToCat.push(repository.relativize(bufferPath));
                if (bufferedFilesToCat.length > 1) {
                  return Observable.empty();
                }

                // use nextTick to buffer many files being requested at once
                // (maybe should use timeout instead?)
                return Observable.fromPromise(nextTick()).switchMap(() => {
                  const filesToCat = [...bufferedFilesToCat];
                  bufferedFilesToCat.length = 0;
                  return repository
                    .fetchMultipleFilesContentAtRevision(
                      filesToCat,
                      hgConstants.HEAD_REVISION_EXPRESSION,
                    )
                    .catch(() =>
                      // hg uses errorCode 1 as "nothing went wrong but nothing was found"
                      Observable.empty(),
                    );
                });
              });