From 1f842ea7693e95aef9bda2c394a0249a0ce300d5 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Thu, 16 Jul 2020 19:12:46 -0400 Subject: [PATCH] api-samples: add new command to output api version The following commit adds a new command to the `api-samples` to output the supported vscode api version for development purposes. The api version is changeable by specifying a cli argument such as: `yarn start --vscode-api-version={version}` Signed-off-by: vince-fugnitto --- examples/api-samples/compile.tsconfig.json | 3 ++ examples/api-samples/package.json | 3 +- .../browser/api-samples-frontend-module.ts | 2 + .../vsx/sample-vsx-command-contribution.ts | 48 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 examples/api-samples/src/browser/vsx/sample-vsx-command-contribution.ts diff --git a/examples/api-samples/compile.tsconfig.json b/examples/api-samples/compile.tsconfig.json index 3fa08280f9188..f82db1c097e92 100644 --- a/examples/api-samples/compile.tsconfig.json +++ b/examples/api-samples/compile.tsconfig.json @@ -14,6 +14,9 @@ }, { "path": "../../packages/output/compile.tsconfig.json" + }, + { + "path": "../../packages/vsx-registry/compile.tsconfig.json" } ] } diff --git a/examples/api-samples/package.json b/examples/api-samples/package.json index dcbb0a9d0d688..cd58c5704a014 100644 --- a/examples/api-samples/package.json +++ b/examples/api-samples/package.json @@ -5,7 +5,8 @@ "description": "Theia - Example code to demonstrate Theia API", "dependencies": { "@theia/core": "^1.8.0", - "@theia/output": "^1.8.0" + "@theia/output": "^1.8.0", + "@theia/vsx-registry": "^1.8.0" }, "theiaExtensions": [ { diff --git a/examples/api-samples/src/browser/api-samples-frontend-module.ts b/examples/api-samples/src/browser/api-samples-frontend-module.ts index 7fb53971ce6b7..887fa64b99270 100644 --- a/examples/api-samples/src/browser/api-samples-frontend-module.ts +++ b/examples/api-samples/src/browser/api-samples-frontend-module.ts @@ -20,6 +20,7 @@ import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribu import { bindSampleOutputChannelWithSeverity } from './output/sample-output-channel-with-severity'; import { bindSampleMenu } from './menu/sample-menu-contribution'; import { bindSampleFileWatching } from './file-watching/sample-file-watching-contribution'; +import { bindVSXCommand } from './vsx/sample-vsx-command-contribution'; import '../../src/browser/style/branding.css'; @@ -29,4 +30,5 @@ export default new ContainerModule(bind => { bindSampleOutputChannelWithSeverity(bind); bindSampleMenu(bind); bindSampleFileWatching(bind); + bindVSXCommand(bind); }); diff --git a/examples/api-samples/src/browser/vsx/sample-vsx-command-contribution.ts b/examples/api-samples/src/browser/vsx/sample-vsx-command-contribution.ts new file mode 100644 index 0000000000000..843679255a3d6 --- /dev/null +++ b/examples/api-samples/src/browser/vsx/sample-vsx-command-contribution.ts @@ -0,0 +1,48 @@ +/******************************************************************************** + * Copyright (C) 2020 Ericsson and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { inject, injectable, interfaces } from 'inversify'; +import { VSXEnvironment } from '@theia/vsx-registry/lib/common/vsx-environment'; +import { Command, CommandContribution, CommandRegistry, MessageService } from '@theia/core/lib/common'; + +@injectable() +export class VSXCommandContribution implements CommandContribution { + + @inject(MessageService) + protected readonly messageService: MessageService; + + @inject(VSXEnvironment) + protected readonly environment: VSXEnvironment; + + protected readonly command: Command = { + id: 'vsx.echo-api-version', + label: 'VS Code API Version' + }; + + registerCommands(commands: CommandRegistry): void { + commands.registerCommand(this.command, { + execute: async () => { + const version = await this.environment.getVscodeApiVersion(); + this.messageService.info(`Supported VS Code API Version: ${version}`); + } + }); + } + +} + +export const bindVSXCommand = (bind: interfaces.Bind) => { + bind(CommandContribution).to(VSXCommandContribution).inSingletonScope(); +};