Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open VSX Registry integration #6655

Merged
merged 7 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cache:
- packages/typehierarchy/node_modules
- packages/userstorage/node_modules
- packages/variable-resolver/node_modules
- packages/vsx-registry/node_modules
- packages/workspace/node_modules
# end_cache_directories
before_cache:
Expand Down
3 changes: 3 additions & 0 deletions configs/root-compilation.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
},
{
"path": "../examples/electron/compile.tsconfig.json"
},
{
"path": "../packages/vsx-registry/compile.tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@theia/typehierarchy": "^0.16.0",
"@theia/userstorage": "^0.16.0",
"@theia/variable-resolver": "^0.16.0",
"@theia/vsx-registry": "^0.16.0",
"@theia/workspace": "^0.16.0"
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions examples/electron/compile.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
},
{
"path": "../../packages/workspace/compile.tsconfig.json"
},
{
"path": "../../packages/vsx-registry/compile.tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@theia/typehierarchy": "^0.16.0",
"@theia/userstorage": "^0.16.0",
"@theia/variable-resolver": "^0.16.0",
"@theia/vsx-registry": "^0.16.0",
"@theia/workspace": "^0.16.0"
},
"scripts": {
Expand Down
19 changes: 13 additions & 6 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import { interfaces, injectable, inject, postConstruct } from 'inversify';
import { IIterator, toArray, find, some, every, map } from '@phosphor/algorithm';
import {
Widget, EXPANSION_TOGGLE_CLASS, COLLAPSED_CLASS, MessageLoop, Message, SplitPanel, BaseWidget,
addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener
addEventListener, SplitLayout, LayoutItem, PanelLayout, addKeyListener, waitForRevealed
} from './widgets';
import { Event, Emitter } from '../common/event';
import { Deferred } from '../common/promise-util';
import { Disposable, DisposableCollection } from '../common/disposable';
import { CommandRegistry } from '../common/command';
import { MenuModelRegistry, MenuPath, MenuAction } from '../common/menu';
Expand Down Expand Up @@ -57,7 +56,6 @@ export class ViewContainerIdentifier {
export class ViewContainer extends BaseWidget implements StatefulWidget, ApplicationShell.TrackableWidgetProvider {

protected panel: SplitPanel;
protected attached = new Deferred<void>();

protected currentPart: ViewContainerPart | undefined;

Expand Down Expand Up @@ -110,7 +108,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}, this.splitPositionHandler)
});
this.panel.node.tabIndex = -1;
layout.addWidget(this.panel);
this.configureLayout(layout);

const { commandRegistry, menuRegistry, contextMenuRenderer } = this;
this.toDispose.pushAll([
Expand Down Expand Up @@ -148,6 +146,10 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}
}

protected configureLayout(layout: PanelLayout): void {
layout.addWidget(this.panel);
}

protected readonly toDisposeOnCurrentPart = new DisposableCollection();

protected updateCurrentPart(part?: ViewContainerPart): void {
Expand Down Expand Up @@ -345,6 +347,9 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
if (!this.isVisible && this.lastVisibleState) {
return this.lastVisibleState;
}
return this.doStoreState();
}
protected doStoreState(): ViewContainer.State {
const parts = this.getParts();
const availableSize = this.containerLayout.getAvailableSize();
const orientation = this.orientation;
Expand All @@ -371,6 +376,9 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
*/
restoreState(state: ViewContainer.State): void {
this.lastVisibleState = state;
this.doRestoreState(state);
}
protected doRestoreState(state: ViewContainer.State): void {
this.setTitleOptions(state.title);
// restore widgets
for (const part of state.parts) {
Expand Down Expand Up @@ -406,7 +414,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}

// Restore part sizes
this.attached.promise.then(() => {
waitForRevealed(this).then(() => {
this.containerLayout.setPartSizes(partStates.map(partState => partState.relativeSize));
});
}
Expand Down Expand Up @@ -539,7 +547,6 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}
}
super.onAfterAttach(msg);
requestAnimationFrame(() => this.attached.resolve());
}

