mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-27 04:35:25 +00:00
Add IDE API (#36)
This commit is contained in:
parent
14da71499f
commit
7b5871136b
5
packages/ide-api/README.md
Normal file
5
packages/ide-api/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# ide-api
|
||||||
|
|
||||||
|
Provides window listeners for interfacing with the IDE.
|
||||||
|
|
||||||
|
Created for content-scripts.
|
38
packages/ide-api/api.d.ts
vendored
Normal file
38
packages/ide-api/api.d.ts
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
interface EvalHelper { }
|
||||||
|
interface ActiveEvalEmitter {
|
||||||
|
removeAllListeners(event?: string): void;
|
||||||
|
emit(event: string, ...args: any[]): void;
|
||||||
|
on(event: string, cb: (...args: any[]) => void): void;
|
||||||
|
}
|
||||||
|
interface Disposer {
|
||||||
|
onDidDispose: (cb: () => void) => void;
|
||||||
|
dispose(): void;
|
||||||
|
}
|
||||||
|
interface IdeApi {
|
||||||
|
readonly client: {
|
||||||
|
run(func: (helper: ActiveEvalEmitter) => Disposer): 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, T3>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2, a3: T3) => Disposer, a1: T1, a2: T2, a3: T3): ActiveEvalEmitter;
|
||||||
|
run<T1, T2, T3, T4>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2, a3: T3, a4: T4) => Disposer, a1: T1, a2: T2, a3: T3, a4: T4): ActiveEvalEmitter;
|
||||||
|
run<T1, T2, T3, T4, T5>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5) => Disposer, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5): ActiveEvalEmitter;
|
||||||
|
run<T1, T2, T3, T4, T5, T6>(func: (helper: ActiveEvalEmitter, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6) => Disposer, a1: T1, a2: T2, a3: T3, a4: T4, a5: T5, a6: T6): ActiveEvalEmitter;
|
||||||
|
|
||||||
|
evaluate<R>(func: (helper: EvalHelper) => R | Promise<R>): Promise<R>;
|
||||||
|
evaluate<R, T1>(func: (helper: EvalHelper, a1: T1) => R | Promise<R>, a1: T1): Promise<R>;
|
||||||
|
evaluate<R, T1, T2>(func: (helper: EvalHelper, a1: T1, a2: T2) => R | Promise<R>, a1: T1, a2: T2): Promise<R>;
|
||||||
|
evaluate<R, T1, T2, T3>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3) => R | Promise<R>, a1: T1, a2: T2, a3: T3): Promise<R>;
|
||||||
|
evaluate<R, T1, T2, T3, T4>(func: (helper: EvalHelper, a1: T1, a2: T2, a3: T3, a4: T4) => R | Promise<R>, a1: T1, a2: T2, a3: T3, a4: T4): 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>;
|
||||||
|
};
|
||||||
|
readonly workbench: {
|
||||||
|
getService<T>(identifier: any): T | undefined;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
declare interface Window {
|
||||||
|
ide?: IdeApi;
|
||||||
|
|
||||||
|
addEventListener(event: "ide-ready", callback: (ide: CustomEvent & { readonly ide: IdeApi }) => void): void;
|
||||||
|
}
|
7
packages/ide-api/package.json
Normal file
7
packages/ide-api/package.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "@coder/ide-api",
|
||||||
|
"typings": "api.d.ts",
|
||||||
|
"author": "Coder",
|
||||||
|
"license": "MIT",
|
||||||
|
"description": "API for interfacing with the API created for content-scripts"
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import { IdeClient } from "@coder/ide";
|
import { IdeClient } from "@coder/ide";
|
||||||
|
import { client as ideClientInstance } from "@coder/ide/src/fill/client";
|
||||||
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
|
||||||
@ -14,6 +15,19 @@ class VSClient extends IdeClient {
|
|||||||
// callback, meaning we are safe to include everything from VS Code now.
|
// callback, meaning we are safe to include everything from VS Code now.
|
||||||
const { workbench } = require("./workbench") as typeof import("./workbench");
|
const { workbench } = require("./workbench") as typeof import("./workbench");
|
||||||
await workbench.initialize();
|
await workbench.initialize();
|
||||||
|
|
||||||
|
window.ide = {
|
||||||
|
client: ideClientInstance,
|
||||||
|
workbench: {
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
getService: <T>(id: any): T => workbench.serviceCollection.get<T>(id) as T,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const event = new CustomEvent("ide-ready");
|
||||||
|
// tslint:disable-next-line:no-any
|
||||||
|
(<any>event).ide = window.ide;
|
||||||
|
window.dispatchEvent(event);
|
||||||
}, this.initData, this.sharedProcessData);
|
}, this.initData, this.sharedProcessData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user