Skip to content

Commit 7f18ce1

Browse files
committed
Update IDE api
1 parent 973450e commit 7f18ce1

File tree

3 files changed

+116
-13
lines changed

3 files changed

+116
-13
lines changed

packages/ide-api/api.d.ts

Lines changed: 105 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,90 @@ interface ActiveEvalEmitter {
44
emit(event: string, ...args: any[]): void;
55
on(event: string, cb: (...args: any[]) => void): void;
66
}
7-
interface Disposer {
8-
onDidDispose: (cb: () => void) => void;
7+
interface IDisposable {
98
dispose(): void;
109
}
11-
interface IdeApi {
12-
readonly client: {
10+
interface Disposer extends IDisposable {
11+
onDidDispose: (cb: () => void) => void;
12+
}
13+
interface Event<T> {
14+
(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]): IDisposable;
15+
}
16+
interface IAction extends IDisposable {
17+
id: string;
18+
label: string;
19+
tooltip: string;
20+
class: string | undefined;
21+
enabled: boolean;
22+
checked: boolean;
23+
radio: boolean;
24+
run(event?: any): Promise<any>;
25+
}
26+
interface IStatusbarEntry {
27+
readonly text: string;
28+
readonly tooltip?: string;
29+
readonly color?: string;
30+
readonly command?: string;
31+
readonly arguments?: any[];
32+
readonly showBeak?: boolean;
33+
}
34+
interface IStatusbarService {
35+
addEntry(entry: IStatusbarEntry, alignment: StatusbarAlignment, priority?: number): IDisposable;
36+
setStatusMessage(message: string, autoDisposeAfter?: number, delayBy?: number): IDisposable;
37+
}
38+
type NotificationMessage = string | Error;
39+
interface INotificationProperties {
40+
sticky?: boolean;
41+
silent?: boolean;
42+
}
43+
interface INotification extends INotificationProperties {
44+
severity: Severity;
45+
message: NotificationMessage;
46+
source?: string;
47+
actions?: INotificationActions;
48+
}
49+
interface INotificationActions {
50+
primary?: IAction[];
51+
secondary?: IAction[];
52+
}
53+
54+
interface INotificationProgress {
55+
infinite(): void;
56+
total(value: number): void;
57+
worked(value: number): void;
58+
done(): void;
59+
}
60+
61+
export interface INotificationHandle {
62+
readonly onDidClose: Event<void>;
63+
readonly progress: INotificationProgress;
64+
updateSeverity(severity: Severity): void;
65+
updateMessage(message: NotificationMessage): void;
66+
updateActions(actions?: INotificationActions): void;
67+
close(): void;
68+
}
69+
70+
export interface IPromptChoice {
71+
label: string;
72+
isSecondary?: boolean;
73+
keepOpen?: boolean;
74+
run: () => void;
75+
}
76+
77+
export interface IPromptOptions extends INotificationProperties {
78+
onCancel?: () => void;
79+
}
80+
81+
export interface INotificationService {
82+
notify(notification: INotification): INotificationHandle;
83+
info(message: NotificationMessage | NotificationMessage[]): void;
84+
warn(message: NotificationMessage | NotificationMessage[]): void;
85+
error(message: NotificationMessage | NotificationMessage[]): void;
86+
prompt(severity: Severity, message: string, choices: IPromptChoice[], options?: IPromptOptions): INotificationHandle;
87+
}
88+
89+
declare namespace ide {
90+
export const client: {
1391
run(func: (helper: ActiveEvalEmitter) => Disposer): ActiveEvalEmitter;
1492
run<T1>(func: (helper: ActiveEvalEmitter, a1: T1) => Disposer, a1: T1): ActiveEvalEmitter;
1593
run<T1, T2>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2) => Disposer, a1: T1, a2: T2): ActiveEvalEmitter;
@@ -26,13 +104,29 @@ interface IdeApi {
26104
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>;
27105
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>;
28106
};
29-
readonly workbench: {
30-
getService<T>(identifier: any): T | undefined;
107+
108+
export const workbench: {
109+
readonly statusbarService: IStatusbarService;
110+
readonly notificationService: INotificationService;
31111
};
32-
}
33112

34-
declare interface Window {
35-
ide?: IdeApi;
113+
export enum Severity {
114+
Ignore = 0,
115+
Info = 1,
116+
Warning = 2,
117+
Error = 3
118+
}
36119

37-
addEventListener(event: "ide-ready", callback: (ide: CustomEvent & { readonly ide: IdeApi }) => void): void;
38-
}
120+
export enum StatusbarAlignment {
121+
LEFT = 0,
122+
RIGHT = 1,
123+
}
124+
}
125+
126+
declare global {
127+
interface Window {
128+
ide?: typeof ide;
129+
130+
addEventListener(event: "ide-ready", callback: (ide: CustomEvent & { readonly ide: IdeApi }) => void): void;
131+
}
132+
}

packages/ide-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "@coder/ide-api",
3+
"version": "1.0.1",
34
"typings": "api.d.ts",
45
"author": "Coder",
56
"license": "MIT",

packages/vscode/src/client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { IdeClient } from "@coder/ide";
22
import { client as ideClientInstance } from "@coder/ide/src/fill/client";
3+
import Severity from "vs/base/common/severity";
4+
import { INotificationService } from "vs/platform/notification/common/notification";
5+
import { IStatusbarService } from "vs/platform/statusbar/common/statusbar";
36
import * as paths from "./fill/paths";
47
import "./vscode.scss";
58
// NOTE: shouldn't import anything from VS Code here or anything that will
@@ -16,12 +19,17 @@ class VSClient extends IdeClient {
1619
const { workbench } = require("./workbench") as typeof import("./workbench");
1720
await workbench.initialize();
1821

22+
// tslint:disable-next-line:no-any
23+
const getService = <T>(id: any): T => workbench.serviceCollection.get<T>(id) as T;
24+
enum StatusbarAlignment { LEFT, RIGHT }
1925
window.ide = {
2026
client: ideClientInstance,
2127
workbench: {
22-
// tslint:disable-next-line:no-any
23-
getService: <T>(id: any): T => workbench.serviceCollection.get<T>(id) as T,
28+
statusbarService: getService<IStatusbarService>(IStatusbarService),
29+
notificationService: getService<INotificationService>(INotificationService),
2430
},
31+
Severity: Severity,
32+
StatusbarAlignment: StatusbarAlignment,
2533
};
2634

2735
const event = new CustomEvent("ide-ready");

0 commit comments

Comments
 (0)