Skip to content

Commit

Permalink
Removed superfluous channel caching for extensions
Browse files Browse the repository at this point in the history
Instead of keeping an extra cache of channels for VS Code extensions,
we delegate the channel  manager one via commands.

Closes #8122

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
  • Loading branch information
Akos Kitta authored and kittaakos committed Sep 15, 2020
1 parent 48dfeb8 commit 525b4e6
Showing 1 changed file with 15 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,39 @@
********************************************************************************/

import { injectable, inject } from 'inversify';
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
import { OutputChannel, OutputChannelManager } from '@theia/output/lib/common/output-channel';
import { CommandService } from '@theia/core/lib/common/command';
import { OutputCommands } from '@theia/output/lib/browser/output-commands';
import { OutputChannelRegistryMain, PluginInfo } from '../../common/plugin-api-rpc';

@injectable()
export class OutputChannelRegistryMainImpl implements OutputChannelRegistryMain {

@inject(OutputChannelManager)
private outputChannelManager: OutputChannelManager;

@inject(OutputContribution)
private outputContribution: OutputContribution;

private commonOutputWidget: OutputWidget | undefined;

private channels: Map<string, OutputChannel> = new Map();

$append(channelName: string, value: string, pluginInfo: PluginInfo): PromiseLike<void> {
const outputChannel = this.getChannel(channelName);
if (outputChannel) {
outputChannel.append(value);
}
@inject(CommandService)
protected readonly commandService: CommandService;

$append(name: string, text: string, pluginInfo: PluginInfo): PromiseLike<void> {
this.commandService.executeCommand(OutputCommands.APPEND.id, { name, text });
return Promise.resolve();
}

$clear(channelName: string): PromiseLike<void> {
const outputChannel = this.getChannel(channelName);
if (outputChannel) {
outputChannel.clear();
}

$clear(name: string): PromiseLike<void> {
this.commandService.executeCommand(OutputCommands.CLEAR.id, { name });
return Promise.resolve();
}

$dispose(channelName: string): PromiseLike<void> {
this.outputChannelManager.deleteChannel(channelName);
if (this.channels.has(channelName)) {
this.channels.delete(channelName);
}

$dispose(name: string): PromiseLike<void> {
this.commandService.executeCommand(OutputCommands.DISPOSE.id, { name });
return Promise.resolve();
}

async $reveal(channelName: string, preserveFocus: boolean): Promise<void> {
const outputChannel = this.getChannel(channelName);
if (outputChannel) {
const activate = !preserveFocus;
const reveal = preserveFocus;
this.commonOutputWidget = await this.outputContribution.openView({ activate, reveal });
outputChannel.setVisibility(true);
}
async $reveal(name: string, preserveFocus: boolean): Promise<void> {
const options = { preserveFocus };
this.commandService.executeCommand(OutputCommands.SHOW.id, { name, options });
}

$close(channelName: string): PromiseLike<void> {
const outputChannel = this.getChannel(channelName);
if (outputChannel) {
outputChannel.setVisibility(false);
}
const channels = this.outputChannelManager.getChannels();
const isEmpty = channels.findIndex((channel: OutputChannel) => channel.isVisible) === -1;
if (isEmpty && this.commonOutputWidget) {
this.commonOutputWidget.close();
}

$close(name: string): PromiseLike<void> {
this.commandService.executeCommand(OutputCommands.HIDE.id, { name });
return Promise.resolve();
}

private getChannel(channelName: string): OutputChannel | undefined {
let outputChannel: OutputChannel | undefined;
if (this.channels.has(channelName)) {
outputChannel = this.channels.get(channelName);
} else {
outputChannel = this.outputChannelManager.getChannel(channelName);
this.channels.set(channelName, outputChannel);
}

return outputChannel;
}
}

0 comments on commit 525b4e6

Please sign in to comment.