Skip to content

Commit e9795f4

Browse files
author
Benjamin Pasero
committed
output - use fileservice for watching
1 parent 1ddbe37 commit e9795f4

1 file changed

Lines changed: 12 additions & 35 deletions

File tree

src/vs/workbench/services/output/node/outputChannelModelService.ts

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
7-
import { watchFolder } from 'vs/base/node/watcher';
8-
import { dirname, join } from 'vs/base/common/path';
7+
import { join } from 'vs/base/common/path';
98
import * as resources from 'vs/base/common/resources';
109
import { ITextModel } from 'vs/editor/common/model';
1110
import { URI } from 'vs/base/common/uri';
1211
import { ThrottledDelayer } from 'vs/base/common/async';
1312
import { IFileService } from 'vs/platform/files/common/files';
1413
import { IModelService } from 'vs/editor/common/services/modelService';
1514
import { IModeService } from 'vs/editor/common/services/modeService';
16-
import { toDisposable, IDisposable, Disposable } from 'vs/base/common/lifecycle';
15+
import { Disposable } from 'vs/base/common/lifecycle';
1716
import { ILogService } from 'vs/platform/log/common/log';
1817
import { IOutputChannelModel, AbstractFileOutputChannelModel, IOutputChannelModelService, AsbtractOutputChannelModelService, BufferredOutputChannel } from 'vs/workbench/services/output/common/outputChannelModel';
1918
import { OutputAppender } from 'vs/workbench/services/output/node/outputAppender';
@@ -24,34 +23,13 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2423
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
2524
import { Emitter, Event } from 'vs/base/common/event';
2625

27-
let watchingOutputDir = false;
28-
let callbacks: ((eventType: 'added' | 'changed' | 'deleted', path: string) => void)[] = [];
29-
function watchOutputDirectory(outputDir: string, logService: ILogService, onChange: (eventType: 'added' | 'changed' | 'deleted', path: string) => void): IDisposable {
30-
callbacks.push(onChange);
31-
if (!watchingOutputDir) {
32-
const watcherDisposable = watchFolder(outputDir, (eventType, path) => {
33-
for (const callback of callbacks) {
34-
callback(eventType, path);
35-
}
36-
}, (error: string) => {
37-
logService.error(error);
38-
});
39-
watchingOutputDir = true;
40-
return toDisposable(() => {
41-
callbacks = [];
42-
watcherDisposable.dispose();
43-
});
44-
}
45-
return toDisposable(() => { });
46-
}
47-
4826
class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implements IOutputChannelModel {
4927

5028
private appender: OutputAppender;
5129
private appendedMessage: string;
5230
private loadingFromFileInProgress: boolean;
5331
private resettingDelayer: ThrottledDelayer<void>;
54-
private readonly rotatingFilePath: string;
32+
private readonly rotatingFilePath: URI;
5533

5634
constructor(
5735
id: string,
@@ -70,9 +48,15 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
7048
// Use one rotating file to check for main file reset
7149
this.appender = new OutputAppender(id, this.file.fsPath);
7250

73-
const rotatingFilePathDirectory = dirname(this.file.fsPath);
74-
this.rotatingFilePath = join(rotatingFilePathDirectory, `${id}.1.log`);
75-
this._register(watchOutputDirectory(rotatingFilePathDirectory, logService, (eventType, path) => this.onFileChangedInOutputDirectory(eventType, path)));
51+
const rotatingFilePathDirectory = resources.dirname(this.file);
52+
this.rotatingFilePath = resources.joinPath(rotatingFilePathDirectory, `${id}.1.log`);
53+
54+
this._register(fileService.watch(rotatingFilePathDirectory));
55+
this._register(fileService.onFileChanges(e => {
56+
if (e.contains(this.rotatingFilePath)) {
57+
this.resettingDelayer.trigger(() => this.resetModel());
58+
}
59+
}));
7660

7761
this.resettingDelayer = new ThrottledDelayer<void>(50);
7862
}
@@ -145,13 +129,6 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
145129
}
146130
}
147131

148-
private onFileChangedInOutputDirectory(eventType: 'added' | 'changed' | 'deleted', path: string): void {
149-
// Check if rotating file has changed. It changes only when the main file exceeds its limit.
150-
if (this.rotatingFilePath === path) {
151-
this.resettingDelayer.trigger(() => this.resetModel());
152-
}
153-
}
154-
155132
private write(content: string): void {
156133
this.appender.append(content);
157134
}

0 commit comments

Comments
 (0)