UNPKG

2.81 kBTypeScriptView Raw
1import { Subject } from 'rxjs';
2import { Controller as BaseController } from 'sourcegraph/module/client/controller';
3import { ExecuteCommandParams } from 'sourcegraph/module/client/providers/command';
4import { MessageTransports } from 'sourcegraph/module/protocol/jsonrpc2/connection';
5import { Notification } from '../app/notifications/notification';
6import { Context } from '../context';
7import { ConfiguredExtension } from '../extensions/extension';
8import { ConfigurationCascade, ConfigurationSubject, Settings } from '../settings';
9/**
10 * Extends the {@link BaseController} class to add functionality that is useful to this package's consumers.
11 */
12export declare class Controller<S extends ConfigurationSubject, C extends Settings> extends BaseController<ConfiguredExtension, ConfigurationCascade<S, C>> {
13 /**
14 * Global notification messages that should be displayed to the user, from the following sources:
15 *
16 * - window/showMessage notifications from extensions
17 * - Errors thrown or returned in command invocation
18 */
19 readonly notifications: Subject<Notification>;
20 /**
21 * Executes the command (registered in the CommandRegistry) specified in params. If an error is thrown, the
22 * error is returned *and* emitted on the {@link Controller#notifications} observable.
23 *
24 * All callers should execute commands using this method instead of calling
25 * {@link sourcegraph:CommandRegistry#executeCommand} directly (to ensure errors are
26 * emitted as notifications).
27 */
28 executeCommand(params: ExecuteCommandParams): Promise<any>;
29}
30/**
31 * React props or state containing the controller. There should be only a single controller for the whole
32 * application.
33 */
34export interface ControllerProps<S extends ConfigurationSubject, C extends Settings> {
35 /**
36 * The controller, which is used to communicate with the extensions and manages extensions based on the
37 * environment.
38 */
39 extensionsController: Controller<S, C>;
40}
41declare global {
42 interface Window {
43 sx: any;
44 sxenv: any;
45 }
46}
47/**
48 * Creates the controller, which handles all communication between the React app and Sourcegraph extensions.
49 *
50 * There should only be a single controller for the entire application. The controller's environment represents all
51 * of the application state that the controller needs to know.
52 *
53 * It receives state updates via calls to the setEnvironment method from React components. It provides results to
54 * React components via its registries and the showMessages, etc., observables.
55 */
56export declare function createController<S extends ConfigurationSubject, C extends Settings>(context: Context<S, C>, createMessageTransports: (extension: ConfiguredExtension) => Promise<MessageTransports>): Controller<S, C>;