Skip to content

Commit

Permalink
feat(vscode): add support for "workbench.extensions.installExtension"…
Browse files Browse the repository at this point in the history
… command

Signed-off-by: Florian Greinacher <florian.greinacher@siemens.com>
  • Loading branch information
fgreinacher committed Nov 20, 2020
1 parent e209832 commit c372d16
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,10 +2,13 @@

## v1.8.0

- [plugin-ext-vscode] added support for the command `workbench.extensions.installExtension`.

<a name="breaking_changes_1.8.0">[Breaking Changes:](#breaking_changes_1.8.0)</a>

- [file-search] Deprecate dependency on `@theia/process` and replaced its usage by node's `child_process` api.
- [electron] Removed `attachWillPreventUnload` method from the Electron main application. The `confirmExit` logic is handled on the frontend. [#8732](https://github.com/eclipse-theia/theia/pull/8732)
- [plugin-ext] `LocalDirectoryPluginDeployerResolver` has moved from `packages/plugin-ext/src/main/node/resolvers/plugin-local-dir-resolver.ts` to `packages/plugin-ext/src/main/node/resolvers/local-file-plugin-deployer-resolver.ts` and now derives from `LocalPluginDeployerResolver`.

## v1.7.0 - 29/10/2020

Expand Down
Expand Up @@ -53,6 +53,7 @@ import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { inject, injectable } from 'inversify';
import { Position } from '@theia/plugin-ext/lib/common/plugin-api-rpc';
import { URI } from 'vscode-uri';
import { PluginServer } from '@theia/plugin-ext/lib/common/plugin-protocol';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { TerminalFrontendContribution } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
import { QuickOpenWorkspace } from '@theia/workspace/lib/browser/quick-open-workspace';
Expand All @@ -63,6 +64,7 @@ import {
} from '@theia/navigator/lib/browser/navigator-contribution';
import { FILE_NAVIGATOR_ID, FileNavigatorWidget } from '@theia/navigator/lib/browser';
import { SelectableTreeNode } from '@theia/core/lib/browser/tree/tree-selection';
import { UriComponents } from '@theia/plugin-ext/lib/common/uri-components';

export namespace VscodeCommands {
export const OPEN: Command = {
Expand Down Expand Up @@ -106,6 +108,8 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
protected readonly terminalService: TerminalService;
@inject(CodeEditorWidgetUtil)
protected readonly codeEditorWidgetUtil: CodeEditorWidgetUtil;
@inject(PluginServer)
protected readonly pluginServer: PluginServer;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(VscodeCommands.OPEN, {
Expand Down Expand Up @@ -208,6 +212,15 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
commands.registerCommand({ id: 'workbench.action.openSettings' }, {
execute: () => commands.executeCommand(CommonCommands.OPEN_PREFERENCES.id)
});
commands.registerCommand({ id: 'workbench.extensions.installExtension' }, {
execute: async (vsixUriOrExtensionId: UriComponents | string) => {
if (typeof vsixUriOrExtensionId === 'string') {
this.pluginServer.deploy(`vscode:extension/${vsixUriOrExtensionId}`);
} else {
this.pluginServer.deploy(`local-file:${URI.revive(vsixUriOrExtensionId).fsPath}`);
}
}
});
commands.registerCommand({ id: 'workbench.action.files.save', }, {
execute: (uri?: monaco.Uri) => {
if (uri) {
Expand Down
Expand Up @@ -17,7 +17,7 @@
import { injectable } from 'inversify';
import { Argv, Arguments } from 'yargs';
import { CliContribution } from '@theia/core/lib/node/cli';
import { LocalDirectoryPluginDeployerResolver } from './resolvers/plugin-local-dir-resolver';
import { LocalDirectoryPluginDeployerResolver } from './resolvers/local-directory-plugin-deployer-resolver';

@injectable()
export class PluginCliContribution implements CliContribution {
Expand Down
Expand Up @@ -24,7 +24,8 @@ import {
PluginDeployerDirectoryHandler, PluginServer, pluginServerJsonRpcPath, PluginDeployerParticipant
} from '../../common/plugin-protocol';
import { PluginDeployerImpl } from './plugin-deployer-impl';
import { LocalDirectoryPluginDeployerResolver } from './resolvers/plugin-local-dir-resolver';
import { LocalFilePluginDeployerResolver } from './resolvers/local-file-plugin-deployer-resolver';
import { LocalDirectoryPluginDeployerResolver } from './resolvers/local-directory-plugin-deployer-resolver';
import { PluginTheiaFileHandler } from './handlers/plugin-theia-file-handler';
import { PluginTheiaDirectoryHandler } from './handlers/plugin-theia-directory-handler';
import { GithubPluginDeployerResolver } from './plugin-github-resolver';
Expand All @@ -47,6 +48,7 @@ export function bindMainBackend(bind: interfaces.Bind): void {
bind(BackendApplicationContribution).toService(PluginDeployerContribution);

bind(PluginDeployerResolver).to(LocalDirectoryPluginDeployerResolver).inSingletonScope();
bind(PluginDeployerResolver).to(LocalFilePluginDeployerResolver).inSingletonScope();
bind(PluginDeployerResolver).to(GithubPluginDeployerResolver).inSingletonScope();
bind(PluginDeployerResolver).to(HttpPluginDeployerResolver).inSingletonScope();

Expand Down
@@ -0,0 +1,39 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. 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
********************************************************************************/

/* eslint-disable @typescript-eslint/no-explicit-any */

import { PluginDeployerResolverContext } from '../../../common/plugin-protocol';
import { injectable } from 'inversify';
import * as fs from 'fs-extra';
import * as path from 'path';
import { LocalPluginDeployerResolver } from './local-plugin-deployer-resolver';

@injectable()
export class LocalDirectoryPluginDeployerResolver extends LocalPluginDeployerResolver {
static LOCAL_DIR = 'local-dir';

constructor() {
super(LocalDirectoryPluginDeployerResolver.LOCAL_DIR);
}

protected async resolveFromLocalPath(pluginResolverContext: PluginDeployerResolverContext, localPath: string): Promise<void> {
const files = await fs.readdir(localPath);
files.forEach(file =>
pluginResolverContext.addPlugin(file, path.resolve(localPath, file))
);
}
}
@@ -0,0 +1,36 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. 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
********************************************************************************/

/* eslint-disable @typescript-eslint/no-explicit-any */

import { PluginDeployerResolverContext } from '../../../common/plugin-protocol';
import { injectable } from 'inversify';
import * as path from 'path';
import { LocalPluginDeployerResolver } from './local-plugin-deployer-resolver';

@injectable()
export class LocalFilePluginDeployerResolver extends LocalPluginDeployerResolver {
static LOCAL_FILE = 'local-file';

constructor() {
super(LocalFilePluginDeployerResolver.LOCAL_FILE);
}

async resolveFromLocalPath(pluginResolverContext: PluginDeployerResolverContext, localPath: string): Promise<void> {
const fileName = path.basename(localPath);
pluginResolverContext.addPlugin(fileName, localPath);
}
}
@@ -0,0 +1,59 @@
/********************************************************************************
* Copyright (C) 2020 Red Hat, Inc. 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 { PluginDeployerResolver, PluginDeployerResolverContext } from '../../../common/plugin-protocol';
import * as fs from 'fs-extra';
import * as path from 'path';
import { FileUri } from '@theia/core/lib/node';
import URI from '@theia/core/lib/common/uri';

export abstract class LocalPluginDeployerResolver implements PluginDeployerResolver {
constructor(private readonly scheme: string) { }

public async resolve(pluginResolverContext: PluginDeployerResolverContext): Promise<void> {
const localPath = await this.resolveLocalPluginPath(
pluginResolverContext,
this.scheme);
if (localPath) {
await this.resolveFromLocalPath(pluginResolverContext, localPath);
}
}

public accept(pluginId: string): boolean {
return pluginId.startsWith(this.scheme);
}

protected abstract resolveFromLocalPath(pluginResolverContext: PluginDeployerResolverContext, localPath: string): Promise<void>;

private async resolveLocalPluginPath(
pluginResolverContext: PluginDeployerResolverContext,
expectedScheme: string): Promise<string | null> {
const localUri = new URI(pluginResolverContext.getOriginId());
if (localUri.scheme !== expectedScheme) {
return null;
}
let fsPath = FileUri.fsPath(localUri);
if (!path.isAbsolute(fsPath)) {
fsPath = path.resolve(process.cwd(), fsPath);
}
if (!await fs.pathExists(fsPath)) {
console.warn(`The local plugin referenced by ${pluginResolverContext.getOriginId()} does not exist.`);
return null;
}
return fsPath;
}

}

This file was deleted.

0 comments on commit c372d16

Please sign in to comment.