protected onBeforeHide(msg: Message): void {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@theia/plugin-ext": "^0.16.0",
"@theia/workspace": "^0.16.0",
"@types/request": "^2.0.3",
"filenamify": "^4.1.0",
vince-fugnitto marked this conversation as resolved.
Show resolved Hide resolved
"request": "^2.82.0"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import { ContainerModule } from 'inversify';
import { CommandContribution } from '@theia/core';
import { PluginVscodeCommandsContribution } from './plugin-vscode-commands-contribution';
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';

export default new ContainerModule(bind => {
bind(PluginVSCodeEnvironment).toSelf().inSingletonScope();
bind(PluginVscodeCommandsContribution).toSelf().inSingletonScope();
bind(CommandContribution).toDynamicValue(context => context.container.get(PluginVscodeCommandsContribution));
});
36 changes: 36 additions & 0 deletions packages/plugin-ext-vscode/src/common/plugin-vscode-environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox 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 { injectable, inject } from 'inversify';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import URI from '@theia/core/lib/common/uri';

@injectable()
export class PluginVSCodeEnvironment {

@inject(EnvVariablesServer)
protected readonly environments: EnvVariablesServer;

protected _extensionsDirUri: URI | undefined;
async getExtensionsDirUri(): Promise<URI> {
if (!this._extensionsDirUri) {
const configDir = new URI(await this.environments.getConfigDirUri());
this._extensionsDirUri = configDir.resolve('extensions');
}
return this._extensionsDirUri;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@
********************************************************************************/

import { ContainerModule } from 'inversify';
import { PluginDeployerFileHandler, PluginDeployerDirectoryHandler, PluginScanner, PluginDeployerResolver } from '@theia/plugin-ext';
import {
PluginDeployerFileHandler, PluginDeployerDirectoryHandler, PluginScanner, PluginDeployerParticipant
} from '@theia/plugin-ext';
import { PluginVsCodeFileHandler } from './plugin-vscode-file-handler';
import { PluginVsCodeDirectoryHandler } from './plugin-vscode-directory-handler';
import { VsCodePluginScanner } from './scanner-vscode';
import { VsCodePluginDeployerResolver } from './plugin-vscode-resolver';
import { PluginVsCodeCliContribution } from './plugin-vscode-cli-contribution';
import { CliContribution } from '@theia/core/lib/node';
import { PluginHostEnvironmentVariable } from '@theia/plugin-ext/lib/common';
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
import { PluginVSCodeDeployerParticipant } from './plugin-vscode-deployer-participant';

export default new ContainerModule(bind => {
bind(PluginVSCodeEnvironment).toSelf().inSingletonScope();

bind(PluginVSCodeDeployerParticipant).toSelf().inSingletonScope();
bind(PluginDeployerParticipant).toService(PluginVSCodeDeployerParticipant);

bind(PluginDeployerFileHandler).to(PluginVsCodeFileHandler).inSingletonScope();
bind(PluginDeployerDirectoryHandler).to(PluginVsCodeDirectoryHandler).inSingletonScope();
bind(PluginScanner).to(VsCodePluginScanner).inSingletonScope();
bind(PluginDeployerResolver).to(VsCodePluginDeployerResolver).inSingletonScope();

bind(PluginVsCodeCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(PluginVsCodeCliContribution);
bind(PluginHostEnvironmentVariable).toService(PluginVsCodeCliContribution);
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************************************************************
* Copyright (C) 2020 TypeFox 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 { injectable, inject } from 'inversify';
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
import { PluginDeployerParticipant, PluginDeployerStartContext } from '@theia/plugin-ext/lib/common/plugin-protocol';

@injectable()
export class PluginVSCodeDeployerParticipant implements PluginDeployerParticipant {

@inject(PluginVSCodeEnvironment)
protected readonly environments: PluginVSCodeEnvironment;

async onWillStart(context: PluginDeployerStartContext): Promise<void> {
const extensionsDirUri = await this.environments.getExtensionsDirUri();
context.userEntries.push(extensionsDirUri.withScheme('local-dir').toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class PluginVsCodeDirectoryHandler implements PluginDeployerDirectoryHand
}
if (options) {
plugin.storeValue('package.json', pck);
plugin.rootPath = plugin.path();
plugin.updatePath(pluginPath);
}
console.log(`Resolved "${plugin.id()}" to a VS Code extension "${pck.name}@${pck.version}" with engines:`, pck.engines);
Expand Down
46 changes: 33 additions & 13 deletions packages/plugin-ext-vscode/src/node/plugin-vscode-file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { PluginDeployerFileHandler, PluginDeployerEntry, PluginDeployerFileHandlerContext } from '@theia/plugin-ext';
import { injectable } from 'inversify';
import { PluginDeployerFileHandler, PluginDeployerEntry, PluginDeployerFileHandlerContext, PluginType } from '@theia/plugin-ext';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as filenamify from 'filenamify';
import { injectable, inject } from 'inversify';
import { getTempDir } from '@theia/plugin-ext/lib/main/node/temp-dir-util';
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
import { FileUri } from '@theia/core/lib/node/file-uri';

@injectable()
export class PluginVsCodeFileHandler implements PluginDeployerFileHandler {

private unpackedFolder: string;
constructor() {
this.unpackedFolder = getTempDir('vscode-unpacked');
}
@inject(PluginVSCodeEnvironment)
protected readonly environment: PluginVSCodeEnvironment;

private readonly systemExtensionsDirUri = FileUri.create(getTempDir('vscode-unpacked'));

accept(resolvedPlugin: PluginDeployerEntry): boolean {
if (!resolvedPlugin.isFile()) {
Expand All @@ -37,19 +40,36 @@ export class PluginVsCodeFileHandler implements PluginDeployerFileHandler {
}

async handle(context: PluginDeployerFileHandlerContext): Promise<void> {
const unpackedPath = path.resolve(this.unpackedFolder, path.basename(context.pluginEntry().path()));
console.log(`unzipping the VS Code extension '${path.basename(context.pluginEntry().path())}' to directory: ${unpackedPath}`);
const id = context.pluginEntry().id();
const extensionDir = await this.getExtensionDir(context);
console.log(`[${id}]: trying to decompress into "${extensionDir}"...`);
if (context.pluginEntry().type === PluginType.User && await fs.pathExists(extensionDir)) {
console.log(`[${id}]: already found`);
context.pluginEntry().updatePath(extensionDir);
return;
}
await this.decompress(extensionDir, context);
console.log(`[${id}]: decompressed`);
context.pluginEntry().updatePath(extensionDir);
}

await context.unzip(context.pluginEntry().path(), unpackedPath);
protected async getExtensionDir(context: PluginDeployerFileHandlerContext): Promise<string> {
let extensionsDirUri = this.systemExtensionsDirUri;
if (context.pluginEntry().type === PluginType.User) {
extensionsDirUri = await this.environment.getExtensionsDirUri();
}
return FileUri.fsPath(extensionsDirUri.resolve(filenamify(context.pluginEntry().id())));
}

protected async decompress(extensionDir: string, context: PluginDeployerFileHandlerContext): Promise<void> {
await context.unzip(context.pluginEntry().path(), extensionDir);
if (context.pluginEntry().path().endsWith('.tgz')) {
const extensionPath = path.join(unpackedPath, 'package');
const extensionPath = path.join(extensionDir, 'package');
const vscodeNodeModulesPath = path.join(extensionPath, 'vscode_node_modules.zip');
if (await fs.pathExists(vscodeNodeModulesPath)) {
await context.unzip(vscodeNodeModulesPath, path.join(extensionPath, 'node_modules'));
}
}

context.pluginEntry().updatePath(unpackedPath);
return Promise.resolve();
}

}
Loading