Update IDE api

This commit is contained in:
Kyle Carberry 2019-02-27 09:03:44 -06:00
parent 71b7bbf99a
commit 0b5b7afbac
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
3 changed files with 116 additions and 13 deletions

View File

@ -4,12 +4,90 @@ interface ActiveEvalEmitter {
emit(event: string, ...args: any[]): void; emit(event: string, ...args: any[]): void;
on(event: string, cb: (...args: any[]) => void): void; on(event: string, cb: (...args: any[]) => void): void;
} }
interface Disposer { interface IDisposable {
onDidDispose: (cb: () => void) => void;
dispose(): void; dispose(): void;
} }
interface IdeApi { interface Disposer extends IDisposable {
readonly client: { onDidDispose: (cb: () => void) => void;
}
interface Event<T> {
(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]): IDisposable;
}
interface IAction extends IDisposable {
id: string;
label: string;
tooltip: string;
class: string | undefined;
enabled: boolean;
checked: boolean;
radio: boolean;
run(event?: any): Promise<any>;
}
interface IStatusbarEntry {
readonly text: string;
readonly tooltip?: string;
readonly color?: string;
readonly command?: string;
readonly arguments?: any[];
readonly showBeak?: boolean;
}
interface IStatusbarService {
addEntry(entry: IStatusbarEntry, alignment: StatusbarAlignment, priority?: number): IDisposable;
setStatusMessage(message: string, autoDisposeAfter?: number, delayBy?: number): IDisposable;
}
type NotificationMessage = string | Error;
interface INotificationProperties {
sticky?: boolean;
silent?: boolean;
}
interface INotification extends INotificationProperties {
severity: Severity;
message: NotificationMessage;
source?: string;
actions?: INotificationActions;
}
interface INotificationActions {
primary?: IAction[];
secondary?: IAction[];
}
interface INotificationProgress {
infinite(): void;
total(value: number): void;
worked(value: number): void;
done(): void;
}
export interface INotificationHandle {
readonly onDidClose: Event<void>;
readonly progress: INotificationProgress;
updateSeverity(severity: Severity): void;
updateMessage(message: NotificationMessage): void;
updateActions(actions?: INotificationActions): void;
close(): void;
}
export interface IPromptChoice {
label: string;
isSecondary?: boolean;
keepOpen?: boolean;
run: () => void;
}
export interface IPromptOptions extends INotificationProperties {
onCancel?: () => void;
}
export interface INotificationService {
notify(notification: INotification): INotificationHandle;
info(message: NotificationMessage | NotificationMessage[]): void;
warn(message: NotificationMessage | NotificationMessage[]): void;
error(message: NotificationMessage | NotificationMessage[]): void;
prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions): INotificationHandle;
}
declare namespace ide {
export const client: {
run(func: (helper: ActiveEvalEmitter) => Disposer): ActiveEvalEmitter; run(func: (helper: ActiveEvalEmitter) => Disposer): ActiveEvalEmitter;
run<T1>(func: (helper: ActiveEvalEmitter, a1: T1) => Disposer, a1: T1): ActiveEvalEmitter; run<T1>(func: (helper: ActiveEvalEmitter, a1: T1) => Disposer, a1: T1): ActiveEvalEmitter;
run<T1, T2>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2) => Disposer, a1: T1, a2: T2): ActiveEvalEmitter; run<T1, T2>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2) => Disposer, a1: T1, a2: T2): ActiveEvalEmitter;
@ -26,13 +104,29 @@ interface IdeApi {
evaluate<R, T1, T2, T3, T4, T5>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5) => R | Promise<R>, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): Promise<R>; evaluate<R, T1, T2, T3, T4, T5>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5) => R | Promise<R>, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): Promise<R>;
evaluate<R, T1, T2, T3, T4, T5, T6>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6) => R | Promise<R>, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): Promise<R>; evaluate<R, T1, T2, T3, T4, T5, T6>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6) => R | Promise<R>, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): Promise<R>;
}; };
readonly workbench: {
getService<T>(identifier: any): T | undefined; export const workbench: {
readonly statusbarService: IStatusbarService;
readonly notificationService: INotificationService;
}; };
export enum Severity {
Ignore = 0,
Info = 1,
Warning = 2,
Error = 3
}
export enum StatusbarAlignment {
LEFT = 0,
RIGHT = 1,
}
} }
declare interface Window { declare global {
ide?: IdeApi; interface Window {
ide?: typeof ide;
addEventListener(event: "ide-ready", callback: (ide: CustomEvent & { readonly ide: IdeApi }) => void): void; addEventListener(event: "ide-ready", callback: (ide: CustomEvent & { readonly ide: IdeApi }) => void): void;
}
} }

View File

@ -1,5 +1,6 @@
{ {
"name": "@coder/ide-api", "name": "@coder/ide-api",
"version": "1.0.1",
"typings": "api.d.ts", "typings": "api.d.ts",
"author": "Coder", "author": "Coder",
"license": "MIT", "license": "MIT",

View File

@ -1,5 +1,8 @@
import { IdeClient } from "@coder/ide"; import { IdeClient } from "@coder/ide";
import { client as ideClientInstance } from "@coder/ide/src/fill/client"; import { client as ideClientInstance } from "@coder/ide/src/fill/client";
import Severity from "vs/base/common/severity";
import { INotificationService } from "vs/platform/notification/common/notification";
import { IStatusbarService } from "vs/platform/statusbar/common/statusbar";
import * as paths from "./fill/paths"; import * as paths from "./fill/paths";
import "./vscode.scss"; import "./vscode.scss";
// NOTE: shouldn't import anything from VS Code here or anything that will // NOTE: shouldn't import anything from VS Code here or anything that will
@ -16,12 +19,17 @@ class VSClient extends IdeClient {
const { workbench } = require("./workbench") as typeof import("./workbench"); const { workbench } = require("./workbench") as typeof import("./workbench");
await workbench.initialize(); await workbench.initialize();
// tslint:disable-next-line:no-any
const getService = <T>(id: any): T => workbench.serviceCollection.get<T>(id) as T;
enum StatusbarAlignment { LEFT, RIGHT }
window.ide = { window.ide = {
client: ideClientInstance, client: ideClientInstance,
workbench: { workbench: {
// tslint:disable-next-line:no-any statusbarService: getService<IStatusbarService>(IStatusbarService),
getService: <T>(id: any): T => workbench.serviceCollection.get<T>(id) as T, notificationService: getService<INotificationService>(INotificationService),
}, },
Severity: Severity,
StatusbarAlignment: StatusbarAlignment,
}; };
const event = new CustomEvent("ide-ready"); const event = new CustomEvent("ide-ready");