diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 002d00267d2b1..b0be6807914b7 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -51,6 +51,7 @@ import { IOutputService } from 'vs/workbench/services/output/common/output'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { IPathService } from 'vs/workbench/services/path/common/pathService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IDisposable } from 'xterm'; interface ITerminalData { terminal: ITerminalInstance; @@ -838,8 +839,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { let terminal: ITerminalInstance | undefined = undefined; let error: TaskError | undefined = undefined; let promise: Promise | undefined = undefined; - const problemMatchers = await this._resolveMatchers(resolver, task.configurationProperties.problemMatchers); - if (task.configurationProperties.isBackground && problemMatchers.length) { + if (task.configurationProperties.isBackground) { + const problemMatchers = await this._resolveMatchers(resolver, task.configurationProperties.problemMatchers); const watchingProblemMatcher = new WatchingProblemCollector(problemMatchers, this._markerService, this._modelService, this._fileService); if ((problemMatchers.length > 0) && !watchingProblemMatcher.isWatching()) { this._appendOutput(nls.localize('TerminalTaskSystem.nonWatchingMatcher', 'Task {0} is a background task but uses a problem matcher without a background pattern', task._label)); @@ -896,20 +897,25 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._logService.error('Task terminal process never got ready'); }); this._fireTaskEvent(TaskEvent.create(TaskEventKind.Start, task, terminal.instanceId, resolver.values)); - const onData = terminal.onLineData((line) => { - watchingProblemMatcher.processLine(line); - if (!delayer) { - delayer = new Async.Delayer(3000); - } - delayer.trigger(() => { - watchingProblemMatcher.forceDelivery(); - delayer = undefined; + let onData: IDisposable | undefined; + if (problemMatchers.length) { + // prevent https://github.com/microsoft/vscode/issues/174511 from happening + onData = terminal.onLineData((line) => { + watchingProblemMatcher.processLine(line); + if (!delayer) { + delayer = new Async.Delayer(3000); + } + delayer.trigger(() => { + watchingProblemMatcher.forceDelivery(); + delayer = undefined; + }); }); - }); + } + promise = new Promise((resolve, reject) => { const onExit = terminal!.onExit((terminalLaunchResult) => { const exitCode = typeof terminalLaunchResult === 'number' ? terminalLaunchResult : terminalLaunchResult?.code; - onData.dispose(); + onData?.dispose(); onExit.dispose(); const key = task.getMapKey(); if (this._busyTasks[mapKey]) {