Skip to content

Commit 2e776c0

Browse files
committed
Use ILogService in TaskQueue
1 parent 5741e45 commit 2e776c0

17 files changed

Lines changed: 77 additions & 50 deletions

addons/addon-webgl/src/CharAtlasCache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ITerminalOptions, Terminal } from '@xterm/xterm';
88
import { ITerminal, ReadonlyColorSet } from 'browser/Types';
99
import { ICharAtlasConfig, ITextureAtlas } from './Types';
1010
import { generateConfig, configEquals } from './CharAtlasUtils';
11+
import type { ILogService } from 'common/services/Services';
1112

1213
interface ITextureAtlasCacheEntry {
1314
atlas: ITextureAtlas;
@@ -67,8 +68,9 @@ export function acquireTextureAtlas(
6768
}
6869

6970
const core: ITerminal = (terminal as any)._core;
71+
const logService = (core as any)._logService as ILogService;
7072
const newEntry: ITextureAtlasCacheEntry = {
71-
atlas: new TextureAtlas(document, newConfig, core.unicodeService),
73+
atlas: new TextureAtlas(document, newConfig, core.unicodeService, logService),
7274
config: newConfig,
7375
ownedBy: [terminal]
7476
};

addons/addon-webgl/src/TextureAtlas.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IdleTaskQueue } from 'common/TaskQueue';
1414
import { IColor } from 'common/Types';
1515
import { AttributeData } from 'common/buffer/AttributeData';
1616
import { Attributes, DEFAULT_COLOR, DEFAULT_EXT, UnderlineStyle } from 'common/buffer/Constants';
17-
import { IUnicodeService } from 'common/services/Services';
17+
import { ILogService, IUnicodeService } from 'common/services/Services';
1818
import { Emitter } from 'common/Event';
1919

