This commit is contained in:
Sandeep Somavarapu
2023-09-04 14:57:47 +02:00
committed by GitHub
parent b481d52f17
commit 976b2d6532

View File

@@ -11,7 +11,7 @@ import { SetLogLevelAction } from 'vs/workbench/contrib/logs/common/logsActions'
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IFileService, whenProviderRegistered } from 'vs/platform/files/common/files'; import { IFileService, whenProviderRegistered } from 'vs/platform/files/common/files';
import { IOutputChannelRegistry, IOutputService, Extensions } from 'vs/workbench/services/output/common/output'; import { IOutputChannelRegistry, IOutputService, Extensions } from 'vs/workbench/services/output/common/output';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { Disposable, DisposableMap, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { CONTEXT_LOG_LEVEL, ILogService, ILoggerResource, ILoggerService, LogLevel, LogLevelToString, isLogLevel } from 'vs/platform/log/common/log'; import { CONTEXT_LOG_LEVEL, ILogService, ILoggerResource, ILoggerService, LogLevel, LogLevelToString, isLogLevel } from 'vs/platform/log/common/log';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
@@ -58,6 +58,7 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
private readonly contextKeys = new CounterSet<string>(); private readonly contextKeys = new CounterSet<string>();
private readonly outputChannelRegistry = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels); private readonly outputChannelRegistry = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels);
private readonly loggerDisposables = this._register(new DisposableMap());
constructor( constructor(
@ILogService private readonly logService: ILogService, @ILogService private readonly logService: ILogService,
@@ -86,7 +87,7 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
if (visibility) { if (visibility) {
this.registerLogChannel(logger); this.registerLogChannel(logger);
} else { } else {
this.outputChannelRegistry.removeChannel(logger.id); this.deregisterLogChannel(logger);
} }
} }
})); }));
@@ -120,7 +121,7 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
if (this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(logger.when))) { if (this.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(logger.when))) {
this.registerLogChannel(logger); this.registerLogChannel(logger);
} else { } else {
this.outputChannelRegistry.removeChannel(logger.id); this.deregisterLogChannel(logger);
} }
} }
} }
@@ -136,7 +137,7 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
} }
} }
} }
this.outputChannelRegistry.removeChannel(logger.id); this.deregisterLogChannel(logger);
} }
} }
@@ -145,27 +146,36 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
if (channel && this.uriIdentityService.extUri.isEqual(channel.file, logger.resource)) { if (channel && this.uriIdentityService.extUri.isEqual(channel.file, logger.resource)) {
return; return;
} }
const disposables = new DisposableStore();
const promise = createCancelablePromise(async token => { const promise = createCancelablePromise(async token => {
await whenProviderRegistered(logger.resource, this.fileService); await whenProviderRegistered(logger.resource, this.fileService);
try { try {
await this.whenFileExists(logger.resource, 1, token); await this.whenFileExists(logger.resource, 1, token);
const channel = this.outputChannelRegistry.getChannel(logger.id); const existingChannel = this.outputChannelRegistry.getChannel(logger.id);
if (channel?.file?.scheme === Schemas.vscodeRemote) { const remoteLogger = existingChannel?.file?.scheme === Schemas.vscodeRemote ? this.loggerService.getRegisteredLogger(existingChannel.file) : undefined;
// Re-register the channel with new id and name if (remoteLogger) {
this.outputChannelRegistry.removeChannel(channel.id); this.deregisterLogChannel(remoteLogger);
this.outputChannelRegistry.registerChannel({ id: `${channel.id}.remote`, label: nls.localize('remote name', "{0} (Remote)", channel.label), file: channel.file, log: channel.log, extensionId: channel.extensionId });
} }
const hasToAppendRemote = channel && logger.resource.scheme === Schemas.vscodeRemote; const hasToAppendRemote = existingChannel && logger.resource.scheme === Schemas.vscodeRemote;
const id = hasToAppendRemote ? `${logger.id}.remote` : logger.id; const id = hasToAppendRemote ? `${logger.id}.remote` : logger.id;
const label = hasToAppendRemote ? nls.localize('remote name', "{0} (Remote)", logger.name ?? logger.id) : logger.name ?? logger.id; const label = hasToAppendRemote ? nls.localize('remote name', "{0} (Remote)", logger.name ?? logger.id) : logger.name ?? logger.id;
this.outputChannelRegistry.registerChannel({ id, label, file: logger.resource, log: true, extensionId: logger.extensionId }); this.outputChannelRegistry.registerChannel({ id, label, file: logger.resource, log: true, extensionId: logger.extensionId });
disposables.add(toDisposable(() => this.outputChannelRegistry.removeChannel(id)));
if (remoteLogger) {
this.registerLogChannel(remoteLogger);
}
} catch (error) { } catch (error) {
if (!isCancellationError(error)) { if (!isCancellationError(error)) {
this.logService.error('Error while registering log channel', logger.resource.toString(), getErrorMessage(error)); this.logService.error('Error while registering log channel', logger.resource.toString(), getErrorMessage(error));
} }
} }
}); });
this._register(toDisposable(() => promise.cancel())); disposables.add(toDisposable(() => promise.cancel()));
this.loggerDisposables.set(logger.resource.toString(), disposables);
}
private deregisterLogChannel(logger: ILoggerResource): void {
this.loggerDisposables.deleteAndDispose(logger.resource.toString());
} }
private async whenFileExists(file: URI, trial: number, token: CancellationToken): Promise<void> { private async whenFileExists(file: URI, trial: number, token: CancellationToken): Promise<void> {