From c9fa87ed3db9213f6e20228e2070c00cbb8001fd Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 5 Sep 2018 19:58:23 +0200 Subject: [PATCH] Make open log file action independent of schema --- .../workbench/parts/output/browser/logViewer.ts | 8 ++++---- .../parts/output/browser/outputActions.ts | 11 +++++------ .../electron-browser/output.contribution.ts | 9 ++++----- .../output/electron-browser/outputServices.ts | 15 +++++++++------ 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/parts/output/browser/logViewer.ts b/src/vs/workbench/parts/output/browser/logViewer.ts index dcd23b9abd9..12786761194 100644 --- a/src/vs/workbench/parts/output/browser/logViewer.ts +++ b/src/vs/workbench/parts/output/browser/logViewer.ts @@ -17,7 +17,7 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn import { URI } from 'vs/base/common/uri'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { IHashService } from 'vs/workbench/services/hash/common/hashService'; -import { LOG_SCHEME } from 'vs/workbench/parts/output/common/output'; +import { LOG_SCHEME, IOutputChannelDescriptor } from 'vs/workbench/parts/output/common/output'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IWindowService } from 'vs/platform/windows/common/windows'; @@ -26,11 +26,11 @@ export class LogViewerInput extends ResourceEditorInput { public static readonly ID = 'workbench.editorinputs.output'; - constructor(private file: URI, + constructor(private outputChannelDescriptor: IOutputChannelDescriptor, @ITextModelService textModelResolverService: ITextModelService, @IHashService hashService: IHashService ) { - super(paths.basename(file.fsPath), paths.dirname(file.fsPath), file.with({ scheme: LOG_SCHEME }), textModelResolverService, hashService); + super(paths.basename(outputChannelDescriptor.file.path), paths.dirname(outputChannelDescriptor.file.path), URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }), textModelResolverService, hashService); } public getTypeId(): string { @@ -38,7 +38,7 @@ export class LogViewerInput extends ResourceEditorInput { } public getResource(): URI { - return this.file; + return this.outputChannelDescriptor.file; } } diff --git a/src/vs/workbench/parts/output/browser/outputActions.ts b/src/vs/workbench/parts/output/browser/outputActions.ts index ed4d811c127..83962bbf42f 100644 --- a/src/vs/workbench/parts/output/browser/outputActions.ts +++ b/src/vs/workbench/parts/output/browser/outputActions.ts @@ -20,7 +20,6 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView import { Registry } from 'vs/platform/registry/common/platform'; import { groupBy } from 'vs/base/common/arrays'; import { ICommandService } from 'vs/platform/commands/common/commands'; -import { URI } from 'vs/base/common/uri'; export class ToggleOutputAction extends TogglePanelAction { @@ -180,16 +179,16 @@ export class OpenLogOutputFile extends Action { } private update(): void { - this.enabled = !!this.getLogFile(); + const outputChannelDescriptor = this.getOutputChannelDescriptor(); + this.enabled = outputChannelDescriptor && outputChannelDescriptor.file && outputChannelDescriptor.log; } public run(): TPromise { - return this.commandService.executeCommand(COMMAND_OPEN_LOG_VIEWER, this.getLogFile()); + return this.enabled ? this.commandService.executeCommand(COMMAND_OPEN_LOG_VIEWER, this.getOutputChannelDescriptor()) : TPromise.as(null); } - private getLogFile(): URI { + private getOutputChannelDescriptor(): IOutputChannelDescriptor { const channel = this.outputService.getActiveChannel(); - const descriptor = channel ? this.outputService.getChannelDescriptors().filter(c => c.id === channel.id)[0] : null; - return descriptor && descriptor.log ? descriptor.file : null; + return channel ? this.outputService.getChannelDescriptors().filter(c => c.id === channel.id)[0] : null; } } diff --git a/src/vs/workbench/parts/output/electron-browser/output.contribution.ts b/src/vs/workbench/parts/output/electron-browser/output.contribution.ts index e17246c2ead..1bd64595efe 100644 --- a/src/vs/workbench/parts/output/electron-browser/output.contribution.ts +++ b/src/vs/workbench/parts/output/electron-browser/output.contribution.ts @@ -13,7 +13,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; import { OutputService, LogContentProvider } from 'vs/workbench/parts/output/electron-browser/outputServices'; import { ToggleOutputAction, ClearOutputAction, OpenLogOutputFile } from 'vs/workbench/parts/output/browser/outputActions'; -import { OUTPUT_MODE_ID, OUTPUT_MIME, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT, LOG_SCHEME, COMMAND_OPEN_LOG_VIEWER, LOG_MODE_ID, LOG_MIME, CONTEXT_ACTIVE_LOG_OUTPUT } from 'vs/workbench/parts/output/common/output'; +import { OUTPUT_MODE_ID, OUTPUT_MIME, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT, LOG_SCHEME, COMMAND_OPEN_LOG_VIEWER, LOG_MODE_ID, LOG_MIME, CONTEXT_ACTIVE_LOG_OUTPUT, IOutputChannelDescriptor } from 'vs/workbench/parts/output/common/output'; import { PanelRegistry, Extensions, PanelDescriptor } from 'vs/workbench/browser/panel'; import { CommandsRegistry, ICommandHandler } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; @@ -25,7 +25,6 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWo import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; -import { URI } from 'vs/base/common/uri'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; // Register Service @@ -180,10 +179,10 @@ registerAction({ } }); -CommandsRegistry.registerCommand(COMMAND_OPEN_LOG_VIEWER, function (accessor: ServicesAccessor, file: URI) { - if (file) { +CommandsRegistry.registerCommand(COMMAND_OPEN_LOG_VIEWER, function (accessor: ServicesAccessor, outputChannelDescriptor: IOutputChannelDescriptor) { + if (outputChannelDescriptor && outputChannelDescriptor.file) { const editorService = accessor.get(IEditorService); - return editorService.openEditor(accessor.get(IInstantiationService).createInstance(LogViewerInput, file)); + return editorService.openEditor(accessor.get(IInstantiationService).createInstance(LogViewerInput, outputChannelDescriptor)); } return null; }); diff --git a/src/vs/workbench/parts/output/electron-browser/outputServices.ts b/src/vs/workbench/parts/output/electron-browser/outputServices.ts index 102597ed546..f6b6437b08b 100644 --- a/src/vs/workbench/parts/output/electron-browser/outputServices.ts +++ b/src/vs/workbench/parts/output/electron-browser/outputServices.ts @@ -34,7 +34,6 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { toLocalISOString } from 'vs/base/common/date'; import { IWindowService } from 'vs/platform/windows/common/windows'; import { ILogService } from 'vs/platform/log/common/log'; -import { Schemas } from 'vs/base/common/network'; import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { CancellationToken } from 'vs/base/common/cancellation'; @@ -591,6 +590,7 @@ export class LogContentProvider { private channels: Map = new Map(); constructor( + @IOutputService private outputService: IOutputService, @IInstantiationService private instantiationService: IInstantiationService ) { } @@ -606,13 +606,16 @@ export class LogContentProvider { } private getChannel(resource: URI): OutputChannel { - const id = resource.path; - let channel = this.channels.get(id); + const channelId = resource.path; + let channel = this.channels.get(channelId); if (!channel) { const channelDisposables: IDisposable[] = []; - channel = this.instantiationService.createInstance(FileOutputChannel, { id, label: '', file: resource.with({ scheme: Schemas.file }), log: true }, resource); - channel.onDispose(() => dispose(channelDisposables), channelDisposables); - this.channels.set(id, channel); + const outputChannelDescriptor = this.outputService.getChannelDescriptors().filter(({ id }) => id === channelId)[0]; + if (outputChannelDescriptor && outputChannelDescriptor.file) { + channel = this.instantiationService.createInstance(FileOutputChannel, outputChannelDescriptor, resource); + channel.onDispose(() => dispose(channelDisposables), channelDisposables); + this.channels.set(channelId, channel); + } } return channel; } -- GitLab