mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
sample for vscode.proposed.d.ts and implementation
This commit is contained in:
@@ -50,6 +50,16 @@ export interface IExtensionApiFactory {
|
||||
(extension: IExtensionDescription): typeof vscode;
|
||||
}
|
||||
|
||||
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
|
||||
if (extension.enableProposedApi) {
|
||||
return fn;
|
||||
} else {
|
||||
return <any>(() => {
|
||||
throw new Error(`${extension.id} cannot access proposed api`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method instantiates and returns the extension API surface
|
||||
*/
|
||||
@@ -84,6 +94,10 @@ export function createApiFactory(initDataConfiguration: IInitConfiguration, init
|
||||
|
||||
return function (extension: IExtensionDescription): typeof vscode {
|
||||
|
||||
if (extension.enableProposedApi) {
|
||||
console.warn(`${extension.name} (${extension.id}) uses PROPOSED API which is subject to change and removal without notice`);
|
||||
}
|
||||
|
||||
// namespace: commands
|
||||
const commands: typeof vscode.commands = {
|
||||
registerCommand<T>(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
|
||||
@@ -258,7 +272,11 @@ export function createApiFactory(initDataConfiguration: IInitConfiguration, init
|
||||
},
|
||||
createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
|
||||
return extHostTerminalService.createTerminal(name, shellPath, shellArgs);
|
||||
}
|
||||
},
|
||||
// proposed API
|
||||
sampleFunction: proposedApiFunction(extension, () => {
|
||||
return extHostMessageService.showMessage(Severity.Info, 'Hello Proposed Api!', []);
|
||||
})
|
||||
};
|
||||
|
||||
// namespace: workspace
|
||||
|
||||
Reference in New Issue
Block a user