diff --git a/src/vs/workbench/contrib/logs/common/logs.contribution.ts b/src/vs/workbench/contrib/logs/common/logs.contribution.ts index 11c7aa061f2..90fae135d50 100644 --- a/src/vs/workbench/contrib/logs/common/logs.contribution.ts +++ b/src/vs/workbench/contrib/logs/common/logs.contribution.ts @@ -12,15 +12,12 @@ import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as import { IFileService, whenProviderRegistered } from '../../../../platform/files/common/files.js'; import { IOutputChannelRegistry, IOutputService, Extensions } from '../../../services/output/common/output.js'; import { Disposable, DisposableMap, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js'; -import { CONTEXT_LOG_LEVEL, ILogService, ILoggerResource, ILoggerService, LogLevel, LogLevelToString, isLogLevel } from '../../../../platform/log/common/log.js'; +import { CONTEXT_LOG_LEVEL, ILoggerResource, ILoggerService, LogLevel, LogLevelToString, isLogLevel } from '../../../../platform/log/common/log.js'; import { LifecyclePhase } from '../../../services/lifecycle/common/lifecycle.js'; import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js'; -import { URI } from '../../../../base/common/uri.js'; import { Event } from '../../../../base/common/event.js'; import { windowLogId, showWindowLogActionId } from '../../../services/log/common/logConstants.js'; -import { createCancelablePromise, timeout } from '../../../../base/common/async.js'; -import { CancellationError, getErrorMessage, isCancellationError } from '../../../../base/common/errors.js'; -import { CancellationToken } from '../../../../base/common/cancellation.js'; +import { createCancelablePromise } from '../../../../base/common/async.js'; import { IDefaultLogLevelsService } from './defaultLogLevels.js'; import { ContextKeyExpr, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js'; import { CounterSet } from '../../../../base/common/map.js'; @@ -61,7 +58,6 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution { private readonly loggerDisposables = this._register(new DisposableMap()); constructor( - @ILogService private readonly logService: ILogService, @ILoggerService private readonly loggerService: ILoggerService, @IContextKeyService private readonly contextKeyService: IContextKeyService, @IFileService private readonly fileService: IFileService, @@ -149,25 +145,21 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution { const disposables = new DisposableStore(); const promise = createCancelablePromise(async token => { await whenProviderRegistered(logger.resource, this.fileService); - try { - await this.whenFileExists(logger.resource, 1, token); - const existingChannel = this.outputChannelRegistry.getChannel(logger.id); - const remoteLogger = existingChannel?.files?.[0].scheme === Schemas.vscodeRemote ? this.loggerService.getRegisteredLogger(existingChannel.files[0]) : undefined; - if (remoteLogger) { - this.deregisterLogChannel(remoteLogger); - } - const hasToAppendRemote = existingChannel && logger.resource.scheme === Schemas.vscodeRemote; - 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; - this.outputChannelRegistry.registerChannel({ id, label, files: [logger.resource], log: true, extensionId: logger.extensionId }); - disposables.add(toDisposable(() => this.outputChannelRegistry.removeChannel(id))); - if (remoteLogger) { - this.registerLogChannel(remoteLogger); - } - } catch (error) { - if (!isCancellationError(error)) { - this.logService.error('Error while registering log channel', logger.resource.toString(), getErrorMessage(error)); - } + if (token.isCancellationRequested) { + return; + } + const existingChannel = this.outputChannelRegistry.getChannel(logger.id); + const remoteLogger = existingChannel?.files?.[0].scheme === Schemas.vscodeRemote ? this.loggerService.getRegisteredLogger(existingChannel.files[0]) : undefined; + if (remoteLogger) { + this.deregisterLogChannel(remoteLogger); + } + const hasToAppendRemote = existingChannel && logger.resource.scheme === Schemas.vscodeRemote; + 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; + this.outputChannelRegistry.registerChannel({ id, label, files: [logger.resource], log: true, extensionId: logger.extensionId }); + disposables.add(toDisposable(() => this.outputChannelRegistry.removeChannel(id))); + if (remoteLogger) { + this.registerLogChannel(remoteLogger); } }); disposables.add(toDisposable(() => promise.cancel())); @@ -178,22 +170,6 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution { this.loggerDisposables.deleteAndDispose(logger.resource.toString()); } - private async whenFileExists(file: URI, trial: number, token: CancellationToken): Promise { - const exists = await this.fileService.exists(file); - if (exists) { - return; - } - if (token.isCancellationRequested) { - throw new CancellationError(); - } - if (trial > 10) { - throw new Error(`Timed out while waiting for file to be created`); - } - this.logService.debug(`[Registering Log Channel] File does not exist. Waiting for 1s to retry.`, file.toString()); - await timeout(1000, token); - await this.whenFileExists(file, trial + 1, token); - } - private registerShowWindowLogAction(): void { this._register(registerAction2(class ShowWindowLogAction extends Action2 { constructor() {