76 lines · 2.6 KB
import type { LineMatch, TextQuery } from "../lib/text-search";

/** Session details the embedding page hands to the workbench (and on to this extension) via a command. */
export type EditorSessionInfo = {
  token: string;
  forgeOrigin: string;
  owner: string;
  repo: string;
  ref: string;
  refKind: "branch" | "tag" | "commit";
  sha: string;
  writable: boolean;
  protected: boolean;
  user: string;
  containers: boolean;
  /** Set by "Open in container" on the forge: start a container and open a terminal after activation. */
  startContainer?: boolean;
  /** File to open on start, e.g. from `/edit/<ref>?path=` or pressing `.` on a file page. */
  openPath?: string | null;
};

export type TreeEntry = { path: string; type: string; sha: string };

export type SearchRequest = TextQuery & {
  maxResults: number;
  /** Paths searched locally from the live room (or deleted there): the head copies would be stale. */
  skip: string[];
  excludeDirs: string[];
};

export type SearchResponse = { files: Array<{ path: string; matches: LineMatch[] }>; limitHit: boolean };

/** Token-only calls to the forge's editor API. */
export class ForgeApi {
  constructor(private session: EditorSessionInfo) {}

  update(session: EditorSessionInfo): void {
    this.session = session;
  }