Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
toDispose.push(this.commands.registerCommand(command, handler));
const { when } = action;
const whenKeys = when && this.contextKeyService.parseKeys(when);
let onDidChange;
if (whenKeys && whenKeys.size) {
const onDidChangeEmitter = new Emitter();
toDispose.push(onDidChangeEmitter);
onDidChange = onDidChangeEmitter.event;
this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners + 1;
toDispose.push(this.contextKeyService.onDidChange(event => {
if (event.affects(whenKeys)) {
onDidChangeEmitter.fire(undefined);
}
}));
toDispose.push(Disposable.create(() => {
this.contextKeyService.onDidChange.maxListeners = this.contextKeyService.onDidChange.maxListeners - 1;
}));
}
// handle group and priority
// if group is empty or white space is will be set to navigation
// ' ' => ['navigation', 0]
// 'navigation@1' => ['navigation', 1]
// '1_rest-client@2' => ['1_rest-client', 2]
// if priority is not a number it will be set to 0
// navigation@test => ['navigation', 0]
const [group, sort] = (action.group || 'navigation').split('@');
const item: Mutable = { id, command: id, group: group.trim() || 'navigation', priority: ~~sort || undefined, when, onDidChange };
toDispose.push(this.tabBarToolbar.registerItem(item));
toDispose.push(this.onDidRegisterCommand(action.command, pluginCommand => {
protected onDidRegisterCommand(id: string, cb: (command: Command) => void): Disposable {
const command = this.commands.getCommand(id);
if (command) {
cb(command);
return Disposable.NULL;
}
const toDispose = new DisposableCollection();
// Registering a menu action requires the related command to be already registered.
// But Theia plugin registers the commands dynamically via the Commands API.
// Let's wait for ~2 sec. It should be enough to finish registering all the contributed commands.
// FIXME: remove this workaround (timer) once the https://github.com/theia-ide/theia/issues/3344 is fixed
const handle = setTimeout(() => toDispose.push(this.onDidRegisterCommand(id, cb)), 2000);
toDispose.push(Disposable.create(() => clearTimeout(handle)));
return toDispose;
}
thenable.push((async () => {
try {
const activationEvents = [...this.activationEvents];
await manager.$start({ plugins, configStorage, activationEvents });
if (toDisconnect.disposed) {
return;
}
for (const contributions of hostContributions) {
started++;
const plugin = contributions.plugin;
const id = plugin.metadata.model.id;
contributions.state = PluginContributions.State.STARTED;
console.log(`[${this.clientId}][${id}]: Started plugin.`);
toDisconnect.push(contributions.push(Disposable.create(() => {
console.log(`[${this.clientId}][${id}]: Stopped plugin.`);
manager.$stop(id);
})));
this.activateByWorkspaceContains(manager, plugin);
}
} catch (e) {
console.error(`Failed to start plugins for '${host}' host`, e);
}
})());
}
constructor(extension: protocol.Extension,
protected readonly server: protocol.ExtensionServer,
protected readonly manager: ExtensionManager) {
super();
Object.assign(this, extension);
this.toDispose.push(this.onDidChangedEmitter);
manager.onDidChange.maxListeners = manager.onDidChange.maxListeners + 1;
this.toDispose.push(manager.onDidChange(change => {
if (change.name === this.name) {
Object.assign(this, change);
this.onDidChangedEmitter.fire(change);
}
}));
this.toDispose.push(Disposable.create(() =>
manager.onDidChange.maxListeners = manager.onDidChange.maxListeners - 1)
);
}
protected doAutoSave(): void {
if (this.autoSave === 'on') {
const token = this.cancelSave();
this.toDisposeOnAutoSave.dispose();
const handle = window.setTimeout(() => {
this.scheduleSave(TextDocumentSaveReason.AfterDelay, token);
}, this.autoSaveDelay);
this.toDisposeOnAutoSave.push(Disposable.create(() =>
window.clearTimeout(handle)),
);
}
}
focus(): void {
if (!this.doFocus()) {
this.onRender.push(Disposable.create(() => this.doFocus()));
this.update();
}
}
protected doFocus(): boolean {
}
for (const { completion } of items) {
completion.range = monaco.Range.fromPositions(position.delta(0, -overwriteBefore), position);
suggestions.push(completion);
}
}
return { suggestions };
}
}));
this.toDispose.push(this.zone.onDidLayoutChange(dimension => this.layout(dimension)));
this.toDispose.push(input.getControl().onDidChangeModelContent(() => {
const heightInLines = input.getControl().getModel()!.getLineCount() + 1;
this.zone.layout(heightInLines);
this.updatePlaceholder();
}));
this.toDispose.push(Disposable.create(() => ReactDOM.unmountComponentAtNode(selectNode)));
}
protected async obtainManager(host: string, hostContributions: PluginContributions[], toDisconnect: DisposableCollection): Promise {
let manager = this.managers.get(host);
if (!manager) {
const pluginId = getPluginId(hostContributions[0].plugin.metadata.model);
const rpc = this.initRpc(host, pluginId);
toDisconnect.push(rpc);
manager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
this.managers.set(host, manager);
toDisconnect.push(Disposable.create(() => this.managers.delete(host)));
const [extApi, globalState, workspaceState, webviewResourceRoot, webviewCspSource, defaultShell] = await Promise.all([
this.server.getExtPluginAPI(),
this.pluginServer.getAllStorageValues(undefined),
this.pluginServer.getAllStorageValues({
workspace: this.workspaceService.workspace,
roots: this.workspaceService.tryGetRoots()
}),
this.webviewEnvironment.resourceRoot(),
this.webviewEnvironment.cspSource(),
this.terminalService.getDefaultShell()
]);
if (toDisconnect.disposed) {
return undefined;
}