sample for vscode.proposed.d.ts and implementation

This commit is contained in:
Johannes Rieken
2016-10-31 17:03:32 +01:00
parent 53df546a67
commit c510d53da7
5 changed files with 36 additions and 2 deletions

View File

@@ -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