2020
/**
@@ -88,7 +88,8 @@ export class TextureAtlas implements ITextureAtlas {
8888
constructor(
8989
private readonly _document: Document,
9090
private readonly _config: ICharAtlasConfig,
91-
private readonly _unicodeService: IUnicodeService
91+
private readonly _unicodeService: IUnicodeService,
92+
private readonly _logService: ILogService
9293
) {
9394
this._createNewPage();
9495
this._tmpCanvas = createCanvas(
@@ -119,7 +120,7 @@ export class TextureAtlas implements ITextureAtlas {
119120

120121
private _doWarmUp(): void {
121122
// Pre-fill with ASCII 33-126, this is not urgent and done in idle callbacks
122-
const queue = new IdleTaskQueue();
123+
const queue = new IdleTaskQueue(this._logService);
123124
for (let i = 33; i < 126; i++) {
124125
queue.enqueue(() => {
125126
if (!this._cacheMap.get(i, DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_EXT)) {

src/browser/services/RenderService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IRenderDimensions, IRenderer } from 'browser/renderer/shared/Types';
99
import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
1010
import { Disposable, MutableDisposable, toDisposable } from 'common/Lifecycle';
1111
import { DebouncedIdleTask } from 'common/TaskQueue';
12-
import { IBufferService, ICoreService, IDecorationService, IOptionsService } from 'common/services/Services';
12+
import { IBufferService, ICoreService, IDecorationService, ILogService, IOptionsService } from 'common/services/Services';
1313
import { Emitter } from 'common/Event';
1414

1515
interface ISelectionState {
@@ -27,7 +27,7 @@ export class RenderService extends Disposable implements IRenderService {
2727

2828
private _renderer: MutableDisposable<IRenderer> = this._register(new MutableDisposable());
2929
private _renderDebouncer: IRenderDebouncerWithCallback;
30-
private _pausedResizeTask = new DebouncedIdleTask();
30+
private _pausedResizeTask: DebouncedIdleTask;
3131
private _observerDisposable = this._register(new MutableDisposable());
3232

3333
private _isPaused: boolean = false;
@@ -58,6 +58,7 @@ export class RenderService extends Disposable implements IRenderService {
5858
private _rowCount: number,
5959
screenElement: HTMLElement,
6060
@IOptionsService private readonly _optionsService: IOptionsService,
61+
@ILogService private readonly _logService: ILogService,
6162
@ICharSizeService private readonly _charSizeService: ICharSizeService,
6263
@ICoreService private readonly _coreService: ICoreService,
6364
@IDecorationService decorationService: IDecorationService,
@@ -67,6 +68,8 @@ export class RenderService extends Disposable implements IRenderService {
6768
) {
6869
super();
6970

71+
this._pausedResizeTask = new DebouncedIdleTask(this._logService);
72+
7073
this._renderDebouncer = new RenderDebouncer((start, end) => this._renderRows(start, end), this._coreBrowserService);
7174
this._register(this._renderDebouncer);
7275

src/common/CoreTerminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
107107
this._instantiationService = new InstantiationService();
108108
this.optionsService = this._register(new OptionsService(options));
109109
this._instantiationService.setService(IOptionsService, this.optionsService);
110-
this._bufferService = this._register(this._instantiationService.createInstance(BufferService));
111-
this._instantiationService.setService(IBufferService, this._bufferService);
112110
this._logService = this._register(this._instantiationService.createInstance(LogService));
113111
this._instantiationService.setService(ILogService, this._logService);
112+
this._bufferService = this._register(this._instantiationService.createInstance(BufferService));
113+
this._instantiationService.setService(IBufferService, this._bufferService);
114114
this.coreService = this._register(this._instantiationService.createInstance(CoreService));
115115
this._instantiationService.setService(ICoreService, this.coreService);
116116
this.coreMouseService = this._register(this._instantiationService.createInstance(CoreMouseService));

src/common/InputHandler.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('InputHandler', () => {
6565

6666
beforeEach(() => {
6767
optionsService = new MockOptionsService();
68-
bufferService = new BufferService(optionsService);
68+
bufferService = new BufferService(optionsService, new MockLogService());
6969
bufferService.resize(80, 30);
7070
coreService = new CoreService(bufferService, new MockLogService(), optionsService);
7171
oscLinkService = new OscLinkService(bufferService);
@@ -2458,7 +2458,7 @@ describe('InputHandler', () => {
24582458

24592459
beforeEach(() => {
24602460
optionsService = new MockOptionsService({ vtExtensions: { kittyKeyboard: true } });
2461-
bufferService = new BufferService(optionsService);
2461+
bufferService = new BufferService(optionsService, new MockLogService());
24622462
bufferService.resize(80, 30);
24632463
coreService = new CoreService(bufferService, new MockLogService(), optionsService);
24642464
inputHandler = new TestInputHandler(bufferService, new MockCharsetService(), coreService, new MockLogService(), optionsService, new MockOscLinkService(), new MockCoreMouseService(), new MockUnicodeService());
@@ -2508,7 +2508,7 @@ describe('InputHandler', () => {
25082508

25092509
beforeEach(() => {
25102510
optionsService = new MockOptionsService();
2511-
bufferService = new BufferService(optionsService);
2511+
bufferService = new BufferService(optionsService, new MockLogService());
25122512
bufferService.resize(80, 30);
25132513
coreService = new CoreService(bufferService, new MockLogService(), optionsService);
25142514
coreService.onData(data => { console.log(data); });

src/common/SortedList.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { assert } from 'chai';
77
import { SortedList } from 'common/SortedList';
8+
import { MockLogService } from 'common/TestUtils.test';
89

910
const deepStrictEqual = assert.deepStrictEqual;
1011

@@ -15,7 +16,7 @@ describe('SortedList', () => {
1516
}
1617

1718
beforeEach(() => {
18-
list = new SortedList<number>(e => e);
19+
list = new SortedList<number>(e => e, new MockLogService());
1920
});
2021

2122
describe('insert', () => {
@@ -90,7 +91,7 @@ describe('SortedList', () => {
9091
assertList([]);
9192
});
9293
it('custom key', () => {
93-
const customList = new SortedList<{ key: number }>(e => e.key);
94+
const customList = new SortedList<{ key: number }>(e => e.key, new MockLogService());
9495
customList.insert({ key: 5 });
9596
customList.insert({ key: 2 });
9697
customList.insert({ key: 10 });

src/common/SortedList.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { IdleTaskQueue } from 'common/TaskQueue';
7+
import type { ILogService } from 'common/services/Services';
78

89
// Work variables to avoid garbage collection.
910
let i = 0;
@@ -18,16 +19,19 @@ export class SortedList<T> {
1819
private _array: T[] = [];
1920

2021
private readonly _insertedValues: T[] = [];
21-
private readonly _flushInsertedTask = new IdleTaskQueue();
22+
private readonly _flushInsertedTask: InstanceType<typeof IdleTaskQueue>;
2223
private _isFlushingInserted = false;
2324

2425
private readonly _deletedIndices: number[] = [];
25-
private readonly _flushDeletedTask = new IdleTaskQueue();
26+
private readonly _flushDeletedTask: InstanceType<typeof IdleTaskQueue>;
2627
private _isFlushingDeleted = false;
2728

2829
constructor(
29-
private readonly _getKey: (value: T) => number
30+
private readonly _getKey: (value: T) => number,
31+
logService: ILogService
3032
) {
33+
this._flushInsertedTask = new IdleTaskQueue(logService);
34+
this._flushDeletedTask = new IdleTaskQueue(logService);
3135
}
3236

3337
public clear(): void {

src/common/TaskQueue.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { isNode } from 'common/Platform';
7+
import type { ILogService } from 'common/services/Services';
78

89
interface ITaskQueue {
910
/**
@@ -34,6 +35,11 @@ abstract class TaskQueue implements ITaskQueue {
3435
private _tasks: (() => boolean | void)[] = [];
3536
private _idleCallback?: number;
3637
private _i = 0;
38+
protected readonly _logService: ILogService;
39+
40+
constructor(logService: ILogService) {
41+
this._logService = logService;
42+
}
3743

3844
protected abstract _requestCallback(callback: CallbackWithDeadline): number;
3945
protected abstract _cancelCallback(identifier: number): void;
@@ -90,7 +96,7 @@ abstract class TaskQueue implements ITaskQueue {
9096
// Warn when the time exceeding the deadline is over 20ms, if this happens in practice the
9197
// task should be split into sub-tasks to ensure the UI remains responsive.
9298
if (lastDeadlineRemaining - taskDuration < -20) {
93-
console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(lastDeadlineRemaining - taskDuration))}ms`);
99+
this._logService.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(lastDeadlineRemaining - taskDuration))}ms`);
94100
}
95101
this._start();
96102
return;
@@ -151,8 +157,8 @@ export const IdleTaskQueue = (!isNode && 'requestIdleCallback' in window) ? Idle
151157
export class DebouncedIdleTask {
152158
private _queue: ITaskQueue;
153159

154-
constructor() {
155-
this._queue = new IdleTaskQueue();
160+
constructor(logService: ILogService) {
161+
this._queue = new IdleTaskQueue(logService);
156162
}
157163

158164
public set(task: () => boolean | void): void {

src/common/TestUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class MockBufferService implements IBufferService {
2727
public rows: number,
2828
optionsService: IOptionsService = new MockOptionsService()
2929
) {
30-
this.buffers = new BufferSet(optionsService, this);
30+
this.buffers = new BufferSet(optionsService, this, new MockLogService());
3131
// Listen to buffer activation events and automatically fire scroll events
3232
this.buffers.onBufferActivate(e => {
3333
this._onScroll.fire(e.activeBuffer.ydisp);

src/common/buffer/Buffer.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { assert } from 'chai';
77
import { Buffer } from 'common/buffer/Buffer';
88
import { CircularList } from 'common/CircularList';
9-
import { MockOptionsService, MockBufferService } from 'common/TestUtils.test';
9+
import { MockOptionsService, MockBufferService, MockLogService } from 'common/TestUtils.test';
1010
import { BufferLine, DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
1111
import { CellData } from 'common/buffer/CellData';
1212
import { ExtendedAttrs } from 'common/buffer/AttributeData';
@@ -23,7 +23,7 @@ describe('Buffer', () => {
2323
beforeEach(() => {
2424
optionsService = new MockOptionsService({ scrollback: INIT_SCROLLBACK });
2525
bufferService = new MockBufferService(INIT_COLS, INIT_ROWS);
26-
buffer = new Buffer(true, optionsService, bufferService);
26+
buffer = new Buffer(true, optionsService, bufferService, new MockLogService());
2727
});
2828

2929
describe('constructor', () => {
@@ -151,7 +151,7 @@ describe('Buffer', () => {
151151

152152
describe('no scrollback', () => {
153153
it('should trim from the top of the buffer when the cursor reaches the bottom', () => {
154-
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService);
154+
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService, new MockLogService());
155155
assert.equal(buffer.lines.maxLength, INIT_ROWS);
156156
buffer.y = INIT_ROWS - 1;
157157
buffer.fillViewportRows();
@@ -1054,7 +1054,7 @@ describe('Buffer', () => {
10541054
describe('buffer marked to have no scrollback', () => {
10551055
it('should always have a scrollback of 0', () => {
10561056
// Test size on initialization
1057-
buffer = new Buffer(false, new MockOptionsService({ scrollback: 1000 }), bufferService);
1057+
buffer = new Buffer(false, new MockOptionsService({ scrollback: 1000 }), bufferService, new MockLogService());
10581058
buffer.fillViewportRows();
10591059
assert.equal(buffer.lines.maxLength, INIT_ROWS);
10601060
// Test size on buffer increase
@@ -1068,15 +1068,15 @@ describe('Buffer', () => {
10681068

10691069
describe('addMarker', () => {
10701070
it('should adjust a marker line when the buffer is trimmed', () => {
1071-
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService);
1071+
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService, new MockLogService());
10721072
buffer.fillViewportRows();
10731073
const marker = buffer.addMarker(buffer.lines.length - 1);
10741074
assert.equal(marker.line, buffer.lines.length - 1);
10751075
buffer.lines.onTrimEmitter.fire(1);
10761076
assert.equal(marker.line, buffer.lines.length - 2);
10771077
});
10781078
it('should dispose of a marker if it is trimmed off the buffer', () => {
1079-
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService);
1079+
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService, new MockLogService());
10801080
buffer.fillViewportRows();
10811081
assert.equal(buffer.markers.length, 0);
10821082
const marker = buffer.addMarker(0);
@@ -1088,7 +1088,7 @@ describe('Buffer', () => {
10881088
});
10891089
it('should call onDispose', () => {
10901090
const eventStack: string[] = [];
1091-
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService);
1091+
buffer = new Buffer(true, new MockOptionsService({ scrollback: 0 }), bufferService, new MockLogService());
10921092
buffer.fillViewportRows();
10931093
assert.equal(buffer.markers.length, 0);
10941094
const marker = buffer.addMarker(0);

0 commit comments

Comments
 (0)