3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { createDecorator , IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
6
+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
7
7
import * as resources from 'vs/base/common/resources' ;
8
8
import { ITextModel } from 'vs/editor/common/model' ;
9
9
import { Emitter , Event } from 'vs/base/common/event' ;
@@ -28,39 +28,6 @@ export interface IOutputChannelModel extends IDisposable {
28
28
clear ( till ?: number ) : void ;
29
29
}
30
30
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
-
64
31
export abstract class AbstractFileOutputChannelModel extends Disposable implements IOutputChannelModel {
65
32
66
33
protected readonly _onDidAppendedContent = this . _register ( new Emitter < void > ( ) ) ;
@@ -117,7 +84,7 @@ export abstract class AbstractFileOutputChannelModel extends Disposable implemen
117
84
return this . model ;
118
85
}
119
86
120
- appendToModel ( content : string ) : void {
87
+ protected appendToModel ( content : string ) : void {
121
88
if ( this . model && content ) {
122
89
const lastLine = this . model . getLineCount ( ) ;
123
90
const lastLineMaxColumn = this . model . getLineMaxColumn ( lastLine ) ;
@@ -197,7 +164,7 @@ class OutputFileListener extends Disposable {
197
164
/**
198
165
* An output channel driven by a file and does not support appending messages.
199
166
*/
200
- class FileOutputChannelModel extends AbstractFileOutputChannelModel implements IOutputChannelModel {
167
+ export class FileOutputChannelModel extends AbstractFileOutputChannelModel implements IOutputChannelModel {
201
168
202
169
private readonly fileHandler : OutputFileListener ;
203
170
@@ -359,44 +326,38 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
359
326
this . appendedMessage = '' ;
360
327
}
361
328
362
- loadModel ( ) : Promise < ITextModel > {
329
+ async loadModel ( ) : Promise < ITextModel > {
363
330
this . loadingFromFileInProgress = true ;
364
331
if ( this . modelUpdater . isScheduled ( ) ) {
365
332
this . modelUpdater . cancel ( ) ;
366
333
}
367
334
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 ) ;
386
348
}
387
349
388
- private resetModel ( ) : Promise < void > {
350
+ private async resetModel ( ) : Promise < void > {
389
351
this . startOffset = 0 ;
390
352
this . endOffset = 0 ;
391
353
if ( this . model ) {
392
- return this . loadModel ( ) . then ( ( ) => undefined ) ;
354
+ await this . loadModel ( ) ;
393
355
}
394
- return Promise . resolve ( undefined ) ;
395
356
}
396
357
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 ( ) ;
400
361
}
401
362
402
363
protected override updateModel ( ) : void {
@@ -415,7 +376,7 @@ class OutputChannelBackedByFile extends AbstractFileOutputChannelModel implement
415
376
}
416
377
}
417
378
418
- class DelegatedOutputChannelModel extends Disposable implements IOutputChannelModel {
379
+ export class DelegatedOutputChannelModel extends Disposable implements IOutputChannelModel {
419
380
420
381
private readonly _onDidAppendedContent : Emitter < void > = this . _register ( new Emitter < void > ( ) ) ;
421
382
readonly onDidAppendedContent : Event < void > = this . _onDidAppendedContent . event ;
0 commit comments