How to use the @nteract/messaging.createMessage function in @nteract/messaging

To help you get started, we’ve selected a few @nteract/messaging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nteract / nteract / packages / editor / __tests__ / editor.spec.tsx View on Github external
it("handles tooltip", done => {
    const sent = new Subject();
    const received = new Subject();
    const mockSocket = Subject.create(sent, received);
    const channels = mockSocket;

    const cm = {
      getCursor: () => ({ line: 0 }),
      getValue: () => "map",
      indexFromPos: () => 3,
      posFromIndex: x => ({ ch: x, line: 0 })
    };

    const message = createMessage("inspect_request");
    const observable = tooltip.tooltipObservable(channels, cm, message);

    // Craft the response to their message
    const response = createMessage("inspect_reply");
    response.content = {
      data: [
        "Init signature: map(self, /, *args, **kwargs)↵Docstring:     ↵map(func, *iterables) --> map object↵↵Make an iterator that computes the function using arguments from↵each of the iterables.  Stops when the shortest iterable is exhausted.↵Type:           type↵"
      ],
      cursor_pos: 3,
      detail_level: 0
    }; // Likely hokey values
    response.parent_header = Object.assign({}, message.header);

    // Listen on the Observable
    observable.subscribe(
      msg => {
github nteract / nteract / packages / editor / __tests__ / complete.spec.ts View on Github external
const received = new Subject();
    const mockSocket = Subject.create(sent, received);
    const channels: Channels = mockSocket;

    const cm: Doc = ({
      getCursor: () => ({ line: 2 }),
      getValue: () => "\n\nimport thi",
      indexFromPos: () => 12,
      posFromIndex: x => ({ ch: x, line: 3 })
    } as unknown) as Doc;

    const message = createMessage("complete_request");
    const observable = complete.codeCompleteObservable(channels, cm, message);

    // Craft the response to their message
    const response = createMessage("complete_reply");
    response.content = {
      matches: ["import this"],
      cursor_start: 9,
      cursor_end: 10
    }; // Likely hokey values
    response.parent_header = Object.assign({}, message.header);

    // Listen on the Observable
    observable.subscribe(
      msg => {
        expect(msg.from).toEqual({ line: 3, ch: 9 });
        expect(msg.list[0].text).toEqual("import this");
        expect(msg.to).toEqual({ ch: 10, line: 3 });
      },
      err => {
        throw err;
github nteract / nteract / packages / epics / __tests__ / execute.spec.ts View on Github external
app: {
          notificationSystem: { addNotification: jest.fn() }
        }
      }
    };
    const action$ = ActionsObservable.of(
      actions.sendExecuteRequest({
        id: "id",
        message: "test",
        contentRef: "fakeContentRef"
      })
    );
    const observable = createExecuteCellStream(
      action$,
      state$.value,
      createMessage("execute_request"),
      "id",
      "fakeContentRef"
    );
    observable.pipe(toArray()).subscribe(
      actions => {
        const errors = actions.map(({ payload: { error } }) =>
          error.toString()
        );
        expect(errors).toEqual(["Error: Kernel not connected!"]);
        done();
      },
      err => done.fail(err)
    );
  });
  test("doesnt complete but does push until abort action", done => {
github nteract / nteract / packages / epics / __tests__ / kernel-lifecycle.spec.ts View on Github external
sent.subscribe((msg: JupyterMessage) => {
      expect(msg.header.msg_type).toEqual("kernel_info_request");

      const response = createMessage("kernel_info_reply" as MessageType);
      response.parent_header = msg.header;
      response.content = {
        status: "ok",
        protocol_version: "5.1",
        implementation: "ipython",
        implementation_version: "6.2.1",
        language_info: {
          name: "python",
          version: "3.6.5",
          mimetype: "text/x-python",
          codemirror_mode: { name: "ipython", version: 3 },
          pygments_lexer: "ipython3",
          nbconvert_exporter: "python",
          file_extension: ".py"
        },
        banner:
github nteract / nteract / packages / editor / src / jupyter / tooltip.js View on Github external
export const tooltipRequest = (code: string, cursorPos: number) =>
  createMessage("inspect_request", {
    content: {
      code,
      cursor_pos: cursorPos,
      detail_level: 0
    }
  });
github nteract / nteract / packages / core / src / epics / comm.js View on Github external
export function createCommOpenMessage(
  comm_id: string,
  target_name: string,
  data: any = {},
  target_module: string
) {
  const msg = createMessage("comm_open", {
    content: { comm_id, target_name, data }
  });
  if (target_module) {
    msg.content.target_module = target_module;
  }
  return msg;
}
github nteract / nteract / packages / core / src / epics / comm.js View on Github external
export function createCommCloseMessage(
  parent_header: any,
  comm_id: string,
  data: any = {}
) {
  return createMessage("comm_close", {
    content: { comm_id, data },
    parent_header
  });
}
github nteract / nteract / packages / editor / src / jupyter / complete.js View on Github external
export const completionRequest = (code: string, cursorPos: number) =>
  createMessage("complete_request", {
    content: {
      code,
      cursor_pos: cursorPos
    }
  });
github nteract / nteract / packages / core / src / epics / kernel-lifecycle.js View on Github external
export function acquireKernelInfo(
  channels: Channels,
  kernelRef: KernelRef,
  contentRef: ContentRef
) {
  const message = createMessage("kernel_info_request");

  const obs = channels.pipe(
    childOf(message),
    ofMessageType("kernel_info_reply"),
    first(),
    mergeMap(msg => {
      const c = msg.content;
      const l = c.language_info;

      const info: KernelInfo = {
        protocolVersion: c.protocol_version,
        implementation: c.implementation,
        implementationVersion: c.implementation_version,
        banner: c.banner,
        helpLinks: c.help_links,
        languageName: l.name,
github nteract / nteract / packages / epics / src / kernel-lifecycle.ts View on Github external
export function acquireKernelInfo(
  channels: Channels,
  kernelRef: KernelRef,
  contentRef: ContentRef,
  state: AppState
) {
  const message = createMessage("kernel_info_request");

  const obs = channels.pipe(
    childOf(message),
    ofMessageType("kernel_info_reply"),
    first(),
    mergeMap(msg => {
      const c = msg.content;
      const l = c.language_info;

      const info: KernelInfo = {
        protocolVersion: c.protocol_version,
        implementation: c.implementation,
        implementationVersion: c.implementation_version,
        banner: c.banner,
        helpLinks: c.help_links,
        languageName: l.name,