Skip to content

Commit cdc1920

Browse files
authored
introduce immediate update (microsoft#154082)
1 parent 62ab77f commit cdc1920

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OutputChannel extends Disposable implements IOutputChannel {
4848
}
4949

5050
update(mode: OutputChannelUpdateMode, till?: number): void {
51-
this.model.update(mode, till);
51+
this.model.update(mode, till, true);
5252
}
5353

5454
clear(): void {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { OutputChannelUpdateMode } from 'vs/workbench/services/output/common/out
2626
export interface IOutputChannelModel extends IDisposable {
2727
readonly onDispose: Event<void>;
2828
append(output: string): void;
29-
update(mode: OutputChannelUpdateMode, till?: number): void;
29+
update(mode: OutputChannelUpdateMode, till: number | undefined, immediate: boolean): void;
3030
loadModel(): Promise<ITextModel>;
3131
clear(): void;
3232
replace(value: string): void;
@@ -129,12 +129,12 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
129129
}
130130

131131
clear(): void {
132-
this.update(OutputChannelUpdateMode.Clear, this.endOffset);
132+
this.update(OutputChannelUpdateMode.Clear, this.endOffset, true);
133133
}
134134

135-
update(mode: OutputChannelUpdateMode, till?: number): void {
135+
update(mode: OutputChannelUpdateMode, till: number | undefined, immediate: boolean): void {
136136
const loadModelPromise: Promise<any> = this.loadModelPromise ? this.loadModelPromise : Promise.resolve();
137-
loadModelPromise.then(() => this.doUpdate(mode, till));
137+
loadModelPromise.then(() => this.doUpdate(mode, till, immediate));
138138
}
139139

140140
loadModel(): Promise<ITextModel> {
@@ -174,7 +174,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
174174
return this.model;
175175
}
176176

177-
private doUpdate(mode: OutputChannelUpdateMode, till?: number): void {
177+
private doUpdate(mode: OutputChannelUpdateMode, till: number | undefined, immediate: boolean): void {
178178
if (mode === OutputChannelUpdateMode.Clear || mode === OutputChannelUpdateMode.Replace) {
179179
this.startOffset = this.endOffset = isNumber(till) ? till : this.endOffset;
180180
this.cancelModelUpdate();
@@ -198,15 +198,15 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
198198
}
199199

200200
else {
201-
this.appendContent(this.model, token);
201+
this.appendContent(this.model, immediate, token);
202202
}
203203
}
204204

205205
private clearContent(model: ITextModel): void {
206206
this.doUpdateModel(model, [EditOperation.delete(model.getFullModelRange())], VSBuffer.fromString(''));
207207
}
208208

209-
private async appendContent(model: ITextModel, token: CancellationToken): Promise<void> {
209+
private async appendContent(model: ITextModel, immediate: boolean, token: CancellationToken): Promise<void> {
210210
this.appendThrottler.trigger(async () => {
211211
/* Abort if operation is cancelled */
212212
if (token.isCancellationRequested) {
@@ -234,7 +234,7 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
234234
const lastLineMaxColumn = model.getLineMaxColumn(lastLine);
235235
const edits = [EditOperation.insert(new Position(lastLine, lastLineMaxColumn), contentToAppend.toString())];
236236
this.doUpdateModel(model, edits, contentToAppend);
237-
});
237+
}, immediate ? 0 : undefined);
238238
}
239239

240240
private async replaceContent(model: ITextModel, token: CancellationToken): Promise<void> {
@@ -298,10 +298,10 @@ export class FileOutputChannelModel extends Disposable implements IOutputChannel
298298
if (!this.modelUpdateInProgress) {
299299
if (isNumber(size) && this.endOffset > size) {
300300
// Reset - Content is removed
301-
this.update(OutputChannelUpdateMode.Clear, 0);
301+
this.update(OutputChannelUpdateMode.Clear, 0, true);
302302
}
303303
}
304-
this.update(OutputChannelUpdateMode.Append);
304+
this.update(OutputChannelUpdateMode.Append, undefined, false /* Not needed to update immediately. Wait to collect more changes and update. */);
305305
}
306306
}
307307

@@ -340,13 +340,13 @@ class OutputChannelBackedByFile extends FileOutputChannelModel implements IOutpu
340340

341341
override append(message: string): void {
342342
this.write(message);
343-
this.update(OutputChannelUpdateMode.Append);
343+
this.update(OutputChannelUpdateMode.Append, undefined, this.isVisible());
344344
}
345345

346346
override replace(message: string): void {
347347
const till = this._offset;
348348
this.write(message);
349-
this.update(OutputChannelUpdateMode.Replace, till);
349+
this.update(OutputChannelUpdateMode.Replace, till, true);
350350
}
351351

352352
private write(content: string): void {
@@ -391,8 +391,8 @@ export class DelegatedOutputChannelModel extends Disposable implements IOutputCh
391391
this.outputChannelModel.then(outputChannelModel => outputChannelModel.append(output));
392392
}
393393

394-
update(mode: OutputChannelUpdateMode, till?: number): void {
395-
this.outputChannelModel.then(outputChannelModel => outputChannelModel.update(mode, till));
394+
update(mode: OutputChannelUpdateMode, till: number | undefined, immediate: boolean): void {
395+
this.outputChannelModel.then(outputChannelModel => outputChannelModel.update(mode, till, immediate));
396396
}
397397

398398
loadModel(): Promise<ITextModel> {

0 commit comments

Comments
 (0)