Skip to content

Commit fb72274

Browse files
committed
clean up
1 parent 47b332e commit fb72274

File tree

4 files changed

+62
-66
lines changed

4 files changed

+62
-66
lines changed

src/vs/workbench/contrib/output/browser/outputServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import { ITextModelService, ITextModelContentProvider } from 'vs/editor/common/s
1616
import { ITextModel } from 'vs/editor/common/model';
1717
import { ILogService } from 'vs/platform/log/common/log';
1818
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
19-
import { IOutputChannelModel, IOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModel';
19+
import { IOutputChannelModel } from 'vs/workbench/contrib/output/common/outputChannelModel';
2020
import { IViewsService } from 'vs/workbench/common/views';
2121
import { OutputViewPane } from 'vs/workbench/contrib/output/browser/outputView';
22+
import { IOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModelService';
2223

2324
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
2425

src/vs/workbench/contrib/output/common/outputChannelModel.ts

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
6+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
77
import * as resources from 'vs/base/common/resources';
88
import { ITextModel } from 'vs/editor/common/model';
99
import { Emitter, Event } from 'vs/base/common/event';
@@ -28,39 +28,6 @@ export interface IOutputChannelModel extends IDisposable {
2828
clear(till?: number): void;
2929
}
3030

31-
export const IOutputChannelModelService = createDecorator<IOutputChannelModelService>('outputChannelModelService');
32-
33-
export interface IOutputChannelModelService {
34-
readonly _serviceBrand: undefined;
35-
36-
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel;
37-
38-
}
39-
40-
export abstract class AbstractOutputChannelModelService {
41-
42-
declare readonly _serviceBrand: undefined;
43-
44-
constructor(
45-
private readonly outputLocation: URI,
46-
@IFileService protected readonly fileService: IFileService,
47-
@IInstantiationService protected readonly instantiationService: IInstantiationService
48-
) { }
49-
50-
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel {
51-
return file ? this.instantiationService.createInstance(FileOutputChannelModel, modelUri, mimeType, file) : this.instantiationService.createInstance(DelegatedOutputChannelModel, id, modelUri, mimeType, this.outputDir);
52-
}
53-
54-
private _outputDir: Promise<URI> | null = null;
55-
private get outputDir(): Promise<URI> {
56-
if (!this._outputDir) {
57-
this._outputDir = this.fileService.createFolder(this.outputLocation).then(() => this.outputLocation);
58-
}
59-
return this._outputDir;
60-
}
61-
62-
}
63-
6431
export abstract class AbstractFileOutputChannelModel extends Disposable implements IOutputChannelModel {
6532

6633
protected readonly _onDidAppendedContent = this._register(new Emitter<void>());
@@ -117,7 +84,7 @@ export abstract class AbstractFileOutputChannelModel extends Disposable implemen
11784
return this.model;
11885
}
11986

120-
appendToModel(content: string): void {
87+
protected appendToModel(content: string): void {
12188
if (this.model && content) {
12289
const lastLine = this.model.getLineCount();
12390
const lastLineMaxColumn = this.model.getLineMaxColumn(lastLine);
@@ -197,7 +164,7 @@ class OutputFileListener extends Disposable {
197164
/**
198165
* An output channel driven by a file and does not support appending messages.
199166
*/
200-
class FileOutputChannelModel extends AbstractFileOutputChannelModel implements IOutputChannelModel {
167+
export class FileOutputChannelModel extends AbstractFileOutputChannelModel implements IOutputChannelModel {
201168

202169
private readonly fileHandler: OutputFileListener;
203170

@@ -359,44 +326,38 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
359326
this.appendedMessage = '';
360327
}
361328

362-
loadModel(): Promise<ITextModel> {
329+
async loadModel(): Promise<ITextModel> {
363330
this.loadingFromFileInProgress = true;
364331
if (this.modelUpdater.isScheduled()) {
365332
this.modelUpdater.cancel();
366333
}
367334
this.appendedMessage = '';
368-
return this.loadFile()
369-
.then(content => {
370-
if (this.endOffset !== this.startOffset + VSBuffer.fromString(content).byteLength) {
371-
// Queue content is not written into the file
372-
// Flush it and load file again
373-
this.flush();
374-
return this.loadFile();
375-
}
376-
return content;
377-
})
378-
.then(content => {
379-
if (this.appendedMessage) {
380-
this.write(this.appendedMessage);
381-
this.appendedMessage = '';
382-
}
383-
this.loadingFromFileInProgress = false;
384-
return this.createModel(content);
385-
});
335+
let content = await this.loadFile();
336+
if (this.endOffset !== this.startOffset + VSBuffer.fromString(content).byteLength) {
337+
// Queue content is not written into the file
338+
// Flush it and load file again
339+
this.flush();
340+
content = await this.loadFile();
341+
}
342+
if (this.appendedMessage) {
343+
this.write(this.appendedMessage);
344+
this.appendedMessage = '';
345+
}
346+
this.loadingFromFileInProgress = false;
347+
return this.createModel(content);
386348
}
387349

388-
private resetModel(): Promise<void> {
350+
private async resetModel(): Promise<void> {
389351
this.startOffset = 0;
390352
this.endOffset = 0;
391353
if (this.model) {
392-
return this.loadModel().then(() => undefined);
354+
await this.loadModel();
393355
}
394-
return Promise.resolve(undefined);
395356
}
396357

397-
private loadFile(): Promise<string> {
398-
return this.fileService.readFile(this.file, { position: this.startOffset })
399-
.then(content => this.appendedMessage ? content.value + this.appendedMessage : content.value.toString());
358+
private async loadFile(): Promise<string> {
359+
const content = await this.fileService.readFile(this.file, { position: this.startOffset });
360+
return this.appendedMessage ? content.value + this.appendedMessage : content.value.toString();
400361
}
401362

402363
protected override updateModel(): void {
@@ -415,7 +376,7 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
415376
}
416377
}
417378

418-
class DelegatedOutputChannelModel extends Disposable implements IOutputChannelModel {
379+
export class DelegatedOutputChannelModel extends Disposable implements IOutputChannelModel {
419380

420381
private readonly _onDidAppendedContent: Emitter<void> = this._register(new Emitter<void>());
421382
readonly onDidAppendedContent: Event<void> = this._onDidAppendedContent.event;

src/vs/workbench/contrib/output/common/outputChannelModelService.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,47 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IOutputChannelModelService, AbstractOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModel';
76
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
87
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
9-
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
8+
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
109
import { IFileService } from 'vs/platform/files/common/files';
1110
import { toLocalISOString } from 'vs/base/common/date';
1211
import { dirname, joinPath } from 'vs/base/common/resources';
12+
import { DelegatedOutputChannelModel, FileOutputChannelModel, IOutputChannelModel } from 'vs/workbench/contrib/output/common/outputChannelModel';
13+
import { URI } from 'vs/base/common/uri';
14+
15+
export const IOutputChannelModelService = createDecorator<IOutputChannelModelService>('outputChannelModelService');
16+
17+
export interface IOutputChannelModelService {
18+
readonly _serviceBrand: undefined;
19+
20+
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel;
21+
22+
}
23+
24+
export abstract class AbstractOutputChannelModelService {
25+
26+
declare readonly _serviceBrand: undefined;
27+
28+
constructor(
29+
private readonly outputLocation: URI,
30+
@IFileService protected readonly fileService: IFileService,
31+
@IInstantiationService protected readonly instantiationService: IInstantiationService
32+
) { }
33+
34+
createOutputChannelModel(id: string, modelUri: URI, mimeType: string, file?: URI): IOutputChannelModel {
35+
return file ? this.instantiationService.createInstance(FileOutputChannelModel, modelUri, mimeType, file) : this.instantiationService.createInstance(DelegatedOutputChannelModel, id, modelUri, mimeType, this.outputDir);
36+
}
37+
38+
private _outputDir: Promise<URI> | null = null;
39+
private get outputDir(): Promise<URI> {
40+
if (!this._outputDir) {
41+
this._outputDir = this.fileService.createFolder(this.outputLocation).then(() => this.outputLocation);
42+
}
43+
return this._outputDir;
44+
}
45+
46+
}
1347

1448
export class OutputChannelModelService extends AbstractOutputChannelModelService implements IOutputChannelModelService {
1549

src/vs/workbench/contrib/output/electron-sandbox/outputChannelModelService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
77
import { join } from 'vs/base/common/path';
88
import { URI } from 'vs/base/common/uri';
99
import { IFileService } from 'vs/platform/files/common/files';
10-
import { IOutputChannelModelService, AbstractOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModel';
1110
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1211
import { toLocalISOString } from 'vs/base/common/date';
1312
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
1413
import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
14+
import { AbstractOutputChannelModelService, IOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModelService';
1515

1616
export class OutputChannelModelService extends AbstractOutputChannelModelService implements IOutputChannelModelService {
1717

0 commit comments

Comments
 (0)